Skip to content

Commit 940ef9d

Browse files
authored
Refine checkstyle rules (#6283)
- Add (and apply) checkstyle rules for - correct spacing (especalliy // space-after-comment-marker) - } else if { (<-- in one line) - no two empty lines - @Deprecation JavaDoc - some coding practices - Fix HTML syntax of JavaDoc comments - Remove CSS class comment syntax in IconTheme class - Remove deprecated method BibEntry#getCiteKey()
1 parent fb2a6d7 commit 940ef9d

File tree

272 files changed

+991
-921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+991
-921
lines changed

config/checkstyle/checkstyle.xml

+59-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"http://www.checkstyle.org/dtds/configuration_1_3.dtd">
55

66
<module name="Checker">
7+
<property name="charset" value="UTF-8"/>
8+
79
<module name="Header">
810
<property name="header" value=""/>
911
</module>
@@ -21,6 +23,9 @@
2123
<property name="fileNamePattern" value="module\-info\.java$"/>
2224
</module>
2325

26+
<module name="FileTabCharacter"/>
27+
<module name="NewlineAtEndOfFile"/>
28+
2429
<module name="TreeWalker">
2530
<!-- Checks for Javadoc comments: https://checkstyle.org/config_javadoc.html -->
2631
<module name="InvalidJavadocPosition"/>
@@ -42,16 +47,27 @@
4247
<property name="sortStaticImportsAlphabetically" value="true"/>
4348
</module>
4449

45-
<!-- Checks for common coding problems: https://checkstyle.org/config_coding.html -->
46-
<module name="DeclarationOrder"/>
47-
4850
<!-- Checks for whitespace: https://checkstyle.org/config_whitespace.html -->
51+
52+
<module name="EmptyForInitializerPad"/>
4953
<module name="EmptyLineSeparator">
54+
<!-- check all except variable declarations -->
5055
<property name="tokens"
51-
value="IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF"/>
56+
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF"/>
5257
<property name="allowMultipleEmptyLines" value="false"/>
5358
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
5459
</module>
60+
<module name="GenericWhitespace"/>
61+
<module name="MethodParamPad"/>
62+
<module name="NoLineWrap"/>
63+
<module name="NoWhitespaceAfter"/>
64+
<module name="NoWhitespaceBefore"/>
65+
<module name="ParenPad"/>
66+
<module name="SeparatorWrap">
67+
<property name="tokens" value="COMMA, SEMI, ELLIPSIS, ARRAY_DECLARATOR, RBRACK, METHOD_REF"/>
68+
</module>
69+
<module name="SingleSpaceSeparator"/>
70+
<module name="WhitespaceAfter"/>
5571
<module name="WhitespaceAround">
5672
<!-- RCULRY causes issues if classes are nested within arrays, therefore not activated -->
5773
<property name="tokens"
@@ -70,5 +86,44 @@
7086

7187
<!-- Checks for blocks: https://checkstyle.org/config_blocks.html -->
7288
<module name="NeedBraces"/>
89+
90+
<module name="EmptyBlock">
91+
<property name="option" value="text"/>
92+
</module>
93+
94+
<!-- Disallows empty catch blocks (not even having a comment): https://checkstyle.sourceforge.io/config_blocks.html#EmptyCatchBlock -->
95+
<module name="EmptyCatchBlock"/>
96+
97+
<!--
98+
following rule enforces that there are no one line statements such as
99+
100+
public String getTabName() { return Localization.lang("XMP metadata"); }
101+
102+
Since it is too much effort to reformat all code, it is currently not enabled -->
103+
<!-- <module name="LeftCurly"/> -->
104+
105+
<module name="RightCurly"/>
106+
<!-- coding - https://checkstyle.sourceforge.io/config_coding.html -->
107+
108+
<module name="AvoidDoubleBraceInitialization"/>
109+
110+
<module name="CovariantEquals"/>
111+
112+
<!-- Checks for common coding problems: https://checkstyle.org/config_coding.html -->
113+
114+
<module name="DeclarationOrder"/>
115+
<module name="EmptyStatement"/>
116+
117+
<module name="EqualsHashCode"/>
118+
119+
<!-- force a space after // for comments -->
120+
<module name="TodoComment">
121+
<property name="id" value="commentStartWithSpace"/>
122+
<property name="format" value="^([^\s\/*])"/>
123+
<message key="todo.match" value="Comment text should start with space."/>
124+
</module>
125+
126+
<module name="MissingDeprecated"/>
127+
73128
</module>
74129
</module>

src/main/java/org/jabref/JabRefExecutorService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void submit(TimerTask timerTask, long millisecondsDelay) {
136136
public void shutdownEverything() {
137137
// those threads will be allowed to finish
138138
this.executorService.shutdown();
139-
//those threads will be interrupted in their current task
139+
// those threads will be interrupted in their current task
140140
this.lowPriorityExecutorService.shutdownNow();
141141
// kill the remote thread
142142
stopRemoteThread();

src/main/java/org/jabref/JabRefGUI.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void openWindow(Stage mainStage) {
6565
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
6666
mainStage.setMaximized(true);
6767
} else if (Screen.getScreens().size() == 1 && isWindowPositionOutOfBounds()) {
68-
//corrects the Window, if its outside of the mainscreen
68+
// corrects the Window, if its outside of the mainscreen
6969
LOGGER.debug("The Jabref Window is outside the Main Monitor\n");
7070
mainStage.setX(0);
7171
mainStage.setY(0);
@@ -94,8 +94,8 @@ private void openWindow(Stage mainStage) {
9494

9595
mainStage.setOnCloseRequest(event -> {
9696
if (!correctedWindowPos) {
97-
//saves the window position only if its not corrected -> the window will rest at the old Position,
98-
//if the external Screen is connected again.
97+
// saves the window position only if its not corrected -> the window will rest at the old Position,
98+
// if the external Screen is connected again.
9999
saveWindowState(mainStage);
100100
}
101101
boolean reallyQuit = mainFrame.quit();

src/main/java/org/jabref/cli/ArgumentProcessor.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ private List<ParserResult> processArguments() {
241241

242242
private boolean exportMatches(List<ParserResult> loaded) {
243243
String[] data = cli.getExportMatches().split(",");
244-
String searchTerm = data[0].replace("\\$", " "); //enables blanks within the search term:
245-
//$ stands for a blank
244+
String searchTerm = data[0].replace("\\$", " "); // enables blanks within the search term:
245+
// $ stands for a blank
246246
ParserResult pr = loaded.get(loaded.size() - 1);
247247
BibDatabaseContext databaseContext = pr.getDatabaseContext();
248248
BibDatabase dataBase = pr.getDatabase();
@@ -252,17 +252,17 @@ private boolean exportMatches(List<ParserResult> loaded) {
252252
searchPreferences.isRegularExpression());
253253
List<BibEntry> matches = new DatabaseSearcher(query, dataBase).getMatches();
254254

255-
//export matches
255+
// export matches
256256
if (!matches.isEmpty()) {
257257
String formatName;
258258

259-
//read in the export format, take default format if no format entered
259+
// read in the export format, take default format if no format entered
260260
switch (data.length) {
261261
case 3:
262262
formatName = data[2];
263263
break;
264264
case 2:
265-
//default exporter: HTML table (with Abstract & BibTeX)
265+
// default exporter: HTML table (with Abstract & BibTeX)
266266
formatName = "tablerefsabsbib";
267267
break;
268268
default:
@@ -272,7 +272,7 @@ private boolean exportMatches(List<ParserResult> loaded) {
272272
return false;
273273
}
274274

275-
//export new database
275+
// export new database
276276
Optional<Exporter> exporter = Globals.exportFactory.getExporterByName(formatName);
277277
if (!exporter.isPresent()) {
278278
System.err.println(Localization.lang("Unknown export format") + ": " + formatName);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.jabref.gui;
22

33
public class AbstractViewModel {
4-
//empty
4+
// empty
55
}

src/main/java/org/jabref/gui/EntryTypeView.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPre
6969
ControlHelper.setAction(generateButton, this.getDialogPane(), event -> viewModel.runFetcherWorker());
7070

7171
setResultConverter(button -> {
72-
//The buttonType will always be cancel, even if we pressed one of the entry type buttons
72+
// The buttonType will always be cancel, even if we pressed one of the entry type buttons
7373
return type;
7474
});
7575

@@ -112,8 +112,8 @@ public void initialize() {
112112

113113
new ViewModelListCellFactory<IdBasedFetcher>().withText(item -> item.getName()).install(idBasedFetchers);
114114

115-
//we set the managed property so that they will only be rendered when they are visble so that the Nodes only take the space when visible
116-
//avoids removing and adding from the scence graph
115+
// we set the managed property so that they will only be rendered when they are visble so that the Nodes only take the space when visible
116+
// avoids removing and adding from the scence graph
117117
bibTexTitlePane.managedProperty().bind(bibTexTitlePane.visibleProperty());
118118
ieeeTranTitlePane.managedProperty().bind(ieeeTranTitlePane.visibleProperty());
119119
biblatexTitlePane.managedProperty().bind(biblatexTitlePane.visibleProperty());

src/main/java/org/jabref/gui/JabRefFrame.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void setWindowTitle() {
293293

294294
// no database open
295295
if (panel == null) {
296-
//setTitle(FRAME_TITLE);
296+
// setTitle(FRAME_TITLE);
297297
return;
298298
}
299299

@@ -307,9 +307,9 @@ public void setWindowTitle() {
307307
.getDatabasePath()
308308
.map(Path::toString)
309309
.orElse(Localization.lang("untitled"));
310-
//setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
310+
// setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
311311
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
312-
//setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
312+
// setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
313313
// + Localization.lang("shared") + "]" + modeInfo);
314314
}
315315
}
@@ -343,7 +343,7 @@ public JabRefPreferences prefs() {
343343
* set to true
344344
*/
345345
private void tearDownJabRef(List<String> filenames) {
346-
//prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH);
346+
// prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH);
347347

348348
if (prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
349349
// Here we store the names of all current files. If
@@ -554,10 +554,10 @@ public void init() {
554554

555555
initDragAndDrop();
556556

557-
//setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
558-
//WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X,
557+
// setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
558+
// WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X,
559559
// JabRefPreferences.SIZE_Y);
560-
//pw.displayWindowAtStoredLocation();
560+
// pw.displayWindowAtStoredLocation();
561561

562562
// Bind global state
563563
stateManager.activeDatabaseProperty().bind(
@@ -595,9 +595,9 @@ public void init() {
595595
stateManager.activeSearchQueryProperty().set(newBasePanel.getCurrentSearchQuery());
596596

597597
// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
598-
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
599-
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class));
600-
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
598+
// previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
599+
// generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class));
600+
// openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
601601

602602
setWindowTitle();
603603
// Update search autocompleter with information for the correct database:
@@ -743,7 +743,7 @@ private MenuBar createMenu() {
743743
);
744744
}
745745

746-
//@formatter:off
746+
// @formatter:off
747747
library.getItems().addAll(
748748
factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)),
749749
factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)),
@@ -883,7 +883,7 @@ private MenuBar createMenu() {
883883
factory.createMenuItem(StandardActions.ABOUT, new AboutAction())
884884
);
885885

886-
//@formatter:on
886+
// @formatter:on
887887
MenuBar menu = new MenuBar();
888888
menu.getStyleClass().add("mainMenu");
889889
menu.getMenus().addAll(

src/main/java/org/jabref/gui/actions/JabRefAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private String getActionName(Action action, Command command) {
5858
return action.getText();
5959
} else {
6060
String commandName = command.getClass().getSimpleName();
61-
if ( commandName.contains("EditAction")
61+
if (commandName.contains("EditAction")
6262
|| commandName.contains("CopyMoreAction")
6363
|| commandName.contains("CopyCitationAction")
6464
|| commandName.contains("PreviewSwitchAction")

src/main/java/org/jabref/gui/autocompleter/SuggestionProvider.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public SuggestionProviderString(Callback<T, String> stringConverter) {
149149

150150
// In case no stringConverter was provided, use the default strategy
151151
if (this.stringConverter == null) {
152-
this.stringConverter = obj -> {
153-
return obj != null ? obj.toString() : ""; //$NON-NLS-1$
154-
};
152+
this.stringConverter = obj -> obj != null ? obj.toString() : "";
155153
}
156154
}
157155

src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ExtractBibtexDialog() {
5252
@FXML
5353
private void initialize() {
5454
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
55-
this.viewModel = new BibtexExtractorViewModel(database, dialogService, JabRefPreferences.getInstance(), fileUpdateMonitor, taskExecutor,undoManager,stateManager);
55+
this.viewModel = new BibtexExtractorViewModel(database, dialogService, JabRefPreferences.getInstance(), fileUpdateMonitor, taskExecutor, undoManager, stateManager);
5656
input.textProperty().bindBidirectional(viewModel.inputTextProperty());
5757
}
5858
}

src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void buildGUI() {
6868
Label keyPattern = new Label(Localization.lang("Key pattern"));
6969
gridPane.add(label, ++columnIndex, rowIndex);
7070
gridPane.add(keyPattern, ++columnIndex, rowIndex);
71-
++columnIndex; //3
71+
columnIndex++;
7272
}
7373

7474
rowIndex++;

src/main/java/org/jabref/gui/collab/ChangeDisplayDialog.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ public ChangeDisplayDialog(BibDatabaseContext database, List<DatabaseChangeViewM
7979
setResultConverter(button -> {
8080
if (button == dismissChanges) {
8181
return false;
82-
8382
} else {
8483
// Perform all accepted changes
8584
NamedCompound ce = new NamedCompound(Localization.lang("Merged external changes"));
8685
for (DatabaseChangeViewModel change : changes) {
8786
if (change instanceof EntryChangeViewModel) {
88-
change.makeChange(database, ce); //We don't have a checkbox for accept and always get the correct merged entry, the accept property in this special case only controls the radio buttons selection
87+
// We don't have a checkbox for accept and always get the correct merged entry, the accept property in this special case only controls the radio buttons selection
88+
change.makeChange(database, ce);
8989
} else if (change.isAccepted()) {
9090
change.makeChange(database, ce);
9191
}
9292
}
9393
ce.end();
94-
//TODO: panel.getUndoManager().addEdit(ce);
94+
// TODO: panel.getUndoManager().addEdit(ce);
9595

9696
return true;
9797
}

src/main/java/org/jabref/gui/commonfxcontrols/BibtexKeyPatternPanel.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,21 @@ private void initialize() {
8080
this.itemsProperty().bindBidirectional(viewModel.patternListProperty());
8181
}
8282

83-
public void setValues() { viewModel.setValues(); }
83+
public void setValues() {
84+
viewModel.setValues();
85+
}
8486

85-
public void resetAll() { viewModel.resetAll(); }
87+
public void resetAll() {
88+
viewModel.resetAll();
89+
}
8690

87-
public ListProperty<BibtexKeyPatternPanelItemModel> patternListProperty() { return viewModel.patternListProperty(); }
91+
public ListProperty<BibtexKeyPatternPanelItemModel> patternListProperty() {
92+
return viewModel.patternListProperty();
93+
}
8894

89-
public ObjectProperty<BibtexKeyPatternPanelItemModel> defaultKeyPatternProperty() { return viewModel.defaultKeyPatternProperty(); }
95+
public ObjectProperty<BibtexKeyPatternPanelItemModel> defaultKeyPatternProperty() {
96+
return viewModel.defaultKeyPatternProperty();
97+
}
9098

9199
private void jumpToSearchKey(KeyEvent keypressed) {
92100
if (keypressed.getCharacter() == null) {

src/main/java/org/jabref/gui/commonfxcontrols/BibtexKeyPatternPanelItemModel.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ public BibtexKeyPatternPanelItemModel(EntryType entryType, String pattern) {
2020
this.pattern.setValue(pattern);
2121
}
2222

23-
public EntryType getEntryType() { return entryType.getValue(); }
23+
public EntryType getEntryType() {
24+
return entryType.getValue();
25+
}
2426

25-
public ObjectProperty<EntryType> entryType() { return entryType; }
27+
public ObjectProperty<EntryType> entryType() {
28+
return entryType;
29+
}
2630

2731
public void setPattern(String pattern) {
2832
this.pattern.setValue(pattern);
@@ -32,8 +36,12 @@ public String getPattern() {
3236
return pattern.getValue();
3337
}
3438

35-
public StringProperty pattern() { return pattern; }
39+
public StringProperty pattern() {
40+
return pattern;
41+
}
3642

3743
@Override
38-
public String toString() { return "[" + entryType.getValue().getName() + "," + pattern.getValue() + "]"; }
44+
public String toString() {
45+
return "[" + entryType.getValue().getName() + "," + pattern.getValue() + "]";
46+
}
3947
}

0 commit comments

Comments
 (0)