Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable OpenRewrite's UnnecessaryParentheses #9876

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ recipeList:
# - org.openrewrite.java.cleanup.StaticMethodNotFinal
- org.openrewrite.java.cleanup.StringLiteralEquality
- org.openrewrite.java.cleanup.TypecastParenPad
# - org.openrewrite.java.cleanup.UnnecessaryParentheses
- org.openrewrite.java.cleanup.UnnecessaryParentheses
- org.openrewrite.java.cleanup.UnwrapRepeatableAnnotations
- org.openrewrite.java.cleanup.UpperCaseLiteralSuffixes
# - org.openrewrite.java.cleanup.UseJavaStyleArrayDeclarations
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/EntryTypeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public EntryTypeView(LibraryTab libraryTab, DialogService dialogService, Prefere

Button btnGenerate = (Button) this.getDialogPane().lookupButton(generateButton);

btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> (searching) ? Localization.lang("Searching...") : Localization.lang("Generate")));
btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> searching ? Localization.lang("Searching...") : Localization.lang("Generate")));
btnGenerate.disableProperty().bind(viewModel.idFieldValidationStatus().validProperty().not().or(viewModel.searchingProperty()));

EasyBind.subscribe(viewModel.searchSuccesfulProperty(), value -> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void notify(String message) {
.text(
"(" + Localization.lang("Check the event log to see all notifications") + ")"
+ "\n\n" + message)
.onAction((e)-> {
.onAction(e-> {
ErrorConsoleAction ec = new ErrorConsoleAction();
ec.execute();
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BackupResolverDialog(Path originalPath, Path backupDir) {

HyperlinkLabel contentLabel = new HyperlinkLabel(content);
contentLabel.setPrefWidth(360);
contentLabel.setOnAction((e) -> {
contentLabel.setOnAction(e -> {
if (backupPathOpt.isPresent()) {
if (!(e.getSource() instanceof Hyperlink)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void parseUsingGrobid() {
GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getGrobidPreferences(), preferencesService.getImportFormatPreferences());
BackgroundTask.wrap(() -> grobidCitationFetcher.performSearch(inputTextProperty.getValue()))
.onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed...")))
.onFailure((e) -> {
.onFailure(e -> {
if (e instanceof FetcherException) {
String msg = Localization.lang("There are connection issues with a JabRef server. Detailed information: %0",
e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ExtractBibtexDialog() {

buttonParse = (Button) getDialogPane().lookupButton(parseButtonType);
buttonParse.setTooltip(new Tooltip((Localization.lang("Starts the extraction and adds the resulting entries to the currently opened database"))));
buttonParse.setOnAction((event) -> viewModel.startParsing());
buttonParse.setOnAction(event -> viewModel.startParsing());
buttonParse.disableProperty().bind(viewModel.inputTextProperty().isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void execute() {
Localization.lang("Copy linked files to folder..."),
exportTask);
Globals.TASK_EXECUTOR.execute(exportTask);
exportTask.setOnSucceeded((e) -> showDialog(exportTask.getValue()));
exportTask.setOnSucceeded(e -> showDialog(exportTask.getValue()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ private void setupTable() {
}));

tvResult.setItems(viewModel.copyFilesResultListProperty());
tvResult.setColumnResizePolicy((param) -> true);
tvResult.setColumnResizePolicy(param -> true);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void openFolderAndSelectFile(Path filePath) throws IOException {
cmd = new String[] {"nemo", absoluteFilePath}; // Although nemo is based on nautilus it does not support --select, it directly highlights the file
}
}
ProcessBuilder processBuilder = new ProcessBuilder((cmd));
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
Process process = processBuilder.start();

StreamGobbler streamGobblerInput = new StreamGobbler(process.getInputStream(), LOGGER::debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void execute() {
}

private void searchPossibleDuplicates(List<BibEntry> entries, BibDatabaseMode databaseMode) {
for (int i = 0; (i < (entries.size() - 1)); i++) {
for (int j = i + 1; (j < entries.size()); j++) {
for (int i = 0; i < (entries.size() - 1); i++) {
for (int j = i + 1; j < entries.size(); j++) {
if (Thread.interrupted()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void setupContentProperties(FileAnnotation annotation) {
this.content.set(annotation.getLinkedFileAnnotation().getContent());
String annotationContent = annotation.getContent();
String illegibleTextMessage = Localization.lang("The marked area does not contain any legible text!");
String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
String markingContent = annotationContent.isEmpty() ? illegibleTextMessage : annotationContent;
this.marking.set(removePunctuationMark(markingContent));
} else {
String content = annotation.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public String getStyleClass() {
public JabRefIcon getIcon() {
switch (logEvent.getLevel()) {
case ERROR:
return (IconTheme.JabRefIcons.INTEGRITY_FAIL);
return IconTheme.JabRefIcons.INTEGRITY_FAIL;
case WARN:
return (IconTheme.JabRefIcons.INTEGRITY_WARN);
return IconTheme.JabRefIcons.INTEGRITY_WARN;
case INFO:
default:
return (IconTheme.JabRefIcons.INTEGRITY_INFO);
return IconTheme.JabRefIcons.INTEGRITY_INFO;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void initResultTable() {

colStatus.setCellValueFactory(cellData -> cellData.getValue().icon());
colStatus.setCellFactory(new ValueTableCellFactory<ImportFilesResultItemViewModel, JabRefIcon>().withGraphic(JabRefIcon::getGraphicNode));
importResultTable.setColumnResizePolicy((param) -> true);
importResultTable.setColumnResizePolicy(param -> true);

importResultTable.setItems(viewModel.resultTableItems());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void moveToDefaultDirectory() {
}

Optional<Path> file = linkedFile.findIn(databaseContext, preferences.getFilePreferences());
if ((file.isPresent())) {
if (file.isPresent()) {
// Found the linked file, so move it
try {
linkedFileHandler.moveToDefaultDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class GroupNodeViewModel {
private final CustomLocalDragboard localDragBoard;
private final ObservableList<BibEntry> entriesList;
private final PreferencesService preferencesService;
private final InvalidationListener onInvalidatedGroup = (listener) -> refreshGroup();
private final InvalidationListener onInvalidatedGroup = listener -> refreshGroup();

public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager stateManager, TaskExecutor taskExecutor, GroupTreeNode groupNode, CustomLocalDragboard localDragBoard, PreferencesService preferencesService) {
this.databaseContext = Objects.requireNonNull(databaseContext);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void initialize() {
BindingsHelper.bindContentBidirectional(
groupTree.getSelectionModel().getSelectedItems(),
viewModel.selectedGroupsProperty(),
(newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode),
newSelectedGroups -> newSelectedGroups.forEach(this::selectNode),
this::updateSelection
));

Expand Down Expand Up @@ -275,7 +275,7 @@ private StackPane createNumberCell(GroupNodeViewModel group) {
}
Text text = new Text();
EasyBind.subscribe(preferencesService.getGroupsPreferences().displayGroupCountProperty(),
(newValue) -> {
newValue -> {
if (text.textProperty().isBound()) {
text.textProperty().unbind();
text.setText("");
Expand Down Expand Up @@ -442,11 +442,11 @@ private void setupDragScrolling() {
scrollBar.setValue(newValue);
}));

groupTree.setOnScroll((event) -> scrollTimer.stop());
groupTree.setOnDragDone((event) -> scrollTimer.stop());
groupTree.setOnDragEntered((event) -> scrollTimer.stop());
groupTree.setOnDragDropped((event) -> scrollTimer.stop());
groupTree.setOnDragExited((event) -> {
groupTree.setOnScroll(event -> scrollTimer.stop());
groupTree.setOnDragDone(event -> scrollTimer.stop());
groupTree.setOnDragEntered(event -> scrollTimer.stop());
groupTree.setOnDragDropped(event -> scrollTimer.stop());
groupTree.setOnDragExited(event -> {
if (event.getY() > 0) {
scrollVelocity = 1.0 / SCROLL_SPEED;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ boolean onlyMinorChanges(AbstractGroup oldGroup, AbstractGroup newGroup) {
return Objects.equals(oldRegexKeywordGroup.getSearchField().getName(), newRegexKeywordGroup.getSearchField().getName())
&& Objects.equals(oldRegexKeywordGroup.getSearchExpression(), newRegexKeywordGroup.getSearchExpression())
&& Objects.equals(oldRegexKeywordGroup.isCaseSensitive(), newRegexKeywordGroup.isCaseSensitive());
} else if ((oldGroup.getClass() == SearchGroup.class)) {
} else if (oldGroup.getClass() == SearchGroup.class) {
SearchGroup oldSearchGroup = (SearchGroup) oldGroup;
SearchGroup newSearchGroup = (SearchGroup) newGroup;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void execute() {
backgroundTask.titleProperty().set(Localization.lang("Import by ID"));
backgroundTask.showToUser(true);
backgroundTask.onRunning(() -> dialogService.notify("%s".formatted(backgroundTask.messageProperty().get())));
backgroundTask.onFailure((exception) -> {
backgroundTask.onFailure(exception -> {
String fetcherExceptionMessage = exception.getMessage();

String msg;
Expand All @@ -76,7 +76,7 @@ public void execute() {
preferencesService, stateManager).execute();
}
});
backgroundTask.onSuccess((bibEntry) -> {
backgroundTask.onSuccess(bibEntry -> {
Optional<BibEntry> result = bibEntry;
if (result.isPresent()) {
final BibEntry entry = result.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService,
Localization.lang("Remote services"),
Localization.lang("Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results."),
Localization.lang("Do not ask again"),
(optOut) -> preferences.grobidOptOutProperty().setValue(optOut));
optOut -> preferences.grobidOptOutProperty().setValue(optOut));
preferences.grobidEnabledProperty().setValue(grobidEnabled);
return grobidEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GeneralPropertiesViewModel implements PropertiesTabViewModel {

@Override
public void setValues() {
boolean isShared = (databaseContext.getLocation() == DatabaseLocation.SHARED);
boolean isShared = databaseContext.getLocation() == DatabaseLocation.SHARED;
encodingDisableProperty.setValue(isShared); // the encoding of shared database is always UTF-8

selectedEncodingProperty.setValue(metaData.getEncoding().orElse(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public OpenFolderAction(DialogService dialogService, StateManager stateManager,
public void execute() {
stateManager.getActiveDatabase().ifPresent(databaseContext -> {
if (entry == null) {
stateManager.getSelectedEntries().stream().filter((entry) -> !entry.getFiles().isEmpty()).forEach(entry -> {
stateManager.getSelectedEntries().stream().filter(entry -> !entry.getFiles().isEmpty()).forEach(entry -> {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
entry.getFiles().get(0),
entry,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/openoffice/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static final XComponentContext bootstrap(String[] argArray, Path path) th
// We need a socket, pipe does not work. https://api.libreoffice.org/examples/examples.html
String[] cmdArray = new String[argArray.length + 2];
cmdArray[0] = path.toAbsolutePath().toString();
cmdArray[1] = ("--accept=socket,host=localhost,port=2083" + ";urp;");
cmdArray[1] = "--accept=socket,host=localhost,port=2083" + ";urp;";

System.arraycopy(argArray, 0, cmdArray, 2, argArray.length);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ void showDialog(String errorTitle, OOError err) {
}

OOVoidResult<OOError> collectResults(String errorTitle, List<OOVoidResult<OOError>> results) {
String msg = (results.stream()
String msg = results.stream()
.filter(OOVoidResult::isError)
.map(e -> e.getError().getLocalizedMessage())
.collect(Collectors.joining("\n\n")));
.collect(Collectors.joining("\n\n"));
if (msg.isEmpty()) {
return OOVoidResult.ok();
} else {
Expand Down Expand Up @@ -219,11 +219,11 @@ private static OOVoidResult<OOError> checkRangeOverlaps(XTextDocument doc, OOFro
boolean requireSeparation = false;
int maxReportedOverlaps = 10;
try {
return (frontend.checkRangeOverlaps(doc,
return frontend.checkRangeOverlaps(doc,
new ArrayList<>(),
requireSeparation,
maxReportedOverlaps)
.mapError(OOError::from));
.mapError(OOError::from);
} catch (NoDocumentException ex) {
return OOVoidResult.error(OOError.from(ex).setTitle(errorTitle));
} catch (WrappedTargetException ex) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/openoffice/OOBibBaseConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public String toString() {
}
}

List<DocumentTitleViewModel> viewModel = (list.stream()
List<DocumentTitleViewModel> viewModel = list.stream()
.map(DocumentTitleViewModel::new)
.collect(Collectors.toList()));
.collect(Collectors.toList());

// This whole method is part of a background task when
// auto-detecting instances, so we need to show dialog in FX
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ private boolean getOrUpdateTheStyle(String title) {
style.ensureUpToDate();
} catch (IOException ex) {
LOGGER.warn("Unable to reload style file '" + style.getPath() + "'", ex);
String msg = (Localization.lang("Unable to reload style file")
String msg = Localization.lang("Unable to reload style file")
+ "'" + style.getPath() + "'"
+ "\n" + ex.getMessage());
+ "\n" + ex.getMessage();
new OOError(title, msg, ex).showErrorDialog(dialogService);
return FAIL;
}
Expand Down Expand Up @@ -330,15 +330,15 @@ private void connectManually() {
}

private void updateButtonAvailability() {
boolean isConnected = (ooBase != null);
boolean isConnected = ooBase != null;
boolean isConnectedToDocument = isConnected && !ooBase.isDocumentConnectionMissing();

// For these, we need to watch something
boolean hasStyle = true; // (style != null);
boolean hasDatabase = true; // !getBaseList().isEmpty();
boolean hasSelectedBibEntry = true;

selectDocument.setDisable(!(isConnected));
selectDocument.setDisable(!isConnected);
pushEntries.setDisable(!(isConnectedToDocument && hasStyle && hasDatabase));

boolean canCite = isConnectedToDocument && hasStyle && hasSelectedBibEntry;
Expand Down Expand Up @@ -418,9 +418,9 @@ private static CitationType citationTypeFromOptions(boolean withText, boolean in
if (!withText) {
return CitationType.INVISIBLE_CIT;
}
return (inParenthesis
return inParenthesis
? CitationType.AUTHORYEAR_PAR
: CitationType.AUTHORYEAR_INTEXT);
: CitationType.AUTHORYEAR_INTEXT;
}

private void pushEntries(CitationType citationType, boolean addPageInfo) {
Expand Down Expand Up @@ -477,9 +477,9 @@ private void pushEntries(CitationType citationType, boolean addPageInfo) {
}

Optional<Update.SyncOptions> syncOptions =
(preferencesService.getOpenOfficePreferences().getSyncWhenCiting()
preferencesService.getOpenOfficePreferences().getSyncWhenCiting()
? Optional.of(new Update.SyncOptions(getBaseList()))
: Optional.empty());
: Optional.empty();

ooBase.guiActionInsertEntry(entries,
database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void initialize() {
return null;
}
String lowerCaseSearchText = searchText.toLowerCase(Locale.ROOT);
return (option) -> option.getKey().toLowerCase(Locale.ROOT).contains(lowerCaseSearchText);
return option -> option.getKey().toLowerCase(Locale.ROOT).contains(lowerCaseSearchText);
}));
columnType.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getType()));
columnKey.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void setupEntryTypesTable() {
})
.withTooltip((type, name) -> {
if (type instanceof CustomEntryTypeViewModel) {
return (Localization.lang("Remove entry type") + " " + name);
return Localization.lang("Remove entry type") + " " + name;
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CustomEntryTypesTabViewModel implements PreferenceTabViewModel {
private final Validator fieldValidator;
private final Set<Field> multiLineFields = new HashSet<>();

Predicate<Field> isMultiline = (field) -> this.multiLineFields.contains(field) || field.getProperties().contains(FieldProperty.MULTILINE_TEXT);
Predicate<Field> isMultiline = field -> this.multiLineFields.contains(field) || field.getProperties().contains(FieldProperty.MULTILINE_TEXT);

public CustomEntryTypesTabViewModel(BibDatabaseMode mode,
BibEntryTypesManager entryTypesManager,
Expand Down
Loading