From 341a929523e60c6da4401cd6c4fa690c16f1e4f7 Mon Sep 17 00:00:00 2001 From: azerr Date: Fri, 8 Dec 2023 15:27:49 +0100 Subject: [PATCH] refactor: remove javax.annotation Signed-off-by: azerr --- .../redhat/devtools/lsp4ij/LSPIJUtils.java | 9 ++++----- .../lsp4ij/LanguageServersRegistry.java | 20 +++++++++---------- .../lsp4ij/internal/SupportedFeatures.java | 11 +++++----- .../com/redhat/devtools/lsp4ij/server/OS.java | 10 ++++++++++ .../ProcessStreamConnectionProvider.java | 16 ++++++++++++++- .../server/StreamConnectionProvider.java | 19 +++++++++++++++++- 6 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LSPIJUtils.java b/src/main/java/com/redhat/devtools/lsp4ij/LSPIJUtils.java index ca816dba0..1ca713307 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LSPIJUtils.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LSPIJUtils.java @@ -41,7 +41,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -93,8 +92,8 @@ public static void openInEditor(VirtualFile file, Position position, Project pro } } - @Nonnull - public static Language getFileLanguage(@Nonnull VirtualFile file, Project project) { + @NotNull + public static Language getFileLanguage(@NotNull VirtualFile file, Project project) { return ReadAction.compute(() -> LanguageUtil.getLanguageForPsi(project, file)); } @@ -230,8 +229,8 @@ public static Position toPosition(int offset, Document document) { return new Position(line, column); } - @Nonnull - public static WorkspaceFolder toWorkspaceFolder(@Nonnull Project project) { + @NotNull + public static WorkspaceFolder toWorkspaceFolder(@NotNull Project project) { WorkspaceFolder folder = new WorkspaceFolder(); folder.setUri(toUri(project).toASCIIString()); folder.setName(project.getName()); diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java index df79a61f8..b79251868 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java @@ -17,14 +17,12 @@ import com.redhat.devtools.lsp4ij.client.LanguageClientImpl; import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider; import org.eclipse.lsp4j.jsonrpc.Launcher; -import org.eclipse.lsp4j.jsonrpc.validation.NonNull; import org.eclipse.lsp4j.services.LanguageServer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.swing.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -44,12 +42,12 @@ enum Scope { private static final int DEFAULT_LAST_DOCUMENTED_DISCONNECTED_TIMEOUT = 5; - public final @Nonnull + public final @NotNull String id; - public final @Nonnull + public final @NotNull String label; public final boolean isSingleton; - public final @Nonnull + public final @NotNull Map languageIdMappings; public final String description; public final int lastDocumentDisconnectedTimeout; @@ -57,9 +55,9 @@ enum Scope { public final boolean supportsLightEdit; - final @Nonnull Scope scope; + final @NotNull Scope scope; - public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, String description, boolean isSingleton, Integer lastDocumentDisconnectedTimeout, String scope, boolean supportsLightEdit) { + public LanguageServerDefinition(@NotNull String id, @NotNull String label, String description, boolean isSingleton, Integer lastDocumentDisconnectedTimeout, String scope, boolean supportsLightEdit) { this.id = id; this.label = label; this.description = description; @@ -90,11 +88,11 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } - public void registerAssociation(@Nonnull Language language, @Nonnull String languageId) { + public void registerAssociation(@NotNull Language language, @NotNull String languageId) { this.languageIdMappings.put(language, languageId); } - @Nonnull + @NotNull public String getDisplayName() { return label != null ? label : id; } @@ -282,7 +280,7 @@ public DocumentMatcher getDocumentMatcher() { * * @return the language server definition for the given language server id and null otherwise. */ - public @Nullable LanguageServerDefinition getServerDefinition(@NonNull String languageServerId) { + public @Nullable LanguageServerDefinition getServerDefinition(@NotNull String languageServerId) { return serverDefinitions.get(languageServerId); } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java b/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java index e30262ce6..f09f9345a 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/internal/SupportedFeatures.java @@ -12,19 +12,18 @@ *******************************************************************************/ package com.redhat.devtools.lsp4ij.internal; -import java.util.Arrays; -import java.util.List; - import org.eclipse.lsp4j.*; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.List; /** * */ public class SupportedFeatures { - public static @Nonnull TextDocumentClientCapabilities getTextDocumentClientCapabilities() { + public static @NotNull TextDocumentClientCapabilities getTextDocumentClientCapabilities() { final var textDocumentClientCapabilities = new TextDocumentClientCapabilities(); // Code Action support @@ -119,7 +118,7 @@ public class SupportedFeatures { return textDocumentClientCapabilities; } - public static @Nonnull WorkspaceClientCapabilities getWorkspaceClientCapabilities() { + public static @NotNull WorkspaceClientCapabilities getWorkspaceClientCapabilities() { final var workspaceClientCapabilities = new WorkspaceClientCapabilities(); workspaceClientCapabilities.setApplyEdit(Boolean.TRUE); // TODO diff --git a/src/main/java/com/redhat/devtools/lsp4ij/server/OS.java b/src/main/java/com/redhat/devtools/lsp4ij/server/OS.java index 220a7e9f5..9ef22aa79 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/server/OS.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/server/OS.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ package com.redhat.devtools.lsp4ij.server; import java.util.Locale; diff --git a/src/main/java/com/redhat/devtools/lsp4ij/server/ProcessStreamConnectionProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/server/ProcessStreamConnectionProvider.java index 89f862965..22f815225 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/server/ProcessStreamConnectionProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/server/ProcessStreamConnectionProvider.java @@ -1,6 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ package com.redhat.devtools.lsp4ij.server; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -8,6 +19,9 @@ import java.util.List; import java.util.Objects; +/** + * Process stream connection provider used to start a language server with a process. + */ public abstract class ProcessStreamConnectionProvider implements StreamConnectionProvider { private @Nullable Process process; diff --git a/src/main/java/com/redhat/devtools/lsp4ij/server/StreamConnectionProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/server/StreamConnectionProvider.java index 011256732..3d4b38ef0 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/server/StreamConnectionProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/server/StreamConnectionProvider.java @@ -1,13 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at https://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ package com.redhat.devtools.lsp4ij.server; import org.eclipse.lsp4j.jsonrpc.messages.Message; import org.eclipse.lsp4j.services.LanguageServer; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +/** + * Stream connection provider API used to: + *
    + *
  • start a language server.
  • + *
  • get the stream of LSP requests, responses and notifications.
  • + *
+ */ public interface StreamConnectionProvider { void start() throws CannotStartProcessException;