Skip to content

Commit

Permalink
Add Checkstyle settings for newline after catch brace (#12189)
Browse files Browse the repository at this point in the history
* [Test] Add settings for newline after catch brace

* [Test] Remove option `KEEP_CONTROL_STATEMENT_IN_ONE_LINE=true`

* [Test] Remove other unnecessary experimental options

* [Test] Remove redundant "catch in newline" check

* Discard changes to src/main/java/org/jabref/cli/ArgumentProcessor.java

* Resolve violations in codebase

* Add newline gap

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
subhramit and koppor authored Nov 16, 2024
1 parent 5f1dd59 commit fd6d06e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config/IntelliJ Code Style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,4 @@
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</code_scheme>
7 changes: 7 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
<property name="fileExtensions" value="groovy,java" />
</module>

<!-- Prevent newline after catch opening parenthesis -->
<module name="RegexpMultiline">
<property name="message" value="No newline allowed after catch opening parenthesis" />
<property name="format" value="catch\s*\(\s*[\r]?\n" />
<property name="fileExtensions" value="groovy,java" />
</module>

<!-- Checks for size violations: https://checkstyle.sourceforge.io/config_sizes.html -->

<!-- LineLength not in place as PreviewerViewer and RelatedArticlesTab have line length with more than 500 charachters -->
Expand Down
7 changes: 7 additions & 0 deletions config/checkstyle/checkstyle_reviewdog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
<property name="fileExtensions" value="groovy,java" />
</module>

<!-- Prevent newline after catch opening parenthesis -->
<module name="RegexpMultiline">
<property name="message" value="No newline allowed after catch opening parenthesis" />
<property name="format" value="catch\s*\(\s*[\r]?\n" />
<property name="fileExtensions" value="groovy,java" />
</module>

<!-- Checks for size violations: https://checkstyle.sourceforge.io/config_sizes.html -->

<!-- LineLength not in place as PreviewerViewer and RelatedArticlesTab have line length with more than 500 charachters -->
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ public void pasteEntry() {
private List<BibEntry> handleNonBibTeXStringData(String data) {
try {
return this.importHandler.handleStringData(data);
} catch (
FetcherException exception) {
} catch (FetcherException exception) {
if (exception instanceof FetcherClientException) {
dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("No data was found for the identifier"));
} else if (exception instanceof FetcherServerException) {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/jabref/gui/frame/JabRefFrameViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,10 @@ private void openDatabases(List<ParserResult> parserResults) {
undoManager,
clipBoardManager,
taskExecutor);
} catch (
SQLException |
DatabaseNotSupportedException |
InvalidDBMSConnectionPropertiesException |
NotASharedDatabaseException e) {
} catch (SQLException
| DatabaseNotSupportedException
| InvalidDBMSConnectionPropertiesException
| NotASharedDatabaseException e) {
LOGGER.error("Connection error", e);
dialogService.showErrorDialogAndWait(
Localization.lang("Connection error"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public void editStyle() {
Optional<ExternalFileType> type = ExternalFileTypes.getExternalFileTypeByExt("jstyle", externalApplicationsPreferences);
try {
NativeDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), externalApplicationsPreferences, filePreferences, jStyle.getPath(), type);
} catch (
IOException e) {
} catch (IOException e) {
dialogService.showErrorDialogAndWait(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ private void updateDirectoryWarning(Path directory) {
} else {
directoryWarning.setVisible(false);
}
} catch (
IOException e) {
} catch (IOException e) {
directoryWarning.setText(Localization.lang("Warning: Failed to check if the directory is empty."));
directoryWarning.setVisible(true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/logic/openoffice/action/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private static List<String> updateDocument(XTextDocument doc,
}

return frontend.citationGroups.getUnresolvedKeys();
} catch (
IOException e) {
} catch (IOException e) {
Logger.warn("Error while updating document", e);
} finally {
if (useLockControllers && UnoScreenRefresh.hasControllersLocked(doc)) {
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/org/jabref/logic/os/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public static String getHostName() {
if (StringUtil.isBlank(hostName)) {
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (
UnknownHostException e) {
} catch (UnknownHostException e) {
LoggerFactory.getLogger(OS.class).info("Hostname not found. Using \"localhost\" as fallback.", e);
hostName = "localhost";
}
Expand All @@ -65,12 +64,10 @@ public static boolean isKeyringAvailable() {
return false;
}
keyring.deletePassword("JabRef", "keyringTest");
} catch (
BackendNotSupportedException ex) {
} catch (BackendNotSupportedException ex) {
LoggerFactory.getLogger(OS.class).warn("Credential store not supported.");
return false;
} catch (
PasswordAccessException ex) {
} catch (PasswordAccessException ex) {
LoggerFactory.getLogger(OS.class).warn("Password storage in credential store failed.");
return false;
} catch (Exception ex) {
Expand All @@ -90,9 +87,8 @@ public static String detectProgramPath(String programName, String directoryName)
try {
ShellLink link = new ShellLink(texworksLinkPath);
return link.resolveTarget();
} catch (
IOException |
ShellLinkException e) {
} catch (IOException
| ShellLinkException e) {
// Static logger instance cannot be used. See the class comment.
Logger logger = Logger.getLogger(OS.class.getName());
logger.log(Level.WARNING, "Had an error while reading .lnk file for TeXworks", e);
Expand Down

0 comments on commit fd6d06e

Please sign in to comment.