From 7db7bd0ba0be59a88675ed6d9fc39d31fdeb0231 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 19 Oct 2018 10:53:31 +0200 Subject: [PATCH 1/3] Checkstyle: force braces around code blocks Enforces that code blocks are surrounded by braces, e.g. the following is invalid ```java if (test) statement; else statement; ``` --- config/checkstyle/checkstyle.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 20cbcee3f60..d0d037d677b 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -49,6 +49,8 @@ + + From 7b12d41e80f6a52b79eb64b3f58769c820c7840a Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Sun, 28 Oct 2018 18:39:07 +0100 Subject: [PATCH 2/3] Fix Violations of Always Use Braces (#4400) --- .../gui/edit/ReplaceStringViewModel.java | 20 +++++++++---------- .../gui/preferences/AppearancePrefsTab.java | 7 +++---- .../logic/integrity/IntegrityMessage.java | 9 ++++++--- .../org/jabref/model/entry/BibtexString.java | 11 ++++++---- .../model/entry/identifier/MathSciNetId.java | 8 ++++++-- .../model/groups/AutomaticKeywordGroup.java | 8 ++++++-- .../model/groups/AutomaticPersonsGroup.java | 8 ++++++-- .../org/jabref/model/groups/TexGroup.java | 12 ++++++++--- .../model/metadata/ContentSelectors.java | 14 ++++++++----- .../gui/search/TextFlowEqualityHelper.java | 6 ++++-- 10 files changed, 65 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java index 89fff7fa8b7..db5ce8b4b29 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java @@ -14,8 +14,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -public class ReplaceStringViewModel extends AbstractViewModel -{ +public class ReplaceStringViewModel extends AbstractViewModel { private boolean allFieldReplace; private String findString; private String replaceString; @@ -29,8 +28,7 @@ public class ReplaceStringViewModel extends AbstractViewModel private BooleanProperty selectOnlyProperty = new SimpleBooleanProperty(); - public ReplaceStringViewModel(BasePanel basePanel) - { + public ReplaceStringViewModel(BasePanel basePanel) { Objects.requireNonNull(basePanel); this.panel = basePanel; } @@ -45,20 +43,20 @@ public int replace() { final NamedCompound compound = new NamedCompound(Localization.lang("Replace string")); int counter = 0; if (selOnly) { - for (BibEntry bibEntry: this.panel.getSelectedEntries()) + for (BibEntry bibEntry : this.panel.getSelectedEntries()) { counter += replaceItem(bibEntry, compound); - } - else { - for (BibEntry bibEntry: this.panel.getDatabase().getEntries()) + } + } else { + for (BibEntry bibEntry : this.panel.getDatabase().getEntries()) { counter += replaceItem(bibEntry, compound); + } } return counter; } /** - * Does the actual operation on a Bibtex entry based on the - * settings specified in this same dialog. Returns the number of - * occurrences replaced. + * Does the actual operation on a Bibtex entry based on the settings specified in this same dialog. Returns the + * number of occurrences replaced. */ private int replaceItem(BibEntry entry, NamedCompound compound) { int counter = 0; diff --git a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java index 92c62d12864..3aae702b2b0 100644 --- a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java @@ -53,13 +53,12 @@ public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs) darkTheme = new RadioButton("Dark theme"); darkTheme.setToggleGroup(themeGroup); - if (prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS)) + if (prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS)) { lightTheme.setSelected(true); - else if (prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS)) + } else if (prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS)) { darkTheme.setSelected(true); - + } container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF, lightTheme, darkTheme); - } public Node getBuilder() { diff --git a/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java b/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java index c04a63f87fa..f11fa936187 100644 --- a/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java +++ b/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java @@ -41,8 +41,12 @@ public Object clone() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } IntegrityMessage that = (IntegrityMessage) o; return Objects.equals(entry, that.entry) && Objects.equals(fieldName, that.fieldName) && @@ -53,5 +57,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(entry, fieldName, message); } - } diff --git a/src/main/java/org/jabref/model/entry/BibtexString.java b/src/main/java/org/jabref/model/entry/BibtexString.java index b03d9ba08e7..52268364cd3 100644 --- a/src/main/java/org/jabref/model/entry/BibtexString.java +++ b/src/main/java/org/jabref/model/entry/BibtexString.java @@ -135,7 +135,7 @@ public boolean hasChanged() { } /* - * Returns user comments (arbitrary text before the string) if there are any. If not returns the empty string + * Returns user comments (arbitrary text before the string) if there are any. If not returns the empty string */ public String getUserComments() { if (parsedSerialization != null) { @@ -173,8 +173,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } BibtexString that = (BibtexString) o; return hasChanged == that.hasChanged && Objects.equals(name, that.name) && @@ -188,5 +192,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(name, content, id, type, parsedSerialization, hasChanged); } - } diff --git a/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java b/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java index c848e56025b..f07ec8be273 100644 --- a/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java +++ b/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java @@ -27,8 +27,12 @@ public static Optional parse(String mrNumberRaw) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } MathSciNetId that = (MathSciNetId) o; return Objects.equals(identifier, that.identifier); } diff --git a/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java b/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java index 062648d7f72..f4952a4f751 100644 --- a/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java +++ b/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java @@ -42,8 +42,12 @@ public AbstractGroup deepCopy() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AutomaticKeywordGroup that = (AutomaticKeywordGroup) o; return Objects.equals(keywordDelimiter, that.keywordDelimiter) && Objects.equals(field, that.field); diff --git a/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java b/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java index 61992508ab9..58f11af3b4c 100644 --- a/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java +++ b/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java @@ -21,8 +21,12 @@ public AutomaticPersonsGroup(String name, GroupHierarchyType context, String fie @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AutomaticPersonsGroup that = (AutomaticPersonsGroup) o; return Objects.equals(field, that.field); } diff --git a/src/main/java/org/jabref/model/groups/TexGroup.java b/src/main/java/org/jabref/model/groups/TexGroup.java index 3c0ef915db9..a9e7f82e006 100644 --- a/src/main/java/org/jabref/model/groups/TexGroup.java +++ b/src/main/java/org/jabref/model/groups/TexGroup.java @@ -59,9 +59,15 @@ public AbstractGroup deepCopy() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } TexGroup group = (TexGroup) o; return Objects.equals(filePath, group.filePath); } diff --git a/src/main/java/org/jabref/model/metadata/ContentSelectors.java b/src/main/java/org/jabref/model/metadata/ContentSelectors.java index 96269ff9349..7f841494bf2 100644 --- a/src/main/java/org/jabref/model/metadata/ContentSelectors.java +++ b/src/main/java/org/jabref/model/metadata/ContentSelectors.java @@ -21,7 +21,7 @@ public void addContentSelector(ContentSelector contentSelector) { } public List getSelectorValuesForField(String fieldName) { - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { if (selector.getFieldName().equals(fieldName)) { return selector.getValues(); } @@ -33,7 +33,7 @@ public List getSelectorValuesForField(String fieldName) { public void removeSelector(String fieldName) { ContentSelector toRemove = null; - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { if (selector.getFieldName().equals(fieldName)) { toRemove = selector; break; @@ -61,7 +61,7 @@ public static ContentSelector parse(String key, String values) { public List getFieldNamesWithSelectors() { List result = new ArrayList<>(contentSelectors.size()); - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { result.add(selector.getFieldName()); } @@ -70,8 +70,12 @@ public List getFieldNamesWithSelectors() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ContentSelectors that = (ContentSelectors) o; return Objects.equals(contentSelectors, that.contentSelectors); } diff --git a/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java b/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java index 0ac74f99233..15246db4681 100644 --- a/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java +++ b/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java @@ -28,16 +28,18 @@ public static void assertEquals(List expectedTexts, TextFlow description) } public static boolean checkIfTextsEqualsExpectedTexts(List texts, List expectedTexts) { - if (expectedTexts.size() != texts.size()) + if (expectedTexts.size() != texts.size()) { return false; + } Text expectedText; for (int i = 0; i < expectedTexts.size(); i++) { expectedText = expectedTexts.get(i); // the strings contain not only the text but also the font and other properties // so comparing them compares the Text object as a whole // the equals method is not implemented... - if (!expectedText.toString().equals(texts.get(i).toString())) + if (!expectedText.toString().equals(texts.get(i).toString())) { return false; + } } return true; } From e3da41f7792e69ce726c78586388f2ca5f72484e Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Sun, 28 Oct 2018 19:15:52 +0100 Subject: [PATCH 3/3] Fix two new issues --- .../gui/bibtexkeypattern/BibtexKeyPatternPanel.java | 11 ++++++----- src/main/java/org/jabref/gui/util/ThemeLoader.java | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 08a101c740d..994452e5efa 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -75,7 +75,7 @@ private void buildGUI() { rowIndex++; Label defaultPattern = new Label(Localization.lang("Default pattern")); Button button = new Button("Default"); - button.setOnAction(e-> defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); + button.setOnAction(e -> defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); gridPane.add(defaultPattern, 1, rowIndex); gridPane.add(defaultPat, 2, rowIndex); gridPane.add(button, 3, rowIndex); @@ -87,7 +87,7 @@ private void buildGUI() { Button button1 = new Button("Default"); button1.setOnAction(e1 -> textField.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); - gridPane.add(label1, 1 + (columnIndex * 3) , rowIndex); + gridPane.add(label1, 1 + (columnIndex * 3), rowIndex); gridPane.add(textField, 2 + (columnIndex * 3), rowIndex); gridPane.add(button1, 3 + (columnIndex * 3), rowIndex); @@ -96,18 +96,19 @@ private void buildGUI() { if (columnIndex == COLUMNS - 1) { columnIndex = 0; rowIndex++; - } else + } else { columnIndex++; + } } rowIndex++; Button help1 = new Button("?"); - help1.setOnAction(e->new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN).getHelpButton().doClick()); + help1.setOnAction(e -> new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN).getHelpButton().doClick()); gridPane.add(help1, 1, rowIndex); Button btnDefaultAll1 = new Button(Localization.lang("Reset all")); - btnDefaultAll1.setOnAction(e-> { + btnDefaultAll1.setOnAction(e -> { // reset all fields for (TextField field : textFields.values()) { field.setText(""); diff --git a/src/main/java/org/jabref/gui/util/ThemeLoader.java b/src/main/java/org/jabref/gui/util/ThemeLoader.java index 9c4e84ce3f6..5f152bfe36d 100644 --- a/src/main/java/org/jabref/gui/util/ThemeLoader.java +++ b/src/main/java/org/jabref/gui/util/ThemeLoader.java @@ -62,8 +62,8 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef /** - * Installs the base css file as a stylesheet in the given scene. - * Changes in the css file lead to a redraw of the scene using the new css file. + * Installs the base css file as a stylesheet in the given scene. Changes in the css file lead to a redraw of the + * scene using the new css file. */ public void installBaseCss(Scene scene, JabRefPreferences preferences) { if (!StringUtil.isNullOrEmpty(cssToLoad)) { @@ -78,7 +78,9 @@ public void installBaseCss(Scene scene, JabRefPreferences preferences) { private void addAndWatchForChanges(Scene scene, String cssUrl, int index) { // avoid repeat add - if (scene.getStylesheets().contains(cssUrl)) return; + if (scene.getStylesheets().contains(cssUrl)) { + return; + } scene.getStylesheets().add(index, cssUrl);