Skip to content

Commit

Permalink
refact: simplify lambda expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Dec 19, 2024
1 parent e517e00 commit b64d98b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testConnect() throws Exception {
assertEquals(1, wrappers.size());

LanguageServerWrapper wrapper = wrappers.iterator().next();
waitForAndAssertCondition(2_000, () -> wrapper.isActive());
waitForAndAssertCondition(2_000, wrapper::isActive);

// e.g. LanguageServerWrapper@69fe8c75 [serverId=org.eclipse.lsp4e.test.server-with-multi-root-support, initialPath=null, initialProject=P/LanguageServerWrapperTest_testConnect_11691664858710, isActive=true]
assertThat(wrapper.toString(), matchesPattern("LanguageServerWrapper@[0-9a-f]+ \\[serverId=org.eclipse.lsp4e.test.server-with-multi-root-support, initialPath=null, initialProject=P\\/LanguageServerWrapperTest_testConnect_[0-9]+, isActive=true, pid=(null|[0-9])+\\]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private LanguageClient getMockClient() {
}

private Predicate<ServerCapabilities> handlesCommand(String command) {
return (cap) -> {
return cap -> {
ExecuteCommandOptions commandProvider = cap.getExecuteCommandProvider();
return commandProvider != null && commandProvider.getCommands().contains(command);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testRenameHandlerEnablement() throws Exception {
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_RENAME);

waitForAndAssertCondition(2_000, () -> command.isEnabled());
waitForAndAssertCondition(2_000, command::isEnabled);
assertTrue(command.isHandled());
}

Expand Down Expand Up @@ -238,7 +238,7 @@ public void testRenameHandlerExecution() throws Exception {
display.addFilter(SWT.Paint, pressOKonRenameDialogPaint);
ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, e);
command.executeWithChecks(executionEvent);
waitForAndAssertCondition("Rename dialog not shown", 3_000, display, () -> renameDialogOkPressed.get());
waitForAndAssertCondition("Rename dialog not shown", 3_000, display, renameDialogOkPressed::get);
IDocument document = LSPEclipseUtils.getDocument(editor);
waitForAndAssertCondition("document not modified, rename not applied", 3_000, display,
() -> "new".equals(document.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ public Object getData() {
};

public static Function<String, IToken> keywordTokenTypeMapper(final IToken token) {
return t -> {
if ("keyword".equals(t)) {
return token;
}
return null;
};
return t -> "keyword".equals(t) ? token : null;
}

public static @NonNull Function<Position, Integer> offsetMapper(IDocument document) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package org.eclipse.lsp4e.test.utils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void earlyStartup() {
private String getClassPath(Class<?> clazz) {
ClassLoader loader = clazz.getClassLoader();
if (loader instanceof URLClassLoader urlClassLoader) {
return List.of(urlClassLoader.getURLs()).stream().map(url -> url.getFile()).collect(Collectors.joining(System.getProperty("path.separator")));
return List.of(urlClassLoader.getURLs()).stream().map(URL::getFile).collect(Collectors.joining(System.getProperty("path.separator")));
}
final var toProcess = new LinkedList<Bundle>();
final var processed = new HashSet<Bundle>();
Expand All @@ -108,13 +108,8 @@ private String getClassPath(Class<?> clazz) {
}
return processed.stream()
.filter(bundle -> bundle.getBundleId() != 0)
.map(bundle -> {
try {
return FileLocator.getBundleFile(bundle);
} catch (IOException e) {
return null;
}
}).flatMap(location -> {
.map(bundle -> FileLocator.getBundleFileLocation(bundle).orElse(null))
.flatMap(location -> {
if (location.isFile()) {
return Arrays.stream(new String[] { location.getAbsolutePath() });
}
Expand Down
16 changes: 7 additions & 9 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,13 @@ private static boolean applyWorkspaceEditIfSingleOpenFile(WorkspaceEdit wsEdit)
.filter(Objects::nonNull)
.findFirst();

doc.ifPresent(document -> {
UI.getDisplay().syncExec(() -> {
try {
LSPEclipseUtils.applyEdits(document, firstDocumentEdits);
} catch (BadLocationException ex) {
LanguageServerPlugin.logError(ex);
}
});
});
doc.ifPresent(document -> UI.getDisplay().syncExec(() -> {
try {
LSPEclipseUtils.applyEdits(document, firstDocumentEdits);
} catch (BadLocationException ex) {
LanguageServerPlugin.logError(ex);
}
}));
return doc.isPresent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ public void setLabel(final @Nullable String label) {
}

protected static @Nullable String getInlayHintString(InlayHint inlayHint) {
Either<String, @Nullable List<InlayHintLabelPart>> label = inlayHint.getLabel();
return label.map(Function.identity(), (parts) -> {
if (parts == null) {
return null;
}
return parts.stream().map(InlayHintLabelPart::getValue).collect(Collectors.joining());
});
return inlayHint.getLabel().map(Function.identity(), parts -> parts == null //
? null
: parts.stream().map(InlayHintLabelPart::getValue).collect(Collectors.joining()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected void execute(ExecutionEvent event, ITextEditor textEditor) {
// TODO maybe consider better strategy such as iterating on all LS until we have
// a good result
LanguageServers.forDocument(document).withCapability(ServerCapabilities::getDocumentSymbolProvider)
.computeFirst((w, ls) -> CompletableFuture.completedFuture(w))
.thenAcceptAsync(oW -> oW.ifPresent(w -> {
new LSPSymbolInFileDialog(shell, textEditor, document, w).open();
}), shell.getDisplay());
.computeFirst((w, ls) -> CompletableFuture.completedFuture(w)) //
.thenAcceptAsync(
oW -> oW.ifPresent(w -> new LSPSymbolInFileDialog(shell, textEditor, document, w).open()),
shell.getDisplay());
}

@Override
Expand Down

0 comments on commit b64d98b

Please sign in to comment.