Skip to content

Commit

Permalink
refact: use Set.of where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Aug 21, 2024
1 parent 976691a commit 0b96183
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -200,9 +199,7 @@ public void testCompleteOnFileEnd() throws CoreException { // bug 508842

@Test
public void testTriggerCharsWithoutPreliminaryCompletion() throws CoreException { // bug 508463
final var triggers = new HashSet<String>();
triggers.add("a");
triggers.add("b");
final Set<String> triggers = Set.of("a", "b");
MockLanguageServer.INSTANCE.setCompletionTriggerChars(triggers);

final var content = "First";
Expand Down Expand Up @@ -368,13 +365,13 @@ public void testChoiceSnippet() throws CoreException {
int invokeOffset = 0;
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(viewer, invokeOffset);
assertEquals(1, proposals.length);
final var beforeShells = new HashSet<>(List.of(viewer.getTextWidget().getDisplay().getShells()));
final var shellsBefore = Set.of(viewer.getTextWidget().getDisplay().getShells());
((LSCompletionProposal) proposals[0]).apply(viewer, '\n', 0, invokeOffset);
assertEquals("1a2", viewer.getDocument().get());
final var newShells = new HashSet<>(List.of(viewer.getTextWidget().getDisplay().getShells()));
newShells.removeAll(beforeShells);
assertNotEquals(Collections.emptySet(), newShells);
final var proposalList = (Table) newShells.iterator().next().getChildren()[0];
final var shellsAfter = Set.of(viewer.getTextWidget().getDisplay().getShells());
final var shellsAdded = shellsAfter.stream().filter(shell -> !shellsBefore.contains(shell)).toList();
assertFalse(shellsAdded.isEmpty());
final var proposalList = (Table) shellsAdded.iterator().next().getChildren()[0];
String[] itemLabels = Arrays.stream(proposalList.getItems()).map(TableItem::getText).toArray(String[]::new);
assertArrayEquals(new String[] {"a", "b"}, itemLabels);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import static org.junit.Assert.*;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -70,9 +70,7 @@ public void testContextInformationNoParameters() throws CoreException {

@Test
public void testTriggerChars() throws CoreException {
final var triggers = new HashSet<String>();
triggers.add("a");
triggers.add("b");
final Set<String> triggers = Set.of("a", "b");
MockLanguageServer.INSTANCE.setContextInformationTriggerChars(triggers);

final var content = "First";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*******************************************************************************/
package org.eclipse.lsp4e;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -75,7 +73,7 @@ public Set<String> getLaunchModes() {
String launchName = launchParts[1];
Set<String> launchModes = Collections.singleton(ILaunchManager.RUN_MODE);
if (launchParts.length > 2) {
launchModes = new HashSet<>(Arrays.asList(launchParts[2].split("\\+"))); //$NON-NLS-1$
launchModes = Set.of(launchParts[2].split("\\+")); //$NON-NLS-1$
}
IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId);
if (contentType == null) {
Expand Down

0 comments on commit 0b96183

Please sign in to comment.