diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/LanguageServersTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/LanguageServersTest.java index 4228469dd..b47438c03 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/LanguageServersTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/LanguageServersTest.java @@ -13,14 +13,8 @@ package org.eclipse.lsp4e.test; import static org.eclipse.lsp4e.LanguageServiceAccessor.hasActiveLanguageServers; -import static org.eclipse.lsp4e.test.utils.TestUtils.createUniqueTestFile; -import static org.eclipse.lsp4e.test.utils.TestUtils.openEditor; -import static org.eclipse.lsp4e.test.utils.TestUtils.waitForCondition; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.eclipse.lsp4e.test.utils.TestUtils.*; +import static org.junit.Assert.*; import java.util.Collections; import java.util.List; @@ -685,10 +679,10 @@ public void testWrapperWrapsSameLS() throws Exception { final AtomicInteger matching = new AtomicInteger(); assertEquals("Should have had two responses", 2, result.size()); - assertNotEquals("LS should have been different proxies", result.get(0).getSecond(), result.get(1).getSecond()); + assertNotEquals("LS should have been different proxies", result.get(0).second(), result.get(1).second()); result.forEach(p -> { - p.getFirst().execute(ls -> { - if (ls == p.getSecond()) { + p.first().execute(ls -> { + if (ls == p.second()) { matching.incrementAndGet(); } return CompletableFuture.completedFuture(null); diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/references/FindReferencesTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/references/FindReferencesTest.java index 64d138043..feb592ff8 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/references/FindReferencesTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/references/FindReferencesTest.java @@ -182,7 +182,7 @@ private void waitForAndAssertSearchResult(CompletableFuture ls.getTextDocumentService().prepareCallHierarchy(prepareParams) .thenApply(result -> new Pair<>(w, result))).thenAccept(o -> o.ifPresentOrElse(p -> { - languageServerWrapper = p.getFirst(); - List hierarchyItems = p.getSecond(); + languageServerWrapper = p.first(); + List hierarchyItems = p.second(); if (!hierarchyItems.isEmpty()) { rootItems = new ArrayList<>(hierarchyItems.size()); for (CallHierarchyItem item : hierarchyItems) { diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/Pair.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/Pair.java index ccb420373..cb12e90eb 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/Pair.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/Pair.java @@ -11,43 +11,10 @@ *******************************************************************************/ package org.eclipse.lsp4e.internal; -import java.util.Objects; +public record Pair(F first, S second) { -public final class Pair { - private final F first; - private final S second; - - public Pair(F first, S second) { - this.first = first; - this.second = second; - } - - public S getSecond() { - return second; - } - - public F getFirst() { - return first; + public static Pair of(final F first, final S second) { + return new Pair<>(first, second); } - @Override - public int hashCode() { - return Objects.hash(first, second); - } - - public static Pair of(F first, S second) { - return new Pair(first, second); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Pair other = (Pair) obj; - return Objects.equals(first, other.first) && Objects.equals(second, other.second); - } } diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java index fbfcaa842..000631143 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java @@ -68,7 +68,7 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo .collectAll(ls -> ls.getTextDocumentService().implementation(LSPEclipseUtils.toImplementationParams(params)).thenApply(l -> Pair.of(Messages.implementationHyperlinkLabel, l))); LanguageServers.addAll(LanguageServers.addAll(LanguageServers.addAll(definitions, declarations), typeDefinitions), implementations) .get(800, TimeUnit.MILLISECONDS) - .stream().flatMap(locations -> toHyperlinks(document, region, locations.getFirst(), locations.getSecond()).stream()) + .stream().flatMap(locations -> toHyperlinks(document, region, locations.first(), locations.second()).stream()) .forEach(link -> allLinks.putIfAbsent(link.getLocation(), link)); } catch (ExecutionException e) { LanguageServerPlugin.logError(e); diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/rename/LSPRenameProcessor.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/rename/LSPRenameProcessor.java index 038133b82..1e9bef792 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/rename/LSPRenameProcessor.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/rename/LSPRenameProcessor.java @@ -116,14 +116,14 @@ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) .get(1000, TimeUnit.MILLISECONDS); Optional>> tmp = list - .stream().filter(Objects::nonNull).filter(t -> t.getSecond() != null).findFirst(); + .stream().filter(Objects::nonNull).filter(t -> t.second() != null).findFirst(); if (tmp.isEmpty()) { status.addFatalError(Messages.rename_invalidated); } else { tmp.ifPresent(p -> { - refactoringServer = p.getFirst(); - prepareRenameResult = p.getSecond(); + refactoringServer = p.first(); + prepareRenameResult = p.second(); }); } } catch (TimeoutException e) { diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/semanticTokens/SemanticHighlightReconcilerStrategy.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/semanticTokens/SemanticHighlightReconcilerStrategy.java index 78dc5e70c..628b034ac 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/semanticTokens/SemanticHighlightReconcilerStrategy.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/semanticTokens/SemanticHighlightReconcilerStrategy.java @@ -181,8 +181,8 @@ private SemanticTokensParams getSemanticTokensParams() { } private void saveStyle(final Pair pair) { - final SemanticTokens semanticTokens = pair.getFirst(); - final SemanticTokensLegend semanticTokensLegend = pair.getSecond(); + final SemanticTokens semanticTokens = pair.first(); + final SemanticTokensLegend semanticTokensLegend = pair.second(); // Skip any processing if not installed or at least one of the pair values is null if (!isInstalled || semanticTokens == null || semanticTokensLegend == null) { diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/typeHierarchy/TypeHierarchyViewContentProvider.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/typeHierarchy/TypeHierarchyViewContentProvider.java index 8d0885b1c..ffecaf251 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/typeHierarchy/TypeHierarchyViewContentProvider.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/typeHierarchy/TypeHierarchyViewContentProvider.java @@ -118,9 +118,9 @@ private void initialise(final @NonNull IDocument document, final int offset, Tre TypeHierarchyPrepareParams prepareParams = toTypeHierarchyPrepareParams(offset, document); executor.computeFirst((w, ls) -> ls.getTextDocumentService().prepareTypeHierarchy(prepareParams) .thenApply(result -> new Pair<>(w, result))).thenAccept(o -> o.ifPresentOrElse(p -> { - languageServerWrapper = p.getFirst(); - if (!p.getSecond().isEmpty()) { - hierarchyItems = p.getSecond(); + languageServerWrapper = p.first(); + if (!p.second().isEmpty()) { + hierarchyItems = p.second(); treeViewer = viewer; PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { if (treeViewer != null) {