Skip to content

Commit

Permalink
refact: replace usage of Arrays.asList with List.of
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Aug 25, 2024
1 parent 804f5f1 commit 2d89929
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static org.eclipse.lsp4e.internal.NullSafetyHelper.lateNonNull;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -270,7 +269,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
if (arg == null) {
configuration.setAttribute(DSPPlugin.ATTR_DSP_ARGS, (String) null);
} else {
configuration.setAttribute(DSPPlugin.ATTR_DSP_ARGS, Arrays.asList(arg.split("\\s+"))); //$NON-NLS-1$
configuration.setAttribute(DSPPlugin.ATTR_DSP_ARGS, List.of(arg.split("\\s+"))); //$NON-NLS-1$
}
configuration.setAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER,
monitorAdapterLauncherProcessCheckbox.getSelection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.lsp4e.jdt;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -52,7 +51,7 @@ public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocat
lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset()));

try {
return Arrays.asList(asJavaProposals(future));
return List.of(asJavaProposals(future));
} catch (ExecutionException | TimeoutException e) {
LanguageServerPlugin.logError(e);
javaCompletionSpecificErrorMessage = createErrorMessage(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -272,7 +271,7 @@ public void testTextEditInsertSameOffset() throws Exception {
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), " throws "),
new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), "Exception") };
IDocument document = viewer.getDocument();
LSPEclipseUtils.applyEdits(document, Arrays.asList(edits));
LSPEclipseUtils.applyEdits(document, List.of(edits));
Assert.assertEquals(" throws Exception", document.get());
}

Expand All @@ -285,7 +284,7 @@ public void testTextEditSplittedLineEndings() throws Exception {
IDocument document = viewer.getDocument();
int linesBeforeApplyEdits = document.getNumberOfLines();
// WHEN the TextEdit gets applied to the document:
LSPEclipseUtils.applyEdits(document, Arrays.asList(edits));
LSPEclipseUtils.applyEdits(document, List.of(edits));
// THEN line1 has been swapped with line 3:
Assert.assertEquals("line3\r\nline2\r\nline1\r\n", document.get());
// AND the number of lines is still the same, because we have not appended a line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -86,7 +85,7 @@ private static InlayHintLabelPart createInlayLabelPart(String text, String comma

private static InlayHint createMultiLabelInlayHint(InlayHintLabelPart... parts) {
final var inlay = new InlayHint();
inlay.setLabel(Arrays.asList(parts));
inlay.setLabel(List.of(parts));
inlay.setPosition(new Position(0, 0));
return inlay;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -87,7 +88,7 @@ public void earlyStartup() {
private String getClassPath(Class<?> clazz) {
ClassLoader loader = clazz.getClassLoader();
if (loader instanceof URLClassLoader urlClassLoader) {
return Arrays.asList(urlClassLoader.getURLs()).stream().map(url -> url.getFile()).collect(Collectors.joining(System.getProperty("path.separator")));
return List.of(urlClassLoader.getURLs()).stream().map(url -> url.getFile()).collect(Collectors.joining(System.getProperty("path.separator")));
}
final var toProcess = new LinkedList<Bundle>();
final var processed = new HashSet<Bundle>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -97,7 +96,7 @@ public static List<IEditorReference> splitActiveEditor() {
editorPart.getTags().add(IPresentationEngine.SPLIT_HORIZONTAL);
}

return Arrays.asList(page.getEditorReferences());
return List.of(page.getEditorReferences());
}

public static IEditorPart openExternalFileInEditor(File file) throws PartInitException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.eclipse.lsp4e.tests.mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -326,7 +325,7 @@ public void setDocumentSymbols(DocumentSymbol documentSymbol) {
}

public void setDocumentSymbols(DocumentSymbol... documentSymbols) {
this.textDocumentService.setDocumentSymbols(Arrays.asList(documentSymbols));
this.textDocumentService.setDocumentSymbols(List.of(documentSymbols));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -165,7 +164,7 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio

@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
return futureFactory(Arrays.asList(this.mockReferences));
return futureFactory(List.of(this.mockReferences));
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,7 @@ public static List<IContentType> getDocumentContentTypes(IDocument document) {
String fileName = getFileName(buffer);
if (fileName != null) {
try (var contents = new DocumentInputStream(document)) {
contentTypes
.addAll(Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(contents, fileName)));
contentTypes.addAll(List.of(Platform.getContentTypeManager().findContentTypesFor(contents, fileName)));
} catch (IOException e) {
LanguageServerPlugin.logError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -444,8 +443,8 @@ public boolean matches(IDocument document, LanguageServerDefinition serverDefini
}

public boolean canUseLanguageServer(IEditorInput editorInput) {
return !getAvailableLSFor(
Arrays.asList(Platform.getContentTypeManager().findContentTypesFor(editorInput.getName())), LSPEclipseUtils.toUri(editorInput)).isEmpty();
return !getAvailableLSFor(List.of(Platform.getContentTypeManager().findContentTypesFor(editorInput.getName())),
LSPEclipseUtils.toUri(editorInput)).isEmpty();
}

public boolean canUseLanguageServer(IDocument document) {
Expand Down

0 comments on commit 2d89929

Please sign in to comment.