Skip to content

Commit

Permalink
Add CheckStyle Check for Constants (final static) (#2992)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDietz authored and tobiasdiez committed Jul 10, 2017
1 parent d972f45 commit 7cb74cc
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 155 deletions.
4 changes: 4 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
PLUS, PLUS_ASSIGN, QUESTION,
SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
</module>

<module name="ConstantName">
<property name="format" value="^log(ger)?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
</module>

<module name="SuppressionFilter">
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Globals {
public static final RemoteListenerServerLifecycle REMOTE_LISTENER = new RemoteListenerServerLifecycle();

public static final ImportFormatReader IMPORT_FORMAT_READER = new ImportFormatReader();
public static final TaskExecutor taskExecutor = new DefaultTaskExecutor();
public static final TaskExecutor TASK_EXECUTOR = new DefaultTaskExecutor();
// In the main program, this field is initialized in JabRef.java
// Each test case initializes this field if required
public static JabRefPreferences prefs;
Expand Down Expand Up @@ -107,7 +107,7 @@ public static FileUpdateMonitor getFileUpdateMonitor() {
}

public static void shutdownThreadPools() {
taskExecutor.shutdown();
TASK_EXECUTOR.shutdown();
JabRefExecutorService.INSTANCE.shutdownEverything();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ public void setClipboardContents(String aString) {
StringSelection stringSelection = new StringSelection(aString);
CLIPBOARD.setContents(stringSelection, this);
}

public List<BibEntry> extractBibEntriesFromClipboard() {
// Get clipboard contents, and see if TransferableBibtexEntry is among the content flavors offered
Transferable content = CLIPBOARD.getContents(null);
List<BibEntry> result = new ArrayList<>();

if (content.isDataFlavorSupported(TransferableBibtexEntry.entryFlavor)) {
if (content.isDataFlavorSupported(TransferableBibtexEntry.ENTRY_FLAVOR)) {
// We have determined that the clipboard data is a set of entries.
try {
@SuppressWarnings("unchecked")
List<BibEntry> contents = (List<BibEntry>) content.getTransferData(TransferableBibtexEntry.entryFlavor);
List<BibEntry> contents = (List<BibEntry>) content.getTransferData(TransferableBibtexEntry.ENTRY_FLAVOR);
result = contents;
} catch (UnsupportedFlavorException | ClassCastException ex) {
LOGGER.warn("Could not paste this type", ex);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static Object createDependency(Class<?> clazz) {
if (clazz == DialogService.class) {
return new FXDialogService();
} else if (clazz == TaskExecutor.class) {
return Globals.taskExecutor;
return Globals.TASK_EXECUTOR;
} else if (clazz == PreferencesService.class) {
return Globals.prefs;
} else if (clazz == KeyBindingRepository.class) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private JPanel createIdFetcherPanel() {

WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).forEach(fetcher -> comboBox.addItem(fetcher.getName()));
// set DOI as default
comboBox.setSelectedItem(DoiFetcher.name);
comboBox.setSelectedItem(DoiFetcher.NAME);

generateButton.addActionListener(action -> {
fetcherWorker.execute();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/TransferableBibtexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class TransferableBibtexEntry implements Transferable {

public static final DataFlavor entryFlavor = new DataFlavor(BibEntry.class, "JabRef entry");
public static final DataFlavor ENTRY_FLAVOR = new DataFlavor(BibEntry.class, "JabRef entry");
private final List<BibEntry> data;


Expand All @@ -32,19 +32,19 @@ public TransferableBibtexEntry(List<BibEntry> bes) {

@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {TransferableBibtexEntry.entryFlavor,
return new DataFlavor[]{TransferableBibtexEntry.ENTRY_FLAVOR,
DataFlavor.stringFlavor};
}

@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(TransferableBibtexEntry.entryFlavor) || flavor.equals(DataFlavor.stringFlavor);
return flavor.equals(TransferableBibtexEntry.ENTRY_FLAVOR) || flavor.equals(DataFlavor.stringFlavor);
}

@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException {
if (flavor.equals(TransferableBibtexEntry.entryFlavor)) {
if (flavor.equals(TransferableBibtexEntry.ENTRY_FLAVOR)) {
return data;
} else if (flavor.equals(DataFlavor.stringFlavor)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean compresse
fieldEditor.setAutoCompleteListener(autoCompleteListener);
*/

FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(),
FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.TASK_EXECUTOR, new FXDialogService(),
Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs,
bPanel.getBibDatabaseContext(), entry.getType());
fieldEditor.bindToEntry(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private StackPane getPane(BibEntry entry) {
progress.setVisible(false);
browser.getEngine().loadContent(convertToHtml(relatedArticles));
})
.executeWith(Globals.taskExecutor);
.executeWith(Globals.TASK_EXECUTOR);

browser.getEngine().getLoadWorker().stateProperty().addListener(new OpenHyperlinksInExternalBrowser(browser));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FindFullTextAction extends AbstractWorker {

private static final Log LOGGER = LogFactory.getLog(FindFullTextAction.class);

private static final int warningLimit = 5; // The minimum number of selected entries to ask the user for confirmation
private static final int WARNING_LIMIT = 5; // The minimum number of selected entries to ask the user for confirmation

private final BasePanel basePanel;
private final Map<Optional<URL>, BibEntry> downloads = new ConcurrentHashMap<>();
Expand All @@ -51,7 +51,7 @@ public void init() throws Exception {

@Override
public void run() {
if (basePanel.getSelectedEntries().size() >= warningLimit) {
if (basePanel.getSelectedEntries().size() >= WARNING_LIMIT) {
String[] options = new String[] {Localization.lang("Look up full text documents"),
Localization.lang("Cancel")};
int answer = JOptionPane.showOptionDialog(basePanel.frame(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ProtectedTermsMenu extends Menu {

private static final ProtectTermsFormatter formatter = new ProtectTermsFormatter(Globals.protectedTermsLoader);
private static final ProtectTermsFormatter FORMATTER = new ProtectTermsFormatter(Globals.protectedTermsLoader);
private final Menu externalFiles;
private final TextArea opener;

Expand All @@ -30,7 +30,7 @@ public ProtectedTermsMenu(TextArea opener) {
});

MenuItem formatItem = new MenuItem(Localization.lang("Format field"));
formatItem.setOnAction(event -> opener.setText(formatter.format(opener.getText())));
formatItem.setOnAction(event -> opener.setText(FORMATTER.format(opener.getText())));

externalFiles = new Menu(Localization.lang("Add selected text to list"));
updateFiles();
Expand Down Expand Up @@ -67,7 +67,5 @@ private void updateFiles() {
}
});
externalFiles.getItems().add(addToNewFileItem);

}

}
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/gui/help/AboutDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

public class AboutDialogViewModel extends AbstractViewModel {

private static final String homepageUrl = "https://www.jabref.org";
private static final String donationUrl = "https://donations.jabref.org";
private static final String librariesUrl = "https://github.com/JabRef/jabref/blob/master/external-libraries.txt";
private static final String githubUrl = "https://github.com/JabRef/jabref";
private static final String licenseUrl = "https://github.com/JabRef/jabref/blob/master/LICENSE.md";
private static final String HOMEPAGE_URL = "https://www.jabref.org";
private static final String DONATION_URL = "https://donations.jabref.org";
private static final String LIBRARIES_URL = "https://github.com/JabRef/jabref/blob/master/external-libraries.txt";
private static final String GITHUB_URL = "https://github.com/JabRef/jabref";
private static final String LICENSE_URL = "https://github.com/JabRef/jabref/blob/master/LICENSE.md";
private final String changelogUrl;
private final String versionInfo;
private final Log logger = LogFactory.getLog(AboutDialogViewModel.class);
Expand Down Expand Up @@ -115,27 +115,27 @@ public void copyVersionToClipboard() {
}

public void openJabrefWebsite() {
openWebsite(homepageUrl);
openWebsite(HOMEPAGE_URL);
}

public void openExternalLibrariesWebsite() {
openWebsite(librariesUrl);
openWebsite(LIBRARIES_URL);
}

public void openGithub() {
openWebsite(githubUrl);
openWebsite(GITHUB_URL);
}

public void openChangeLog() {
openWebsite(changelogUrl);
}

public void openLicense() {
openWebsite(licenseUrl);
openWebsite(LICENSE_URL);
}

public void openDonation() {
openWebsite(donationUrl);
openWebsite(DONATION_URL);
}

private void openWebsite(String url) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/help/HelpAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HelpAction extends MnemonicAwareAction {
/**
* New languages of the help have to be added here
*/
private static final Set<String> avaiableLangFiles = Stream.of("en", "de", "fr", "in", "ja")
private static final Set<String> AVAIABLE_LANG_FILES = Stream.of("en", "de", "fr", "in", "ja")
.collect(Collectors.toCollection(HashSet::new));

private HelpFile helpPage;
Expand Down Expand Up @@ -99,7 +99,7 @@ private void openHelpPage() {
String lang = Globals.prefs.get(JabRefPreferences.LANGUAGE);
StringBuilder sb = new StringBuilder("https://help.jabref.org/");

if (avaiableLangFiles.contains(lang)) {
if (AVAIABLE_LANG_FILES.contains(lang)) {
sb.append(lang);
sb.append("/");
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AppearancePrefsTab extends JPanel implements PrefsTab {
private final JCheckBox customLAF;

static class LookAndFeel {
private static final List<String> looks = Arrays.asList(
private static final List<String> LOOKS = Arrays.asList(
UIManager.getSystemLookAndFeelClassName(),
UIManager.getCrossPlatformLookAndFeelClassName(),
"com.jgoodies.looks.plastic.Plastic3DLookAndFeel",
Expand All @@ -63,7 +63,7 @@ static class LookAndFeel {
public static List<String> getAvailableLookAndFeels() {
List<String> lookAndFeels = new ArrayList<>();

for (String l : looks) {
for (String l : LOOKS) {
try {
// Try to find L&F
Class.forName(l);
Expand Down Expand Up @@ -158,16 +158,16 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
FormBuilder generalBuilder = FormBuilder.create();
JPanel generalPanel = generalBuilder.columns("left:pref, left:pref, 3dlu, pref, 7dlu, right:pref, 3dlu, pref")
.rows("pref, 3dlu, pref, 3dlu, pref")
.columnGroup(2,6)
.columnGroup(4,8)
.add(overrideFonts).xyw(1,1,5)
.add(new JLabel(" ")).xy(1,3)
.add(new JLabel(Localization.lang("Menu and label font size") + ":")).xy(2,3)
.add(fontSize).xy(4,3)
.columnGroup(2, 6)
.columnGroup(4, 8)
.add(overrideFonts).xyw(1, 1, 5)
.add(new JLabel(" ")).xy(1, 3)
.add(new JLabel(Localization.lang("Menu and label font size") + ":")).xy(2, 3)
.add(fontSize).xy(4, 3)
.add(new JLabel(Localization.lang("Size of large icons") + ":")).xy(2, 5)
.add(largeIconsTextField).xy(4,5)
.add(largeIconsTextField).xy(4, 5)
.add(new JLabel(Localization.lang("Size of small icons") + ":")).xy(6, 5)
.add(smallIconsTextField).xy(8,5)
.add(smallIconsTextField).xy(8, 5)
.build();

builder.append(generalPanel);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/preftabs/FontSelectorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ public class FontSelectorDialog extends JabRefDialog {

private static final String ITALIC = "italic";

private static final String[] styles = {PLAIN, BOLD, ITALIC, BOLD_ITALIC};
private static final String[] STYLES = {PLAIN, BOLD, ITALIC, BOLD_ITALIC};

private static final String[] sizes = {"9", "10", "12", "14", "16", "18", "24"};
private static final String[] SIZES = {"9", "10", "12", "14", "16", "18", "24"};
// private members
private boolean isOK;
private final JTextField familyField = new JTextField();
private final JList<String> familyList;
private final JTextField sizeField = new JTextField();
private final JList<String> sizeList = new JList<>(sizes);
private final JList<String> sizeList = new JList<>(SIZES);
private final JTextField styleField = new JTextField();
private final JList<String> styleList = new JList<>(styles);
private final JList<String> styleList = new JList<>(STYLES);

private final JLabel preview;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/exporter/FileSaveSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void commit(Path file) throws SaveException {
PosixFilePermission.GROUP_READ,
PosixFilePermission.GROUP_WRITE,
PosixFilePermission.OTHERS_READ);
if (FileUtil.isPosixCompilant && Files.exists(file)) {
if (FileUtil.IS_POSIX_COMPILANT && Files.exists(file)) {
try {
oldFilePermissions = Files.getPosixFilePermissions(file);
} catch (IOException exception) {
Expand All @@ -102,7 +102,7 @@ public void commit(Path file) throws SaveException {
FileUtil.copyFile(temporaryFile, file, true);

// Restore file permissions
if (FileUtil.isPosixCompilant) {
if (FileUtil.IS_POSIX_COMPILANT) {
try {
Files.setPosixFilePermissions(file, oldFilePermissions);
} catch (IOException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.jabref.model.entry.identifier.DOI;

public class DoiFetcher implements IdBasedFetcher, EntryBasedFetcher {
public static final String name = "DOI";
public static final String NAME = "DOI";

private final ImportFormatPreferences preferences;

Expand All @@ -33,7 +33,7 @@ public DoiFetcher(ImportFormatPreferences preferences) {

@Override
public String getName() {
return DoiFetcher.name;
return DoiFetcher.NAME;
}

@Override
Expand Down Expand Up @@ -80,5 +80,4 @@ public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
bibEntry.ifPresent(list::add);
return list;
}

}
Loading

0 comments on commit 7cb74cc

Please sign in to comment.