diff --git a/build.gradle b/build.gradle index e8c9e050..412ce914 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ @@ -32,15 +32,16 @@ apply from: "${rootDir}/gradle/versions.gradle" subprojects { repositories.mavenCentral() - + group = 'org.eclipse.lsp4j' version = rootProject.version - + + apply plugin: 'eclipse' apply plugin: 'java-library' apply plugin: 'org.xtext.xtend' apply plugin: 'eclipse' apply plugin: 'maven-publish' - + apply from: "${rootDir}/gradle/java-compiler-settings.gradle" apply from: "${rootDir}/gradle/xtend-compiler-settings.gradle" apply from: "${rootDir}/gradle/maven-deployment.gradle" @@ -54,6 +55,123 @@ subprojects { } } } + + eclipse { + jdt.file.withProperties { properties -> + properties['org.eclipse.jdt.core.compiler.release']='enabled' + properties['org.eclipse.jdt.core.compiler.doc.comment.support']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.APILeak']='warning' + properties['org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated']='info' + properties['org.eclipse.jdt.core.compiler.problem.annotationSuperInterface']='warning' + properties['org.eclipse.jdt.core.compiler.problem.assertIdentifier']='error' + properties['org.eclipse.jdt.core.compiler.problem.autoboxing']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.comparingIdentical']='warning' + properties['org.eclipse.jdt.core.compiler.problem.deadCode']='warning' + properties['org.eclipse.jdt.core.compiler.problem.deprecation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.discouragedReference']='warning' + properties['org.eclipse.jdt.core.compiler.problem.emptyStatement']='warning' + properties['org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.enumIdentifier']='error' + properties['org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable']='warning' + properties['org.eclipse.jdt.core.compiler.problem.fallthroughCase']='warning' + properties['org.eclipse.jdt.core.compiler.problem.fatalOptionalError']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.fieldHiding']='warning' + properties['org.eclipse.jdt.core.compiler.problem.finalParameterBound']='warning' + properties['org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally']='warning' + properties['org.eclipse.jdt.core.compiler.problem.forbiddenReference']='error' + properties['org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock']='warning' + properties['org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod']='warning' + properties['org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch']='warning' + properties['org.eclipse.jdt.core.compiler.problem.indirectStaticAccess']='warning' + properties['org.eclipse.jdt.core.compiler.problem.invalidJavadoc']='warning' + properties['org.eclipse.jdt.core.compiler.problem.invalidJavadocTags']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility']='protected' + properties['org.eclipse.jdt.core.compiler.problem.localVariableHiding']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.methodWithConstructorName']='warning' + properties['org.eclipse.jdt.core.compiler.problem.missingDefaultCase']='info' + properties['org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod']='warning' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocComments']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility']='public' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription']='return_tag' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocTags']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility']='public' + properties['org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.missingSerialVersion']='warning' + properties['org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod']='warning' + properties['org.eclipse.jdt.core.compiler.problem.noEffectAssignment']='warning' + properties['org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion']='warning' + properties['org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped']='warning' + properties['org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict']='error' + properties['org.eclipse.jdt.core.compiler.problem.nullReference']='warning' + properties['org.eclipse.jdt.core.compiler.problem.nullSpecViolation']='error' + properties['org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion']='warning' + properties['org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod']='warning' + properties['org.eclipse.jdt.core.compiler.problem.parameterAssignment']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables']='warning' + properties['org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment']='warning' + properties['org.eclipse.jdt.core.compiler.problem.potentialNullReference']='warning' + properties['org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable']='warning' + properties['org.eclipse.jdt.core.compiler.problem.rawTypeReference']='warning' + properties['org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.redundantNullCheck']='warning' + properties['org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments']='warning' + properties['org.eclipse.jdt.core.compiler.problem.redundantSuperinterface']='warning' + properties['org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures']='warning' + properties['org.eclipse.jdt.core.compiler.problem.specialParameterHidingField']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.staticAccessReceiver']='warning' + properties['org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.suppressWarnings']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed']='info' + properties['org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.terminalDeprecation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.typeParameterHiding']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unclosedCloseable']='warning' + properties['org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.unhandledWarningToken']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType']='info' + properties['org.eclipse.jdt.core.compiler.problem.unnecessaryElse']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.unusedImport']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedLabel']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedLocal']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedParameter']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference']='enabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete']='disabled' + properties['org.eclipse.jdt.core.compiler.problem.unusedPrivateMember']='warning' + properties['org.eclipse.jdt.core.compiler.problem.unusedTypeParameter']='ignore' + properties['org.eclipse.jdt.core.compiler.problem.unusedWarningToken']='warning' + properties['org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast']='warning' + } + } } task clean(type: Delete) { diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java index b094ff74..ec931d63 100644 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java @@ -1,18 +1,16 @@ /****************************************************************************** * Copyright (c) 2022 itemis AG and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.debug.adapters; -import java.util.function.Predicate; - import org.eclipse.lsp4j.debug.AttachRequestArguments; import org.eclipse.lsp4j.debug.LaunchRequestArguments; import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter; @@ -20,23 +18,21 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; public class RestartArgumentsArgumentsTypeAdapter implements TypeAdapterFactory { - private static final TypeToken> ELEMENT_TYPE = new TypeToken>() { + private static final TypeToken> ELEMENT_TYPE = new TypeToken<>() { }; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("noDebug"); - Predicate rightChecker = leftChecker.negate(); - TypeAdapter> elementTypeAdapter = new EitherTypeAdapter<>( - gson, ELEMENT_TYPE, leftChecker, rightChecker); + final var leftChecker = new PropertyChecker("noDebug"); + final var rightChecker = leftChecker.negate(); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); return (TypeAdapter) elementTypeAdapter; } diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolClient.java b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolClient.java index 5cf3eb4b..7dd67af2 100644 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolClient.java +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolClient.java @@ -47,7 +47,7 @@ public interface IDebugProtocolClient { /** * Version of Debug Protocol */ - public static final String SCHEMA_VERSION = "1.60.0"; + String SCHEMA_VERSION = "1.60.0"; /** * This event indicates that the debug adapter is ready to accept configuration diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolServer.java b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolServer.java index 06c53940..8ea1fe03 100644 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolServer.java +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/services/IDebugProtocolServer.java @@ -91,7 +91,7 @@ public interface IDebugProtocolServer { /** * Version of Debug Protocol */ - public static final String SCHEMA_VERSION = "1.60.0"; + String SCHEMA_VERSION = "1.60.0"; /** * The 'cancel' request is used by the client in two situations: diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/DebugLauncher.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/DebugLauncher.java index ce1862fd..14c1607e 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/DebugLauncher.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/DebugLauncher.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.debug; @@ -38,7 +38,7 @@ * and an output stream. */ public final class DebugLauncher { - + private DebugLauncher() {} /** @@ -191,22 +191,21 @@ public static Launcher createIoLauncher(Object localService, Class rem .configureGson(configureGson) .create(); } - + /** * Launcher builder for the debug protocol. Adapts the JSON-RPC message classes to the JSON format used * by the debug protocol. */ public static class Builder extends Launcher.Builder { - + @Override protected MessageJsonHandler createJsonHandler() { Map supportedMethods = getSupportedMethods(); if (configureGson != null) return new DebugMessageJsonHandler(supportedMethods, configureGson); - else - return new DebugMessageJsonHandler(supportedMethods); + return new DebugMessageJsonHandler(supportedMethods); } - + @Override protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler); @@ -221,6 +220,6 @@ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { remoteEndpoint.setJsonHandler(jsonHandler); return remoteEndpoint; } - + } } diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugEnumTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugEnumTypeAdapter.java index 21977c07..2a4fae50 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugEnumTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugEnumTypeAdapter.java @@ -41,8 +41,8 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { } - private final Map serializedFormToEnum = new HashMap(); - private final Map enumToSerializedForm = new HashMap(); + private final Map serializedFormToEnum = new HashMap<>(); + private final Map enumToSerializedForm = new HashMap<>(); public DebugEnumTypeAdapter(Class clazz) { try { @@ -73,7 +73,7 @@ private String getSerializedForm(String name) { m.appendReplacement(sb, m.group().toUpperCase()); } m.appendTail(sb); - return sb.toString().replaceAll("_", ""); + return sb.toString().replace("_", ""); } @Override diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugMessageTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugMessageTypeAdapter.java index a25493cb..4e8ba776 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugMessageTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/adapters/DebugMessageTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2017 Kichwa Coders Ltd. and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.debug.adapters; @@ -261,9 +261,8 @@ public Message read(JsonReader in) throws IOException { Message resultMessage = createMessage(messageType, seq, request_seq, method, success, message, rawParams, rawBody); MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(resultMessage, issue); - } else { - throw exception; } + throw exception; } } @@ -329,7 +328,7 @@ protected Object parseBody(Object rawBody, String messageType, int request_seq, if (!(rawBody instanceof JsonElement)) { return rawBody; } - JsonElement rawJsonParams = (JsonElement) rawBody; + final var rawJsonParams = (JsonElement) rawBody; return fromJson(rawJsonParams, Object.class); } return rawBody; @@ -388,7 +387,7 @@ private Message createMessage(String messageType, int seq, int request_seq, Stri Type returnType = jsonRpcMethod.getReturnType(); if (jsonRpcMethod.getReturnTypeAdapterFactory() != null) typeAdapter = jsonRpcMethod.getReturnTypeAdapterFactory().create(gson, TypeToken.get(returnType)); - JsonElement jsonElement = (JsonElement) body; + final var jsonElement = (JsonElement) body; if (typeAdapter != null) body = typeAdapter.fromJsonTree(jsonElement); else @@ -410,7 +409,7 @@ private Message createMessage(String messageType, int seq, int request_seq, Stri public void write(JsonWriter out, Message message) throws IOException { out.beginObject(); if (message instanceof DebugRequestMessage) { - DebugRequestMessage requestMessage = (DebugRequestMessage) message; + final var requestMessage = (DebugRequestMessage) message; out.name("type"); out.value("request"); out.name("seq"); @@ -419,11 +418,11 @@ public void write(JsonWriter out, Message message) throws IOException { out.value(requestMessage.getMethod()); Object params = requestMessage.getParams(); if (params != null) { - out.name("arguments"); + out.name("arguments"); gson.toJson(params, params.getClass(), out); } } else if (message instanceof DebugResponseMessage) { - DebugResponseMessage responseMessage = (DebugResponseMessage) message; + final var responseMessage = (DebugResponseMessage) message; out.name("type"); out.value("response"); out.name("seq"); @@ -458,7 +457,7 @@ public void write(JsonWriter out, Message message) throws IOException { } } } else if (message instanceof DebugNotificationMessage) { - DebugNotificationMessage notificationMessage = (DebugNotificationMessage) message; + final var notificationMessage = (DebugNotificationMessage) message; out.name("type"); out.value("event"); out.name("seq"); diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/json/DebugMessageJsonHandler.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/json/DebugMessageJsonHandler.java index 1e725578..adcb1f41 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/json/DebugMessageJsonHandler.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/json/DebugMessageJsonHandler.java @@ -30,6 +30,7 @@ public DebugMessageJsonHandler(Map supportedMethods, Cons super(supportedMethods, configureGson); } + @Override public GsonBuilder getDefaultGsonBuilder() { return super.getDefaultGsonBuilder().registerTypeAdapterFactory(new DebugMessageTypeAdapter.Factory(this)) .registerTypeAdapterFactory(new DebugEnumTypeAdapter.Factory()); diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugNotificationMessage.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugNotificationMessage.java index 738a789f..f5b2b4e6 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugNotificationMessage.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugNotificationMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2017 Kichwa Coders Ltd. and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.debug.messages; @@ -38,7 +38,7 @@ public String getId() { return id.getRight().toString(); return null; } - + @NonNull public Either getRawId() { return id; @@ -47,11 +47,11 @@ public Either getRawId() { public void setId(String id) { this.id = Either.forLeft(id); } - + public void setId(int id) { this.id = Either.forRight(id); } - + public void setRawId(@NonNull Either id) { this.id = id; } @@ -66,7 +66,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - DebugNotificationMessage other = (DebugNotificationMessage) obj; + final var other = (DebugNotificationMessage) obj; if (this.id == null) { if (other.id != null) return false; @@ -79,7 +79,7 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + (this.id == null ? 0 : this.id.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugResponseMessage.java b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugResponseMessage.java index 26fe32b5..a21c294f 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugResponseMessage.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/main/java/org/eclipse/lsp4j/jsonrpc/debug/messages/DebugResponseMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2017 Kichwa Coders Ltd. and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.debug.messages; @@ -40,7 +40,7 @@ public String getResponseId() { return responseId.getRight().toString(); return null; } - + @NonNull public Either getRawResponseId() { return responseId; @@ -49,11 +49,11 @@ public Either getRawResponseId() { public void setResponseId(String id) { this.responseId = Either.forLeft(id); } - + public void setResponseId(int id) { this.responseId = Either.forRight(id); } - + public void setRawResponseId(@NonNull Either id) { this.responseId = id; } @@ -83,7 +83,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - DebugResponseMessage other = (DebugResponseMessage) obj; + final var other = (DebugResponseMessage) obj; if (this.responseId == null) { if (other.responseId != null) return false; @@ -101,8 +101,8 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.responseId == null) ? 0 : this.responseId.hashCode()); - result = prime * result + ((this.method == null) ? 0 : this.method.hashCode()); + result = prime * result + (this.responseId == null ? 0 : this.responseId.hashCode()); + result = prime * result + (this.method == null ? 0 : this.method.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugIntegrationTest.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugIntegrationTest.java index 4d4fd190..06068125 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugIntegrationTest.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugIntegrationTest.java @@ -51,18 +51,18 @@ public MyParam(String string) { String value; } - public static interface MyServer { + public interface MyServer { @JsonRequest CompletableFuture askServer(MyParam param); } - public static interface MyVoidServer { + public interface MyVoidServer { @JsonRequest CompletableFuture askServer(MyParam param); } - public static interface MyClient { + public interface MyClient { @JsonRequest CompletableFuture askClient(MyParam param); } @@ -438,7 +438,7 @@ public CompletableFuture askServer(MyParam param) { out.toString()); } - public static interface UnexpectedParamsTestServer { + public interface UnexpectedParamsTestServer { @JsonNotification void myNotification(); } @@ -461,6 +461,7 @@ public void testUnexpectedParams() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); UnexpectedParamsTestServer server = new UnexpectedParamsTestServer() { + @Override public void myNotification() { } }; @@ -474,16 +475,16 @@ public void myNotification() { } } - protected String getHeader(int contentLength) { - StringBuilder headerBuilder = new StringBuilder(); - headerBuilder.append(CONTENT_LENGTH_HEADER).append(": ").append(contentLength).append(CRLF); - headerBuilder.append(CRLF); - return headerBuilder.toString(); - } + protected String getHeader(int contentLength) { + StringBuilder headerBuilder = new StringBuilder(); + headerBuilder.append(CONTENT_LENGTH_HEADER).append(": ").append(contentLength).append(CRLF); + headerBuilder.append(CRLF); + return headerBuilder.toString(); + } - /** - * Test a fully connected design with the {@link ReflectiveMessageValidator} enabled. - */ + /** + * Test a fully connected design with the {@link ReflectiveMessageValidator} enabled. + */ @Test public void testValidatedRequests() throws Exception { // create client side diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugLauncherTest.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugLauncherTest.java index 73aa13e3..fa60153a 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugLauncherTest.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugLauncherTest.java @@ -42,8 +42,8 @@ static class Param { public String message; } - static interface A { - @JsonNotification public void say(Param p); + interface A { + @JsonNotification void say(Param p); } @Test public void testDone() throws Exception { @@ -89,7 +89,7 @@ public void say(Param p) { } }; ByteArrayOutputStream out = new ByteArrayOutputStream(); - TypeAdapter typeAdapter = new TypeAdapter() { + TypeAdapter typeAdapter = new TypeAdapter<>() { @Override public void write(JsonWriter out, Param value) throws IOException { out.beginObject(); diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugRemoteEndpointTest.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugRemoteEndpointTest.java index d0b7a9db..312261fe 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugRemoteEndpointTest.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/DebugRemoteEndpointTest.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2017 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.debug.test; @@ -41,6 +41,7 @@ static class TestEndpoint implements Endpoint { List notifications = new ArrayList<>(); Map> requests = new LinkedHashMap<>(); + @Override public void notify(String method, Object parameter) { notifications.add(new NotificationMessage() {{ setMethod(method); @@ -50,7 +51,7 @@ public void notify(String method, Object parameter) { @Override public CompletableFuture request(String method, Object parameter) { - CompletableFuture completableFuture = new CompletableFuture(); + final var completableFuture = new CompletableFuture<>(); requests.put(new RequestMessage() {{ setMethod(method); setParams(parameter); diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/DebugMessageJsonHandlerTest.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/DebugMessageJsonHandlerTest.java index a3b75650..3ea38f75 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/DebugMessageJsonHandlerTest.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/DebugMessageJsonHandlerTest.java @@ -37,7 +37,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; import com.google.gson.reflect.TypeToken; public class DebugMessageJsonHandlerTest { @@ -60,7 +59,7 @@ public void testParseList() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" @@ -87,7 +86,7 @@ public void testParseList_02() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" @@ -114,7 +113,7 @@ public void testEither_01() { new TypeToken>>>() {}.getType(), new TypeToken>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" @@ -145,9 +144,9 @@ public void testEither_02() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"response\",\n" @@ -165,9 +164,9 @@ public void testEither_03() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>, List>>>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" @@ -227,9 +226,9 @@ public void testEither_04() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" @@ -260,9 +259,9 @@ public void testEither_05() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken, MyClassList>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{" + "\"seq\":2,\n" @@ -295,7 +294,7 @@ public void testParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"request\",\n" @@ -314,7 +313,7 @@ public void testParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -332,7 +331,7 @@ public void testParamsParsing_03() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -350,7 +349,7 @@ public void testParamsParsing_04() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -369,7 +368,7 @@ public void testRawMultiParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -393,7 +392,7 @@ public void testRawMultiParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -413,7 +412,7 @@ public void testRawMultiParamsParsing_03() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -439,7 +438,7 @@ public void testRawMultiParamsParsing_04() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -464,7 +463,7 @@ public void testMultiParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -488,7 +487,7 @@ public void testMultiParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -508,7 +507,7 @@ public void testMultiParamsParsing_03() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -534,7 +533,7 @@ public void testMultiParamsParsing_04() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" @@ -558,7 +557,7 @@ public void testEnumParam() { new TypeToken() {}.getType(), new TypeToken>() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{" + "\"seq\":2,\n" + "\"type\":\"request\",\n" @@ -644,7 +643,7 @@ public void testRequest_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"request\"", @@ -668,7 +667,7 @@ public void testNormalResponse_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", @@ -694,7 +693,7 @@ public void testNormalResponseExtraFields_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", @@ -721,7 +720,7 @@ public void testErrorResponse_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", @@ -749,7 +748,7 @@ public void testNotification_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"event\"", @@ -773,7 +772,7 @@ public void testMissingSuccessResponse_AllOrders() { new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"seq\":2", "\"type\":\"response\"", @@ -799,7 +798,7 @@ public void testParseErrorRequest() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String input = "{" + "\"seq\":2,\n" + "\"type\":\"request\",\n" @@ -828,7 +827,7 @@ public void testParseSyntaxErrorRequest() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String input = "{" + "\"seq\":2,\n" + "\"type\":\"request\",\n" @@ -856,7 +855,7 @@ private void voidResponse(String body) { }.getType(), new TypeToken() { }.getType())); DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String bodyField = ""; if (body != null) { diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClass.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClass.java index 73b85c00..d3ff7e58 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClass.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClass.java @@ -23,17 +23,20 @@ public void setValue(String value) { this.value = value; } + @Override public String toString() { return "MyClass [value=" + value + "]"; } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + (value == null ? 0 : value.hashCode()); return result; } + @Override public boolean equals(Object obj) { if (this == obj) return true; diff --git a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClassList.java b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClassList.java index 664b84fc..fbbeb4cd 100644 --- a/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClassList.java +++ b/org.eclipse.lsp4j.jsonrpc.debug/src/test/java/org/eclipse/lsp4j/jsonrpc/debug/test/json/MyClassList.java @@ -26,13 +26,15 @@ public void setItems(List items) { this.items = items; } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((items == null) ? 0 : items.hashCode()); + result = prime * result + (items == null ? 0 : items.hashCode()); return result; } + @Override public boolean equals(Object obj) { if (this == obj) return true; @@ -49,6 +51,7 @@ public boolean equals(Object obj) { return true; } + @Override public String toString() { return "MyClassList [items=" + items + "]"; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/CompletableFutures.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/CompletableFutures.java index 44682f9d..46a10dc8 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/CompletableFutures.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/CompletableFutures.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc; @@ -18,52 +18,52 @@ public final class CompletableFutures { private CompletableFutures() {} - + /** * A utility method to create a {@link CompletableFuture} with cancellation support. - * + * * @param code a function that accepts a {@link CancelChecker} and returns the to be computed value * @return a future */ public static CompletableFuture computeAsync(Function code) { - CompletableFuture start = new CompletableFuture<>(); + final var start = new CompletableFuture(); CompletableFuture result = start.thenApplyAsync(code); start.complete(new FutureCancelChecker(result)); return result; } - + /** * A utility method to create a {@link CompletableFuture} with cancellation support. - * + * * @param code a function that accepts a {@link CancelChecker} and returns the to be computed value * @return a future */ public static CompletableFuture computeAsync(Executor executor, Function code) { - CompletableFuture start = new CompletableFuture<>(); + final var start = new CompletableFuture(); CompletableFuture result = start.thenApplyAsync(code, executor); start.complete(new FutureCancelChecker(result)); return result; } - + public static class FutureCancelChecker implements CancelChecker { - + private final CompletableFuture future; - + public FutureCancelChecker(CompletableFuture future) { this.future = future; } @Override public void checkCanceled() { - if (future.isCancelled()) + if (future.isCancelled()) throw new CancellationException(); } - + @Override public boolean isCanceled() { return future.isCancelled(); } - + } - + } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Launcher.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Launcher.java index 600c1a4d..14f7a078 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Launcher.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/Launcher.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc; @@ -39,14 +39,14 @@ /** * This is the entry point for applications that use LSP4J. A Launcher does all the wiring that is necessary to connect * your endpoint via an input stream and an output stream. - * + * * @param remote service interface type */ public interface Launcher { - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -60,11 +60,11 @@ static Launcher createLauncher(Object localService, Class remoteInterf .setOutput(out) .create(); } - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream, * and set up message validation and tracing. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -83,12 +83,12 @@ static Launcher createLauncher(Object localService, Class remoteInterf .traceMessages(trace) .create(); } - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -100,12 +100,12 @@ static Launcher createLauncher(Object localService, Class remoteInterf ExecutorService executorService, Function wrapper) { return createIoLauncher(localService, remoteInterface, in, out, executorService, wrapper); } - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -124,14 +124,14 @@ static Launcher createIoLauncher(Object localService, Class remoteInte .wrapMessages(wrapper) .create(); } - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. * The {@code configureGson} function can be used to register additional type adapters in the {@link GsonBuilder} * in order to support protocol classes that cannot be handled by Gson's reflective capabilities. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -152,14 +152,14 @@ static Launcher createIoLauncher(Object localService, Class remoteInte .configureGson(configureGson) .create(); } - + /** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. * The {@code configureGson} function can be used to register additional type adapters in the {@link GsonBuilder} * in order to support protocol classes that cannot be handled by Gson's reflective capabilities. - * + * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages @@ -182,7 +182,7 @@ static Launcher createIoLauncher(Object localService, Class remoteInte .configureGson(configureGson) .create(); } - + /** * Create a new Launcher for a collection of local service objects, a collection of remote interfaces and an * input and output stream. Threads are started with the given executor service. The wrapper function is applied @@ -190,7 +190,7 @@ static Launcher createIoLauncher(Object localService, Class remoteInte * can be included. The {@code configureGson} function can be used to register additional type adapters in * the {@link GsonBuilder} in order to support protocol classes that cannot be handled by Gson's reflective * capabilities. - * + * * @param localServices - the objects that receive method calls from the remote services * @param remoteInterfaces - interfaces on which RPC methods are looked up * @param classLoader - a class loader that is able to resolve all given interfaces @@ -203,7 +203,7 @@ static Launcher createIoLauncher(Object localService, Class remoteInte static Launcher createIoLauncher(Collection localServices, Collection> remoteInterfaces, ClassLoader classLoader, InputStream in, OutputStream out, ExecutorService executorService, Function wrapper, Consumer configureGson) { - return new Builder() + return new Builder<>() .setLocalServices(localServices) .setRemoteInterfaces(remoteInterfaces) .setClassLoader(classLoader) @@ -214,17 +214,17 @@ static Launcher createIoLauncher(Collection localServices, Colle .configureGson(configureGson) .create(); } - - + + //------------------------------ Builder Class ------------------------------// - + /** * The launcher builder wires up all components for JSON-RPC communication. - * + * * @param remote service interface type */ public static class Builder { - + protected Collection localServices; protected Collection> remoteInterfaces; protected InputStream input; @@ -236,7 +236,7 @@ public static class Builder { protected Consumer configureGson; protected ClassLoader classLoader; protected MessageTracer messageTracer; - + public Builder setLocalService(Object localService) { this.localServices = Collections.singletonList(localService); return this; @@ -251,7 +251,7 @@ public Builder setRemoteInterface(Class remoteInterface) { this.remoteInterfaces = Collections.singletonList(remoteInterface); return this; } - + public Builder setRemoteInterfaces(Collection> remoteInterfaces) { this.remoteInterfaces = remoteInterfaces; return this; @@ -281,17 +281,17 @@ public Builder wrapMessages(Function wrappe this.messageWrapper = wrapper; return this; } - + public Builder setExceptionHandler(Function exceptionHandler) { this.exceptionHandler = exceptionHandler; return this; } - + public Builder validateMessages(boolean validate) { this.validateMessages = validate; return this; } - + public Builder traceMessages(PrintWriter tracer) { if (tracer != null) { this.messageTracer = new MessageTracer(tracer); @@ -314,7 +314,7 @@ public Launcher create() { throw new IllegalStateException("Local service must be configured."); if (remoteInterfaces == null) throw new IllegalStateException("Remote interface must be configured."); - + // Create the JSON handler, remote endpoint and remote proxy MessageJsonHandler jsonHandler = createJsonHandler(); if (messageTracer != null) { @@ -322,15 +322,15 @@ public Launcher create() { } RemoteEndpoint remoteEndpoint = createRemoteEndpoint(jsonHandler); T remoteProxy = createProxy(remoteEndpoint); - + // Create the message processor - StreamMessageProducer reader = new StreamMessageProducer(input, jsonHandler, remoteEndpoint); + final var reader = new StreamMessageProducer(input, jsonHandler, remoteEndpoint); MessageConsumer messageConsumer = wrapMessageConsumer(remoteEndpoint); ConcurrentMessageProcessor msgProcessor = createMessageProcessor(reader, messageConsumer, remoteProxy); ExecutorService execService = executorService != null ? executorService : Executors.newCachedThreadPool(); return createLauncher(execService, remoteProxy, remoteEndpoint, msgProcessor); } - + /** * Create the JSON handler for messages between the local and remote services. */ @@ -338,10 +338,9 @@ protected MessageJsonHandler createJsonHandler() { Map supportedMethods = getSupportedMethods(); if (configureGson != null) return new MessageJsonHandler(supportedMethods, configureGson); - else - return new MessageJsonHandler(supportedMethods); + return new MessageJsonHandler(supportedMethods); } - + /** * Create the remote endpoint that communicates with the local services. */ @@ -358,7 +357,7 @@ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { remoteEndpoint.setJsonHandler(jsonHandler); return remoteEndpoint; } - + /** * Create the proxy for calling methods on the remote service. */ @@ -366,24 +365,23 @@ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { protected T createProxy(RemoteEndpoint remoteEndpoint) { if (localServices.size() == 1 && remoteInterfaces.size() == 1) { return ServiceEndpoints.toServiceObject(remoteEndpoint, remoteInterfaces.iterator().next()); - } else { - return (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection>) (Object) remoteInterfaces, classLoader); } + return (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection>) (Object) remoteInterfaces, classLoader); } - + /** - * Create the message processor that listens to the input stream. + * Create the message processor that listens to the input stream. */ - protected ConcurrentMessageProcessor createMessageProcessor(MessageProducer reader, + protected ConcurrentMessageProcessor createMessageProcessor(MessageProducer reader, MessageConsumer messageConsumer, T remoteProxy) { return new ConcurrentMessageProcessor(reader, messageConsumer); } - + protected Launcher createLauncher(ExecutorService execService, T remoteProxy, RemoteEndpoint remoteEndpoint, ConcurrentMessageProcessor msgProcessor) { - return new StandardLauncher(execService, remoteProxy, remoteEndpoint, msgProcessor); + return new StandardLauncher<>(execService, remoteProxy, remoteEndpoint, msgProcessor); } - + protected MessageConsumer wrapMessageConsumer(MessageConsumer consumer) { MessageConsumer result = consumer; if (messageTracer != null) { @@ -397,17 +395,17 @@ protected MessageConsumer wrapMessageConsumer(MessageConsumer consumer) { } return result; } - + /** * Gather all JSON-RPC methods from the local and remote services. */ protected Map getSupportedMethods() { - Map supportedMethods = new LinkedHashMap<>(); + final var supportedMethods = new LinkedHashMap(); // Gather the supported methods of remote interfaces for (Class interface_ : remoteInterfaces) { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(interface_)); } - + // Gather the supported methods of local services for (Object localService : localServices) { if (localService instanceof JsonRpcMethodProvider) { @@ -417,30 +415,30 @@ protected Map getSupportedMethods() { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass())); } } - + return supportedMethods; } } - - + + //---------------------------- Interface Methods ----------------------------// - + /** * Start a thread that listens to the input stream. The thread terminates when the stream is closed. - * + * * @return a future that returns {@code null} when the listener thread is terminated */ Future startListening(); - + /** * Returns the proxy instance that implements the remote service interfaces. */ T getRemoteProxy(); - + /** * Returns the remote endpoint. Use this one to send generic {@code request} or {@code notify} methods * to the remote services. */ RemoteEndpoint getRemoteEndpoint(); - + } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageIssueException.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageIssueException.java index 58dec38a..0b18b147 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageIssueException.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageIssueException.java @@ -50,7 +50,7 @@ public MessageIssueException(Message rpcMessage, Stream issueStrea @Override public String getMessage() { - return issues.stream().map(issue -> issue.getText()).collect(Collectors.joining("\n")); + return issues.stream().map(MessageIssue::getText).collect(Collectors.joining("\n")); } public Message getRpcMessage() { diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageTracer.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageTracer.java index 948323f6..373acaf7 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageTracer.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/MessageTracer.java @@ -41,7 +41,7 @@ public void setJsonHandler(MessageJsonHandler jsonHandler) { @Override public MessageConsumer apply(MessageConsumer messageConsumer) { - TracingMessageConsumer tracingMessageConsumer = new TracingMessageConsumer( + final var tracingMessageConsumer = new TracingMessageConsumer( messageConsumer, sentRequests, receivedRequests, printWriter, Clock.systemDefaultZone()); tracingMessageConsumer.setJsonHandler(jsonHandler); return tracingMessageConsumer; diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java index 8f8b4234..4ee8bd09 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/RemoteEndpoint.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc; @@ -46,8 +46,8 @@ public class RemoteEndpoint implements Endpoint, MessageConsumer, MessageIssueHandler, MethodProvider { private static final Logger LOG = Logger.getLogger(RemoteEndpoint.class.getName()); - - public static final Function DEFAULT_EXCEPTION_HANDLER = (throwable) -> { + + public static final Function DEFAULT_EXCEPTION_HANDLER = throwable -> { if (throwable instanceof ResponseErrorException) { return ((ResponseErrorException) throwable).getResponseError(); } else if ((throwable instanceof CompletionException || throwable instanceof InvocationTargetException) @@ -60,11 +60,11 @@ public class RemoteEndpoint implements Endpoint, MessageConsumer, MessageIssueHa private static ResponseError fallbackResponseError(String header, Throwable throwable) { LOG.log(Level.SEVERE, header + ": " + throwable.getMessage(), throwable); - ResponseError error = new ResponseError(); + final var error = new ResponseError(); error.setMessage(header + "."); error.setCode(ResponseErrorCode.InternalError); - ByteArrayOutputStream stackTrace = new ByteArrayOutputStream(); - PrintWriter stackTraceWriter = new PrintWriter(stackTrace); + final var stackTrace = new ByteArrayOutputStream(); + final var stackTraceWriter = new PrintWriter(stackTrace); throwable.printStackTrace(stackTraceWriter); stackTraceWriter.flush(); error.setData(stackTrace.toString()); @@ -75,11 +75,11 @@ private static ResponseError fallbackResponseError(String header, Throwable thro private final Endpoint localEndpoint; private final Function exceptionHandler; private MessageJsonHandler jsonHandler; - + private final AtomicInteger nextRequestId = new AtomicInteger(); private final Map sentRequestMap = new LinkedHashMap<>(); private final Map> receivedRequestMap = new LinkedHashMap<>(); - + /** * Information about requests that have been sent and for which no response has been received yet. */ @@ -91,7 +91,7 @@ private static class PendingRequestInfo { RequestMessage requestMessage; CompletableFuture future; } - + /** * @param out - a consumer that transmits messages to the remote service * @param localEndpoint - the local service implementation @@ -108,7 +108,7 @@ public RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint, Function request(String method, Object parameter) { final RequestMessage requestMessage = createRequestMessage(method, parameter); - final CompletableFuture result = new CompletableFuture() { + final var result = new CompletableFuture<>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { sendCancelNotification(requestMessage.getRawId()); @@ -165,7 +165,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { // Store request information so it can be handled when the response is received sentRequestMap.put(requestMessage.getId(), new PendingRequestInfo(requestMessage, result)); } - + try { // Send the request to the remote service out.consume(requestMessage); @@ -177,7 +177,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { } protected RequestMessage createRequestMessage(String method, Object parameter) { - RequestMessage requestMessage = new RequestMessage(); + final var requestMessage = new RequestMessage(); requestMessage.setJsonHandler(getJsonHandler()); requestMessage.setId(String.valueOf(nextRequestId.incrementAndGet())); requestMessage.setMethod(method); @@ -194,13 +194,13 @@ protected void sendCancelNotification(Either id) { @Override public void consume(Message message) { if (message instanceof NotificationMessage) { - NotificationMessage notificationMessage = (NotificationMessage) message; + final var notificationMessage = (NotificationMessage) message; handleNotification(notificationMessage); } else if (message instanceof RequestMessage) { - RequestMessage requestMessage = (RequestMessage) message; + final var requestMessage = (RequestMessage) message; handleRequest(requestMessage); } else if (message instanceof ResponseMessage) { - ResponseMessage responseMessage = (ResponseMessage) message; + final var responseMessage = (ResponseMessage) message; handleResponse(responseMessage); } else { LOG.log(Level.WARNING, "Unkown message type.", message); @@ -234,12 +234,12 @@ protected void handleNotification(NotificationMessage notificationMessage) { } } } - + /** * Cancellation is handled inside this class and not forwarded to the local endpoint. - * + * * @return {@code true} if the given message is a cancellation notification, - * {@code false} if it can be handled by the local endpoint + * {@code false} if it can be handled by the local endpoint */ protected boolean handleCancellation(NotificationMessage notificationMessage) { if (MessageJsonHandler.CANCEL_METHOD.getMethodName().equals(notificationMessage.getMethod())) { @@ -255,16 +255,15 @@ protected boolean handleCancellation(NotificationMessage notificationMessage) { LOG.warning("Unmatched cancel notification for request id " + id); } return true; - } else { - LOG.warning("Cancellation support is disabled, since the '" + MessageJsonHandler.CANCEL_METHOD.getMethodName() + "' method has been registered explicitly."); } + LOG.warning("Cancellation support is disabled, since the '" + MessageJsonHandler.CANCEL_METHOD.getMethodName() + "' method has been registered explicitly."); } else { LOG.warning("Missing 'params' attribute of cancel notification."); } } return false; } - + protected void handleRequest(RequestMessage requestMessage) { CompletableFuture future; try { @@ -279,23 +278,22 @@ protected void handleRequest(RequestMessage requestMessage) { out.consume(createErrorResponseMessage(requestMessage, errorObject)); if (throwable instanceof Error) throw (Error) throwable; - else - return; + return; } - + final String messageId = requestMessage.getId(); synchronized (receivedRequestMap) { receivedRequestMap.put(messageId, future); } - future.thenAccept((result) -> { - // Reply with the result object that was computed by the local endpoint + future.thenAccept(result -> { + // Reply with the result object that was computed by the local endpoint out.consume(createResultResponseMessage(requestMessage, result)); }).exceptionally((Throwable t) -> { // The local endpoint has failed computing a result - reply with an error response ResponseMessage responseMessage; if (isCancellation(t)) { String message = "The request (id: " + messageId + ", method: '" + requestMessage.getMethod() + "') has been cancelled"; - ResponseError errorObject = new ResponseError(ResponseErrorCode.RequestCancelled, message, null); + final var errorObject = new ResponseError(ResponseErrorCode.RequestCancelled, message, null); responseMessage = createErrorResponseMessage(requestMessage, errorObject); } else { ResponseError errorObject = exceptionHandler.apply(t); @@ -306,7 +304,7 @@ protected void handleRequest(RequestMessage requestMessage) { } out.consume(responseMessage); return null; - }).thenApply((obj) -> { + }).thenApply(obj -> { synchronized (receivedRequestMap) { receivedRequestMap.remove(messageId); } @@ -319,27 +317,27 @@ public void handle(Message message, List issues) { if (issues.isEmpty()) { throw new IllegalArgumentException("The list of issues must not be empty."); } - + if (message instanceof RequestMessage) { - RequestMessage requestMessage = (RequestMessage) message; + final var requestMessage = (RequestMessage) message; handleRequestIssues(requestMessage, issues); } else if (message instanceof ResponseMessage) { - ResponseMessage responseMessage = (ResponseMessage) message; + final var responseMessage = (ResponseMessage) message; handleResponseIssues(responseMessage, issues); } else { logIssues(message, issues); } } - + protected void logIssues(Message message, List issues) { for (MessageIssue issue : issues) { String logMessage = "Issue found in " + message.getClass().getSimpleName() + ": " + issue.getText(); LOG.log(Level.WARNING, logMessage, issue.getCause()); } } - + protected void handleRequestIssues(RequestMessage requestMessage, List issues) { - ResponseError errorObject = new ResponseError(); + final var errorObject = new ResponseError(); if (issues.size() == 1) { MessageIssue issue = issues.get(0); errorObject.setMessage(issue.getText()); @@ -355,7 +353,7 @@ protected void handleRequestIssues(RequestMessage requestMessage, List issues) { PendingRequestInfo requestInfo; synchronized (sentRequestMap) { @@ -371,7 +369,7 @@ protected void handleResponseIssues(ResponseMessage responseMessage, List startProcessing(MessageProducer messageProducer, MessageConsumer messageConsumer, ExecutorService executorService) { - ConcurrentMessageProcessor reader = new ConcurrentMessageProcessor(messageProducer, messageConsumer); + final var reader = new ConcurrentMessageProcessor(messageProducer, messageConsumer); final Future result = executorService.submit(reader); return wrapFuture(result, messageProducer); } public static Future wrapFuture(Future result, MessageProducer messageProducer) { - return new Future() { + return new Future<>() { @Override public Void get() throws InterruptedException, ExecutionException { @@ -95,10 +95,10 @@ public ConcurrentMessageProcessor(MessageProducer messageProducer, MessageConsum this.messageProducer = messageProducer; this.messageConsumer = messageConsumer; } - + /** * Start a thread that listens for messages in the message producer and forwards them to the message consumer. - * + * * @param executorService - the thread is started using this service * @return a future that is resolved when the started thread is terminated, e.g. by closing a stream */ @@ -107,6 +107,7 @@ public Future beginProcessing(ExecutorService executorService) { return wrapFuture(result, messageProducer); } + @Override public void run() { processingStarted(); try { diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/JsonRpcMethod.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/JsonRpcMethod.java index b2dcf13d..8921f8fb 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/JsonRpcMethod.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/JsonRpcMethod.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json; @@ -16,16 +16,16 @@ import com.google.gson.TypeAdapterFactory; /** - * A description of a JSON-RPC method. + * A description of a JSON-RPC method. */ public class JsonRpcMethod { - + private final String methodName; private final Type[] parameterTypes; private final Type returnType; private final TypeAdapterFactory returnTypeAdapterFactory; private final boolean isNotification; - + private JsonRpcMethod(String methodName, Type[] parameterTypes, Type returnType, TypeAdapterFactory returnTypeAdapterFactory, boolean isNotification) { if (methodName == null) @@ -40,38 +40,38 @@ private JsonRpcMethod(String methodName, Type[] parameterTypes, Type returnType, public String getMethodName() { return methodName; } - + public Type[] getParameterTypes() { return parameterTypes; } - + public Type getReturnType() { return returnType; } - + public TypeAdapterFactory getReturnTypeAdapterFactory() { return returnTypeAdapterFactory; } - + public boolean isNotification() { return isNotification; } - + public static JsonRpcMethod notification(String name, Type... parameterTypes) { return new JsonRpcMethod(name, parameterTypes, Void.class, null, true); } - + public static JsonRpcMethod request(String name, Type returnType, Type... parameterTypes) { return new JsonRpcMethod(name, parameterTypes, returnType, null, false); } - + public static JsonRpcMethod request(String name, Type returnType, TypeAdapterFactory returnTypeAdapterFactory, Type... parameterTypes) { return new JsonRpcMethod(name, parameterTypes, returnType, returnTypeAdapterFactory, false); } - + @Override public String toString() { - StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); if (isNotification) builder.append("JsonRpcMethod (notification) {\n"); else diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageConstants.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageConstants.java index e6676fa1..474e7a7e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageConstants.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageConstants.java @@ -13,10 +13,10 @@ public interface MessageConstants { - public static String JSONRPC_VERSION = "2.0"; - public static String CONTENT_LENGTH_HEADER = "Content-Length"; - public static String CONTENT_TYPE_HEADER = "Content-Type"; - public static String JSON_MIME_TYPE = "application/json"; - public static String CRLF = "\r\n"; + String JSONRPC_VERSION = "2.0"; + String CONTENT_LENGTH_HEADER = "Content-Length"; + String CONTENT_TYPE_HEADER = "Content-Type"; + String JSON_MIME_TYPE = "application/json"; + String CRLF = "\r\n"; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java index c223b2bc..e5faad28 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json; @@ -46,15 +46,15 @@ * A wrapper around Gson that includes configuration required for JSON-RPC messages. */ public class MessageJsonHandler { - + public static final JsonRpcMethod CANCEL_METHOD = JsonRpcMethod.notification("$/cancelRequest", CancelParams.class); private final Gson gson; private final Map supportedMethods; - + private MethodProvider methodProvider; - + /** * @param supportedMethods - a map used to resolve RPC methods in {@link #getJsonRpcMethod(String)} */ @@ -62,7 +62,7 @@ public MessageJsonHandler(Map supportedMethods) { this.supportedMethods = supportedMethods; this.gson = getDefaultGsonBuilder().create(); } - + /** * @param supportedMethods - a map used to resolve RPC methods in {@link #getJsonRpcMethod(String)} * @param configureGson - a function that contributes to the GsonBuilder created by {@link #getDefaultGsonBuilder()} @@ -73,7 +73,7 @@ public MessageJsonHandler(Map supportedMethods, Consumer< configureGson.accept(gsonBuilder); this.gson = gsonBuilder.create(); } - + /** * Create a {@link GsonBuilder} with default settings for parsing JSON-RPC messages. */ @@ -86,11 +86,11 @@ public GsonBuilder getDefaultGsonBuilder() { .registerTypeAdapterFactory(new EnumTypeAdapter.Factory()) .registerTypeAdapterFactory(new MessageTypeAdapter.Factory(this)); } - + public Gson getGson() { return gson; } - + /** * Resolve an RPC method by name. */ @@ -102,35 +102,35 @@ else if (CANCEL_METHOD.getMethodName().equals(name)) return CANCEL_METHOD; return null; } - + public MethodProvider getMethodProvider() { return methodProvider; } - + public void setMethodProvider(MethodProvider methodProvider) { this.methodProvider = methodProvider; } - + public Message parseMessage(CharSequence input) throws JsonParseException { - StringReader reader = new StringReader(input.toString()); + final var reader = new StringReader(input.toString()); return parseMessage(reader); } - + public Message parseMessage(Reader input) throws JsonParseException { JsonReader jsonReader = new JsonReader(input); Message message = gson.fromJson(jsonReader, Message.class); - + if (message != null) { message.setJsonHandler(this); // Check whether the input has been fully consumed try { if (jsonReader.peek() != JsonToken.END_DOCUMENT) { - MessageIssue issue = new MessageIssue("JSON document was not fully consumed.", ResponseErrorCode.ParseError.getValue()); + final var issue = new MessageIssue("JSON document was not fully consumed.", ResponseErrorCode.ParseError.getValue()); throw new MessageIssueException(message, issue); } } catch (MalformedJsonException e) { - MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), e); + final var issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), e); throw new MessageIssueException(message, issue); } catch (IOException e) { throw new JsonIOException(e); @@ -138,13 +138,13 @@ public Message parseMessage(Reader input) throws JsonParseException { } return message; } - + public String serialize(Message message) { - StringWriter writer = new StringWriter(); + final var writer = new StringWriter(); serialize(message, writer); return writer.toString(); } - + public void serialize(Message message, Writer output) throws JsonIOException { gson.toJson(message, Message.class, output); } @@ -154,7 +154,7 @@ public void serialize(Message message, Writer output) throws JsonIOException { * enhanced with the pretty printing option. */ public String format(Object object) { - StringWriter writer = new StringWriter(); + final var writer = new StringWriter(); JsonWriter jsonWriter = null; try { jsonWriter = gson.newJsonWriter(writer); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/StreamMessageConsumer.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/StreamMessageConsumer.java index 313c4723..3f1bfbad 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/StreamMessageConsumer.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/StreamMessageConsumer.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json; @@ -78,7 +78,7 @@ public void consume(Message message) { * {@code Content-Length} and {@code Content-Type} attributes according to the LSP specification. */ protected String getHeader(int contentLength) { - StringBuilder headerBuilder = new StringBuilder(); + final var headerBuilder = new StringBuilder(); appendHeader(headerBuilder, CONTENT_LENGTH_HEADER, contentLength).append(CRLF); if (!StandardCharsets.UTF_8.name().equals(encoding)) { appendHeader(headerBuilder, CONTENT_TYPE_HEADER, JSON_MIME_TYPE); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/CollectionTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/CollectionTypeAdapter.java index 96d34f80..d88b8d65 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/CollectionTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/CollectionTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2017 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json.adapters; @@ -38,7 +38,7 @@ * A specialized type adapter for collections that can handle single values. */ public class CollectionTypeAdapter extends TypeAdapter> { - + public static class Factory implements TypeAdapterFactory { @Override @@ -77,13 +77,13 @@ protected Supplier> getConstructor(Class new TreeSet(); + return TreeSet::new; else if (Set.class.isAssignableFrom(rawType)) - return () -> new LinkedHashSet(); + return LinkedHashSet::new; else if (Queue.class.isAssignableFrom(rawType)) - return () -> new LinkedList(); + return LinkedList::new; else - return () -> new ArrayList(); + return ArrayList::new; } } @@ -135,7 +135,7 @@ public void write(JsonWriter out, Collection collection) throws IOException { if (element != null && elementType != element.getClass() && (elementType instanceof TypeVariable || elementType instanceof Class)) { @SuppressWarnings("unchecked") - TypeAdapter runtimeTypeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(element.getClass())); + final var runtimeTypeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(element.getClass())); runtimeTypeAdapter.write(out, element); } else { elementTypeAdapter.write(out, element); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EitherTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EitherTypeAdapter.java index 29dd9c58..1dff4c8e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EitherTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EitherTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json.adapters; @@ -51,29 +51,29 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { } } - + /** * A predicate that is useful for checking alternatives in case both the left and the right type * are JSON object types. */ public static class PropertyChecker implements Predicate { - + private final String propertyName; private final String expectedValue; private final Class expectedType; - + public PropertyChecker(String propertyName) { this.propertyName = propertyName; this.expectedValue = null; this.expectedType = null; } - + public PropertyChecker(String propertyName, String expectedValue) { this.propertyName = propertyName; this.expectedValue = expectedValue; this.expectedType = null; } - + public PropertyChecker(String propertyName, Class expectedType) { this.propertyName = propertyName; this.expectedType = expectedType; @@ -94,21 +94,21 @@ else if (expectedType != null) } return false; } - + } - + /** * A predicate for the case that a type alternative is a list. */ public static class ListChecker implements Predicate { - + private final Predicate elementChecker; private final boolean resultIfEmpty; - + public ListChecker(Predicate elementChecker) { this(elementChecker, false); } - + public ListChecker(Predicate elementChecker, boolean resultIfEmpty) { this.elementChecker = elementChecker; this.resultIfEmpty = resultIfEmpty; @@ -129,7 +129,7 @@ public boolean test(JsonElement t) { } return false; } - + } protected final TypeToken> typeToken; @@ -141,7 +141,7 @@ public boolean test(JsonElement t) { public EitherTypeAdapter(Gson gson, TypeToken> typeToken) { this(gson, typeToken, null, null); } - + public EitherTypeAdapter(Gson gson, TypeToken> typeToken, Predicate leftChecker, Predicate rightChecker) { this(gson, typeToken, leftChecker, rightChecker, null, null); } @@ -150,8 +150,8 @@ public EitherTypeAdapter(Gson gson, TypeToken> typeToken, TypeAdapter leftAdapter, TypeAdapter rightAdapter) { this.typeToken = typeToken; Type[] elementTypes = TypeUtils.getElementTypes(typeToken, Either.class); - this.left = new EitherTypeArgument(gson, elementTypes[0], leftAdapter); - this.right = new EitherTypeArgument(gson, elementTypes[1], rightAdapter); + this.left = new EitherTypeArgument<>(gson, elementTypes[0], leftAdapter); + this.right = new EitherTypeArgument<>(gson, elementTypes[1], rightAdapter); this.leftChecker = leftChecker; this.rightChecker = rightChecker; } @@ -209,14 +209,14 @@ protected Either create(JsonToken nextToken, JsonReader in) throws IOExcep } throw new JsonParseException("Unexpected token " + nextToken + ": expected " + left + " | " + right + " tokens."); } - + @SuppressWarnings("unchecked") protected Either createLeft(L obj) throws IOException { if (Either3.class.isAssignableFrom(typeToken.getRawType())) return (Either) Either3.forLeft3(obj); return Either.forLeft(obj); } - + @SuppressWarnings("unchecked") protected Either createRight(R obj) throws IOException { if (Either3.class.isAssignableFrom(typeToken.getRawType())) @@ -237,8 +237,8 @@ public EitherTypeArgument(Gson gson, Type type) { @SuppressWarnings("unchecked") public EitherTypeArgument(Gson gson, Type type, TypeAdapter adapter) { this.typeToken = (TypeToken) TypeToken.get(type); - this.adapter = (adapter != null) ? adapter : - ((type == Object.class) ? (TypeAdapter) new JsonElementTypeAdapter(gson) : gson.getAdapter(this.typeToken)); + this.adapter = adapter != null ? adapter : + type == Object.class ? (TypeAdapter) new JsonElementTypeAdapter(gson) : gson.getAdapter(this.typeToken); this.expectedTokens = new HashSet<>(); for (Type expectedType : TypeUtils.getExpectedTypes(type)) { Class rawType = TypeToken.get(expectedType).getRawType(); @@ -274,14 +274,14 @@ public void write(JsonWriter out, T value) throws IOException { public T read(JsonReader in) throws IOException { return this.adapter.read(in); } - + public T read(JsonElement element) throws IOException { return this.adapter.fromJsonTree(element); } @Override public String toString() { - StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); for (JsonToken expectedToken : expectedTokens) { if (builder.length() != 0) { builder.append(" | "); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EnumTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EnumTypeAdapter.java index c24ded2f..622bdd07 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EnumTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/EnumTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2017 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json.adapters; @@ -28,7 +28,7 @@ * A custom type adapter for enums that uses integer values. */ public class EnumTypeAdapter> extends TypeAdapter { - + public static class Factory implements TypeAdapterFactory { @Override @@ -45,15 +45,15 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { throw new RuntimeException(e); } } - + } - + private static String VALUE_FIELD_NAME = "value"; - + private final Map nameToConstant = new HashMap<>(); private final Map valueToConstant = new HashMap<>(); private final Map constantToValue = new HashMap<>(); - + EnumTypeAdapter(Class classOfT) throws IllegalAccessException { try { Field valueField = classOfT.getDeclaredField(VALUE_FIELD_NAME); @@ -62,7 +62,7 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { valueField.setAccessible(true); for (T constant : classOfT.getEnumConstants()) { nameToConstant.put(constant.name(), constant); - Integer constValue = (Integer) valueField.get(constant); + final var constValue = (Integer) valueField.get(constant); valueToConstant.put(constValue, constant); constantToValue.put(constant, constValue); } @@ -75,7 +75,7 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { } } } - + @Override public T read(JsonReader in) throws IOException { JsonToken peek = in.peek(); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/JsonElementTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/JsonElementTypeAdapter.java index 0e19daa9..9da26afd 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/JsonElementTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/JsonElementTypeAdapter.java @@ -61,7 +61,7 @@ public void write(JsonWriter out, Object value) throws IOException { } else if (value instanceof JsonElement) { adapter.write(out, (JsonElement) value); } else { - gson.toJson(value, value.getClass(), out);; + gson.toJson(value, value.getClass(), out); } } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java index 64f0c491..180ea503 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016-2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json.adapters; @@ -54,11 +54,11 @@ * {@link ResponseMessage}, and {@link NotificationMessage}. */ public class MessageTypeAdapter extends TypeAdapter { - + public static class Factory implements TypeAdapterFactory { - + private final MessageJsonHandler handler; - + public Factory(MessageJsonHandler handler) { this.handler = handler; } @@ -70,14 +70,14 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { return null; return (TypeAdapter) new MessageTypeAdapter(handler, gson); } - + } - + private static Type[] EMPTY_TYPE_ARRAY = {}; private final MessageJsonHandler handler; private final Gson gson; - + public MessageTypeAdapter(MessageJsonHandler handler, Gson gson) { this.handler = handler; this.gson = gson; @@ -89,7 +89,7 @@ public Message read(JsonReader in) throws IOException, JsonIOException, JsonSynt in.nextNull(); return null; } - + in.beginObject(); String jsonrpc = null, method = null; Either id = null; @@ -97,7 +97,7 @@ public Message read(JsonReader in) throws IOException, JsonIOException, JsonSynt Object rawResult = null; ResponseError responseError = null; try { - + while (in.hasNext()) { String name = in.nextName(); switch (name) { @@ -134,19 +134,18 @@ public Message read(JsonReader in) throws IOException, JsonIOException, JsonSynt } Object params = parseParams(rawParams, method); Object result = parseResult(rawResult, id != null ? id.get().toString() : null); - + in.endObject(); return createMessage(jsonrpc, id, method, params, result, responseError); - + } catch (JsonSyntaxException | MalformedJsonException | EOFException exception) { if (id != null || method != null) { // Create a message and bundle it to an exception with an issue that wraps the original exception Message message = createMessage(jsonrpc, id, method, rawParams, rawResult, responseError); - MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); + final var issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(message, issue); - } else { - throw exception; } + throw exception; } } @@ -264,7 +263,7 @@ protected Object parseParams(JsonReader in, String method) throws IOException, J return fromJson(in, parameterTypes[0]); } if (parameterTypes.length > 1 && next == JsonToken.BEGIN_ARRAY) { - List parameters = new ArrayList(parameterTypes.length); + final var parameters = new ArrayList<>(parameterTypes.length); int index = 0; in.beginArray(); while (in.hasNext()) { @@ -307,18 +306,18 @@ protected Object parseParams(Object params, String method) { if (!(params instanceof JsonElement)) { return params; } - JsonElement rawParams = (JsonElement) params; + final var rawParams = (JsonElement) params; Type[] parameterTypes = getParameterTypes(method); if (parameterTypes.length == 1) { return fromJson(rawParams, parameterTypes[0]); } if (parameterTypes.length > 1 && rawParams instanceof JsonArray) { JsonArray array = (JsonArray) rawParams; - List parameters = new ArrayList(Math.max(array.size(), parameterTypes.length)); + final var parameters = new ArrayList<>(Math.max(array.size(), parameterTypes.length)); int index = 0; Iterator iterator = array.iterator(); while (iterator.hasNext()) { - Type parameterType = index < parameterTypes.length ? parameterTypes[index] : null; + Type parameterType = index < parameterTypes.length ? parameterTypes[index] : null; Object parameter = fromJson(iterator.next(), parameterType); parameters.add(parameter); index++; @@ -343,7 +342,7 @@ protected Object fromJson(JsonReader in, Type type) throws JsonIOException { } return gson.fromJson(in, type); } - + protected Object fromJson(JsonElement element, Type type) { if (isNull(element)) { return null; @@ -361,7 +360,7 @@ protected Object fromJson(JsonElement element, Type type) { protected boolean isNull(Object value) { return value == null || value instanceof JsonNull; } - + protected boolean isNullOrVoidType(Type type) { return type == null || Void.class == type; } @@ -374,11 +373,11 @@ protected Type[] getParameterTypes(String method) { } return EMPTY_TYPE_ARRAY; } - + protected Message createMessage(String jsonrpc, Either id, String method, Object params, Object responseResult, ResponseError responseError) throws JsonParseException { if (id != null && method != null) { - RequestMessage message = new RequestMessage(); + final var message = new RequestMessage(); message.setJsonHandler(handler); message.setJsonrpc(jsonrpc); message.setRawId(id); @@ -386,7 +385,7 @@ protected Message createMessage(String jsonrpc, Either id, Strin message.setParams(params); return message; } else if (id != null) { - ResponseMessage message = new ResponseMessage(); + final var message = new ResponseMessage(); message.setJsonHandler(handler); message.setJsonrpc(jsonrpc); message.setRawId(id); @@ -396,7 +395,7 @@ protected Message createMessage(String jsonrpc, Either id, Strin message.setResult(responseResult); return message; } else if (method != null) { - NotificationMessage message = new NotificationMessage(); + final var message = new NotificationMessage(); message.setJsonHandler(handler); message.setJsonrpc(jsonrpc); message.setMethod(method); @@ -412,9 +411,9 @@ public void write(JsonWriter out, Message message) throws IOException { out.beginObject(); out.name("jsonrpc"); out.value(message.getJsonrpc() == null ? MessageConstants.JSONRPC_VERSION : message.getJsonrpc()); - + if (message instanceof RequestMessage) { - RequestMessage requestMessage = (RequestMessage) message; + final var requestMessage = (RequestMessage) message; out.name("id"); writeId(out, requestMessage.getRawId()); out.name("method"); @@ -426,7 +425,7 @@ public void write(JsonWriter out, Message message) throws IOException { else handleParameter(out, params, requestMessage.getMethod()); } else if (message instanceof ResponseMessage) { - ResponseMessage responseMessage = (ResponseMessage) message; + final var responseMessage = (ResponseMessage) message; out.name("id"); writeId(out, responseMessage.getRawId()); if (responseMessage.getError() != null) { @@ -441,7 +440,7 @@ public void write(JsonWriter out, Message message) throws IOException { gson.toJson(result, result.getClass(), out); } } else if (message instanceof NotificationMessage) { - NotificationMessage notificationMessage = (NotificationMessage) message; + final var notificationMessage = (NotificationMessage) message; out.name("method"); out.value(notificationMessage.getMethod()); out.name("params"); @@ -451,13 +450,13 @@ public void write(JsonWriter out, Message message) throws IOException { else handleParameter(out, params, notificationMessage.getMethod()); } - + out.endObject(); } - + protected void handleParameter(JsonWriter out, Object params, String method) { - boolean isSingleArray = (getParameterTypes(method).length == 1 && Collection.class.isInstance(params) - || params.getClass().isArray()); + boolean isSingleArray = getParameterTypes(method).length == 1 && Collection.class.isInstance(params) + || params.getClass().isArray(); boolean needsWrap = isSingleArray || params instanceof String || isWrapperType(params.getClass()) || isPrimitive(getClass()); if (needsWrap) { @@ -466,7 +465,7 @@ protected void handleParameter(JsonWriter out, Object params, String method) { gson.toJson(params, params.getClass(), out); } } - + protected void writeId(JsonWriter out, Either id) throws IOException { if (id == null) writeNullValue(out); @@ -475,7 +474,7 @@ else if (id.isLeft()) else if (id.isRight()) out.value(id.getRight()); } - + /** * Use this method to write a {@code null} value even if the JSON writer is set to not serialize {@code null}. */ @@ -485,7 +484,7 @@ protected void writeNullValue(JsonWriter out) throws IOException { out.nullValue(); out.setSerializeNulls(previousSerializeNulls); } - + /** * Returns true if this type is a primitive. */ diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TupleTypeAdapters.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TupleTypeAdapters.java index 2214f03d..240b132e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TupleTypeAdapters.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TupleTypeAdapters.java @@ -14,14 +14,14 @@ import com.google.gson.stream.JsonWriter; public final class TupleTypeAdapters { - + private TupleTypeAdapters() {} public static class TwoTypeAdapter extends TypeAdapter> { - + protected final TypeAdapter first; protected final TypeAdapter second; - + @SuppressWarnings("unchecked") public TwoTypeAdapter(Gson gson, TypeToken> typeToken) { Type[] elementTypes = TypeUtils.getElementTypes(typeToken, Two.class); @@ -40,7 +40,7 @@ public void write(final JsonWriter out, final Two value) throws IOExceptio out.endArray(); } } - + @Override public Two read(final JsonReader in) throws IOException { JsonToken next = in.peek(); @@ -51,11 +51,11 @@ public Two read(final JsonReader in) throws IOException { in.beginArray(); F f = first.read(in); S s = second.read(in); - Two result = new Two(f, s); + final var result = new Two<>(f, s); in.endArray(); return result; } - + } public static class TwoTypeAdapterFactory implements TypeAdapterFactory { diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TypeUtils.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TypeUtils.java index 11e45308..b8f8727e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TypeUtils.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/TypeUtils.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2017 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.json.adapters; @@ -31,16 +31,16 @@ * Utilities for handling types in the JSON parser / serializer. */ public final class TypeUtils { - + private TypeUtils() {} - + /** * Determine the actual type arguments of the given type token with regard to the given target type. */ public static Type[] getElementTypes(TypeToken typeToken, Class targetType) { return getElementTypes(typeToken.getType(), typeToken.getRawType(), targetType); } - + private static Type[] getElementTypes(Type type, Class rawType, Class targetType) { if (targetType.equals(rawType) && type instanceof ParameterizedType) { Type mappedType; @@ -74,16 +74,16 @@ private static Type[] getElementTypes(Type type, Class rawType, Class targ } } // No luck, return an array of Object types - Type[] result = new Type[targetType.getTypeParameters().length]; + final var result = new Type[targetType.getTypeParameters().length]; Arrays.fill(result, Object.class); return result; } - + private static Map createVariableMapping(Type type, Class rawType) { if (type instanceof ParameterizedType) { TypeVariable>[] vars = rawType.getTypeParameters(); Type[] args = ((ParameterizedType) type).getActualTypeArguments(); - Map newVarMapping = new HashMap<>(capacity(vars.length)); + final var newVarMapping = new HashMap(capacity(vars.length)); for (int i = 0; i < vars.length; i++) { Type actualType = Object.class; if (i < args.length) { @@ -97,14 +97,13 @@ private static Map createVariableMapping(Type type, Class r } return Collections.emptyMap(); } - + private static int capacity(int expectedSize) { if (expectedSize < 3) return expectedSize + 1; - else - return expectedSize + expectedSize / 3; + return expectedSize + expectedSize / 3; } - + private static Type getMappedType(Type type, Map varMapping) { if (type instanceof TypeVariable) { String name = ((TypeVariable) type).getName(); @@ -127,26 +126,26 @@ private static Type getMappedType(Type type, Map varMapping) { } private static class ParameterizedTypeImpl implements ParameterizedType { - + private final Type ownerType; private final Type rawType; private final Type[] actualTypeArguments; - + ParameterizedTypeImpl(ParameterizedType original, Type[] typeArguments) { this(original.getOwnerType(), original.getRawType(), typeArguments); } - + ParameterizedTypeImpl(Type ownerType, Type rawType, Type[] typeArguments) { this.ownerType = ownerType; this.rawType = rawType; this.actualTypeArguments = typeArguments; } - + @Override public Type getOwnerType() { return ownerType; } - + @Override public Type getRawType() { return rawType; @@ -156,10 +155,10 @@ public Type getRawType() { public Type[] getActualTypeArguments() { return actualTypeArguments; } - + @Override public String toString() { - StringBuilder result = new StringBuilder(); + final var result = new StringBuilder(); if (ownerType != null) { result.append(toString(ownerType)); result.append('$'); @@ -174,16 +173,15 @@ public String toString() { result.append('>'); return result.toString(); } - + private String toString(Type type) { if (type instanceof Class) return ((Class) type).getName(); - else - return String.valueOf(type); + return String.valueOf(type); } - + } - + /** * Return all possible types that can be expected when an element of the given type is parsed. * If the type satisfies {@link #isEither(Type)}, a list of the corresponding type arguments is returned, @@ -191,7 +189,7 @@ private String toString(Type type) { * by this method (use {@link #getElementTypes(TypeToken, Class)} to get resolved parameters). */ public static Collection getExpectedTypes(Type type) { - Collection result = new ArrayList<>(); + final var result = new ArrayList(); collectExpectedTypes(type, result); return result; } @@ -225,7 +223,7 @@ public static boolean isEither(Type type) { } return false; } - + /** * Test whether the given type is a two-tuple (pair). */ diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/CancelParams.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/CancelParams.java index 727cb0a9..681c0b6f 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/CancelParams.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/CancelParams.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -21,7 +21,7 @@ * To cancel a request a notification message with the following properties is sent. */ public class CancelParams { - + /** * The request id to cancel. */ @@ -38,7 +38,7 @@ public String getId() { return id.getRight().toString(); return null; } - + @NonNull public Either getRawId() { return id; @@ -47,15 +47,15 @@ public Either getRawId() { public void setId(@NonNull String id) { this.id = Either.forLeft(id); } - + public void setId(@NonNull int id) { this.id = Either.forRight(id); } - + public void setRawId(@NonNull Either id) { this.id = id; } - + @Override public String toString() { try { @@ -66,7 +66,7 @@ public String toString() { } protected String toStringFallback() { - ToStringBuilder builder = new ToStringBuilder(this); + final var builder = new ToStringBuilder(this); builder.addAllFields(); return builder.toString(); } @@ -79,7 +79,7 @@ public boolean equals(final Object obj) { return false; if (getClass() != obj.getClass()) return false; - CancelParams other = (CancelParams) obj; + final var other = (CancelParams) obj; if (this.id == null) { if (other.id != null) return false; @@ -92,7 +92,7 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + (this.id == null ? 0 : this.id.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either.java index 0b5f4844..4ba5e77c 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either.java @@ -80,10 +80,10 @@ public T map( @Override public boolean equals(Object obj) { if (obj instanceof Either) { - Either other = (Either) obj; - return (this.left == other.left && this.right == other.right) - || (this.left != null && other.left != null && this.left.equals(other.left)) - || (this.right != null && other.right != null && this.right.equals(other.right)); + final var other = (Either) obj; + return this.left == other.left && this.right == other.right + || this.left != null && other.left != null && this.left.equals(other.left) + || this.right != null && other.right != null && this.right.equals(other.right); } return false; } @@ -97,8 +97,9 @@ public int hashCode() { return 0; } + @Override public String toString() { - StringBuilder builder = new StringBuilder("Either [").append(System.lineSeparator()); + final var builder = new StringBuilder("Either [").append(System.lineSeparator()); builder.append(" left = ").append(left).append(System.lineSeparator()); builder.append(" right = ").append(right).append(System.lineSeparator()); return builder.append("]").toString(); @@ -113,7 +114,7 @@ public String toString() { public static Type getLeftDisjointType(Type type) { if (isEither(type)) { if (type instanceof ParameterizedType) { - final ParameterizedType parameterizedType = (ParameterizedType) type; + final var parameterizedType = (ParameterizedType) type; return parameterizedType.getActualTypeArguments()[0]; } if (type instanceof Class) { @@ -133,7 +134,7 @@ public static Type getLeftDisjointType(Type type) { public static Type getRightDisjointType(Type type) { if (isEither(type)) { if (type instanceof ParameterizedType) { - final ParameterizedType parameterizedType = (ParameterizedType) type; + final var parameterizedType = (ParameterizedType) type; return parameterizedType.getActualTypeArguments()[1]; } if (type instanceof Class) { diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either3.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either3.java index 81f385ec..4e0866bb 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either3.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Either3.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2017 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -19,66 +19,64 @@ * Union type for three types. */ public class Either3 extends Either> { - + public static Either3 forFirst(@NonNull T1 first) { - return new Either3(first, null); + return new Either3<>(first, null); } public static Either3 forSecond(@NonNull T2 second) { - return new Either3(null, new Either(second, null)); + return new Either3<>(null, new Either<>(second, null)); } - + public static Either3 forThird(@NonNull T3 third) { - return new Either3(null, new Either(null, third)); + return new Either3<>(null, new Either<>(null, third)); } - + public static Either3 forLeft3(@NonNull T1 first) { - return new Either3(first, null); + return new Either3<>(first, null); } - + public static Either3 forRight3(@NonNull Either right) { - return new Either3(null, right); + return new Either3<>(null, right); } protected Either3(T1 left, Either right) { super(left, right); } - + public T1 getFirst() { return getLeft(); } - + public T2 getSecond() { Either right = getRight(); if (right == null) return null; - else - return right.getLeft(); + return right.getLeft(); } - + public T3 getThird() { Either right = getRight(); if (right == null) return null; - else - return right.getRight(); + return right.getRight(); } - + @Override public Object get() { if (isRight()) return getRight().get(); return super.get(); } - + public boolean isFirst() { return isLeft(); } - + public boolean isSecond() { return isRight() && getRight().isLeft(); } - + public boolean isThird() { return isRight() && getRight().isRight(); } @@ -101,7 +99,7 @@ public T map( @Override public String toString() { - StringBuilder builder = new StringBuilder("Either3 [").append(System.lineSeparator()); + final var builder = new StringBuilder("Either3 [").append(System.lineSeparator()); builder.append(" first = ").append(getFirst()).append(System.lineSeparator()); builder.append(" second = ").append(getSecond()).append(System.lineSeparator()); builder.append(" third = ").append(getThird()).append(System.lineSeparator()); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/IdentifiableMessage.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/IdentifiableMessage.java index 61faf65a..75b181cb 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/IdentifiableMessage.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/IdentifiableMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -17,7 +17,7 @@ * A message with an {@code id} property. */ public abstract class IdentifiableMessage extends Message { - + /** * The message identifier. */ @@ -33,7 +33,7 @@ public String getId() { return id.getRight().toString(); return null; } - + @NonNull public Either getRawId() { return id; @@ -42,11 +42,11 @@ public Either getRawId() { public void setId(String id) { this.id = Either.forLeft(id); } - + public void setId(int id) { this.id = Either.forRight(id); } - + public void setRawId(@NonNull Either id) { this.id = id; } @@ -61,7 +61,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - IdentifiableMessage other = (IdentifiableMessage) obj; + final var other = (IdentifiableMessage) obj; if (this.id == null) { if (other.id != null) return false; @@ -74,7 +74,7 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + (this.id == null ? 0 : this.id.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Message.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Message.java index 15063ed7..98ef3aca 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Message.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Message.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -51,7 +51,7 @@ public String getJsonrpc() { public void setJsonrpc(@NonNull String jsonrpc) { this.jsonrpc = jsonrpc; } - + @Override public String toString() { try { @@ -62,7 +62,7 @@ public String toString() { } protected String toStringFallback() { - ToStringBuilder builder = new ToStringBuilder(this); + final var builder = new ToStringBuilder(this); builder.addAllFields(field -> !Modifier.isTransient(field.getModifiers())); return builder.toString(); } @@ -75,7 +75,7 @@ public boolean equals(final Object obj) { return false; if (getClass() != obj.getClass()) return false; - Message other = (Message) obj; + final var other = (Message) obj; if (this.jsonrpc == null) { if (other.jsonrpc != null) return false; @@ -88,7 +88,7 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.jsonrpc == null) ? 0 : this.jsonrpc.hashCode()); + result = prime * result + (this.jsonrpc == null ? 0 : this.jsonrpc.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/MessageIssue.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/MessageIssue.java index 12202553..5c77819f 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/MessageIssue.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/MessageIssue.java @@ -19,11 +19,11 @@ public class MessageIssue { @NonNull - private String text; + private final String text; - private int code; + private final int code; - private Exception cause; + private final Exception cause; public MessageIssue(@NonNull String text) { this(text, 0, null); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/NotificationMessage.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/NotificationMessage.java index b10f9d46..94f0a23b 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/NotificationMessage.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/NotificationMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -57,7 +57,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - NotificationMessage other = (NotificationMessage) obj; + final var other = (NotificationMessage) obj; if (this.method == null) { if (other.method != null) return false; @@ -75,8 +75,8 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.method == null) ? 0 : this.method.hashCode()); - result = prime * result + ((this.params == null) ? 0 : this.params.hashCode()); + result = prime * result + (this.method == null ? 0 : this.method.hashCode()); + result = prime * result + (this.params == null ? 0 : this.params.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/RequestMessage.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/RequestMessage.java index 42d76c26..107611c1 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/RequestMessage.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/RequestMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -58,7 +58,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - RequestMessage other = (RequestMessage) obj; + final var other = (RequestMessage) obj; if (this.method == null) { if (other.method != null) return false; @@ -76,8 +76,8 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.method == null) ? 0 : this.method.hashCode()); - result = prime * result + ((this.params == null) ? 0 : this.params.hashCode()); + result = prime * result + (this.method == null ? 0 : this.method.hashCode()); + result = prime * result + (this.params == null ? 0 : this.params.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseError.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseError.java index 2dcd919a..00313b0e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseError.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseError.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -93,7 +93,7 @@ public String toString() { } protected String toStringFallback() { - ToStringBuilder builder = new ToStringBuilder(this); + final var builder = new ToStringBuilder(this); builder.addAllFields(); return builder.toString(); } @@ -106,7 +106,7 @@ public boolean equals(final Object obj) { return false; if (getClass() != obj.getClass()) return false; - ResponseError other = (ResponseError) obj; + final var other = (ResponseError) obj; if (other.code != this.code) return false; if (this.message == null) { @@ -127,8 +127,8 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + this.code; - result = prime * result + ((this.message == null) ? 0 : this.message.hashCode()); - result = prime * result + ((this.data == null) ? 0 : this.data.hashCode()); + result = prime * result + (this.message == null ? 0 : this.message.hashCode()); + result = prime * result + (this.data == null ? 0 : this.data.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseMessage.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseMessage.java index baf33e3b..f72de4f9 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseMessage.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/ResponseMessage.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.messages; @@ -57,7 +57,7 @@ public boolean equals(final Object obj) { return false; if (!super.equals(obj)) return false; - ResponseMessage other = (ResponseMessage) obj; + final var other = (ResponseMessage) obj; if (this.result == null) { if (other.result != null) return false; @@ -75,8 +75,8 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((this.result == null) ? 0 : this.result.hashCode()); - result = prime * result + ((this.error == null) ? 0 : this.error.hashCode()); + result = prime * result + (this.result == null ? 0 : this.result.hashCode()); + result = prime * result + (this.error == null ? 0 : this.error.hashCode()); return result; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Tuple.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Tuple.java index 03618ceb..528a15b3 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Tuple.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/messages/Tuple.java @@ -1,28 +1,19 @@ package org.eclipse.lsp4j.jsonrpc.messages; -import java.io.IOException; - -import org.eclipse.lsp4j.jsonrpc.validation.NonNull; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - /** * Representation of tuple types. */ -@SuppressWarnings("all") public interface Tuple { - public static Two two(F first, S second) { - return new Two(first, second); + static Two two(F first, S second) { + return new Two<>(first, second); } - + /** * A two-tuple, i.e. a pair. */ public static class Two implements Tuple { - + private final F first; private final S second; @@ -47,7 +38,7 @@ public boolean equals(final Object obj) { return false; if (getClass() != obj.getClass()) return false; - Tuple.Two other = (Tuple.Two) obj; + final var other = (Tuple.Two) obj; if (this.first == null) { if (other.first != null) return false; @@ -65,17 +56,17 @@ public boolean equals(final Object obj) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.first == null) ? 0 : this.first.hashCode()); - return prime * result + ((this.second == null) ? 0 : this.second.hashCode()); + result = prime * result + (this.first == null ? 0 : this.first.hashCode()); + return prime * result + (this.second == null ? 0 : this.second.hashCode()); } @Override public String toString() { - StringBuilder builder = new StringBuilder("Tuples.Two [").append(System.lineSeparator()); + final var builder = new StringBuilder("Tuples.Two [").append(System.lineSeparator()); builder.append(" first = ").append(first).append(System.lineSeparator()); builder.append(" second = ").append(second).append(System.lineSeparator()); return builder.append("]").toString(); } } - + } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/AnnotationUtil.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/AnnotationUtil.java index 48f6fc2f..8933c954 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/AnnotationUtil.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/AnnotationUtil.java @@ -1,17 +1,18 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.services; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.Arrays; import java.util.Set; @@ -19,7 +20,7 @@ public final class AnnotationUtil { private AnnotationUtil() {} - + public static void findDelegateSegments(Class clazz, Set> visited, Consumer acceptor) { if (clazz == null || !visited.add(clazz)) return; @@ -47,7 +48,6 @@ public static boolean isDelegateMethod(Method method) { } return false; } - /** * Depth first search for annotated methods in hierarchy. @@ -72,7 +72,7 @@ protected static String getSegment(Class clazz) { JsonSegment jsonSegment = clazz.getAnnotation(JsonSegment.class); return jsonSegment == null ? "" : jsonSegment.value() + "/"; } - + protected static MethodInfo createMethodInfo(Method method, String segment) { if (!method.isSynthetic()) { JsonRequest jsonRequest = method.getAnnotation(JsonRequest.class); @@ -92,30 +92,30 @@ protected static MethodInfo createNotificationInfo(Method method, String segment methodInfo.isNotification = true; return methodInfo; } - + protected static MethodInfo createRequestInfo(Method method, String segment, JsonRequest jsonRequest) { return createMethodInfo(method, jsonRequest.useSegment(), segment, jsonRequest.value()); } - + protected static MethodInfo createMethodInfo(Method method, boolean useSegment, String segment, String value) { method.setAccessible(true); - MethodInfo methodInfo = new MethodInfo(); + final var methodInfo = new MethodInfo(); methodInfo.method = method; methodInfo.parameterTypes = getParameterTypes(method); methodInfo.name = getMethodName(method, useSegment, segment, value); return methodInfo; } - + protected static String getMethodName(Method method, boolean useSegment, String segment, String value) { String name = value != null && value.length() > 0 ? value : method.getName(); return useSegment ? segment + name : name; } protected static Type[] getParameterTypes(Method method) { - return Arrays.stream(method.getParameters()).map(t -> t.getParameterizedType()).toArray(Type[]::new); + return Arrays.stream(method.getParameters()).map(Parameter::getParameterizedType).toArray(Type[]::new); } - + static class MethodInfo { private static Type[] EMPTY_TYPE_ARRAY = {}; public String name; diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/EndpointProxy.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/EndpointProxy.java index bb1609c7..54f3625e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/EndpointProxy.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/EndpointProxy.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.services; @@ -29,7 +29,7 @@ * containing {@link JsonNotification} and {@link JsonRequest} methods. */ public class EndpointProxy implements InvocationHandler { - + private final Method object_equals; private final Method object_hashCode; private final Method object_toString; @@ -41,7 +41,7 @@ public class EndpointProxy implements InvocationHandler { public EndpointProxy(Endpoint delegate, Class interface_) { this(delegate, Collections.singletonList(interface_)); } - + public EndpointProxy(Endpoint delegate, Collection> interfaces) { if (delegate == null) throw new NullPointerException("delegate"); @@ -49,7 +49,7 @@ public EndpointProxy(Endpoint delegate, Collection> interfaces) { throw new NullPointerException("interfaces"); if (interfaces.isEmpty()) throw new IllegalArgumentException("interfaces must not be empty."); - + this.delegate = delegate; try { object_equals = Object.class.getDeclaredMethod("equals", Object.class); @@ -61,14 +61,14 @@ public EndpointProxy(Endpoint delegate, Collection> interfaces) { methodInfos = new LinkedHashMap<>(); delegatedSegments = new LinkedHashMap<>(); for (Class interf : interfaces) { - AnnotationUtil.findRpcMethods(interf, new HashSet>(), (methodInfo) -> { + AnnotationUtil.findRpcMethods(interf, new HashSet<>(), methodInfo -> { if (methodInfos.put(methodInfo.method.getName(), methodInfo) != null) { throw new IllegalStateException("Duplicate RPC method " + methodInfo.method); } }); - AnnotationUtil.findDelegateSegments(interf, new HashSet>(), (method) -> { + AnnotationUtil.findDelegateSegments(interf, new HashSet<>(), method -> { Object delegateProxy = ServiceEndpoints.toServiceObject(delegate, method.getReturnType()); - DelegateInfo info = new DelegateInfo(); + final var info = new DelegateInfo(); info.delegate = delegateProxy; info.method = method; if (delegatedSegments.put(method.getName(), info) != null) { @@ -121,7 +121,7 @@ protected Object getParams(Object[] args, MethodInfo methodInfo) { } return Arrays.asList(args); } - + @Override public String toString() { return getClass().getSimpleName() + " for " + delegate.toString(); diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java index 8cfa43d0..efb3b8c0 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/GenericEndpoint.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016, 2024 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.services; @@ -36,7 +36,7 @@ * {@link JsonRequest} methods of one or more given delegate objects. */ public class GenericEndpoint implements Endpoint { - + private static final Logger LOG = Logger.getLogger(GenericEndpoint.class.getName()); private static final Object[] NO_ARGUMENTS = {}; @@ -47,7 +47,7 @@ public GenericEndpoint(Object delegate) { this.delegates = Collections.singletonList(delegate); recursiveFindRpcMethods(delegate, new HashSet<>(), new HashSet<>()); } - + public GenericEndpoint(Collection delegates) { this.delegates = new ArrayList<>(delegates); for (Object delegate : this.delegates) { @@ -56,9 +56,9 @@ public GenericEndpoint(Collection delegates) { } protected void recursiveFindRpcMethods(Object current, Set> visited, Set> visitedForDelegate) { - AnnotationUtil.findRpcMethods(current.getClass(), visited, (methodInfo) -> { + AnnotationUtil.findRpcMethods(current.getClass(), visited, methodInfo -> { @SuppressWarnings("unchecked") - Function> handler = (arg) -> { + Function> handler = arg -> { Method method = methodInfo.method; Object[] arguments = this.getArguments(method, arg); try { @@ -79,7 +79,7 @@ protected void recursiveFindRpcMethods(Object current, Set> visited, Se throw new IllegalStateException("Multiple methods for name " + methodInfo.name); } }); - AnnotationUtil.findDelegateSegments(current.getClass(), visitedForDelegate, (method) -> { + AnnotationUtil.findDelegateSegments(current.getClass(), visitedForDelegate, method -> { try { Object delegate = method.invoke(current); if (delegate != null) { @@ -92,7 +92,7 @@ protected void recursiveFindRpcMethods(Object current, Set> visited, Se } }); } - + protected Object[] getArguments(Method method, Object arg) { int parameterCount = method.getParameterCount(); if (parameterCount == 0) { @@ -102,8 +102,8 @@ protected Object[] getArguments(Method method, Object arg) { return NO_ARGUMENTS; } if (arg instanceof List) { - List arguments = (List) arg; - int argumentCount = arguments.size(); + final var arguments = (List) arg; + int argumentCount = arguments.size(); if (argumentCount == parameterCount) { return arguments.toArray(); } @@ -127,9 +127,9 @@ public CompletableFuture request(String method, Object parameter) { if (handler != null) { return handler.apply(parameter); } - + // Ask the delegate objects whether they can handle the request generically - List> futures = new ArrayList<>(delegates.size()); + final var futures = new ArrayList>(delegates.size()); for (Object delegate : delegates) { if (delegate instanceof Endpoint) { futures.add(((Endpoint) delegate).request(method, parameter)); @@ -138,7 +138,7 @@ public CompletableFuture request(String method, Object parameter) { if (!futures.isEmpty()) { return CompletableFuture.anyOf(futures.toArray(new CompletableFuture[futures.size()])); } - + // Create a log message about the unsupported method String message = "Unsupported request method: " + method; if (isOptionalMethod(method)) { @@ -146,7 +146,7 @@ public CompletableFuture request(String method, Object parameter) { return CompletableFuture.completedFuture(null); } LOG.log(Level.WARNING, message); - CompletableFuture exceptionalResult = new CompletableFuture(); + final var exceptionalResult = new CompletableFuture<>(); ResponseError error = new ResponseError(ResponseErrorCode.MethodNotFound, message, null); exceptionalResult.completeExceptionally(new ResponseErrorException(error)); return exceptionalResult; @@ -160,7 +160,7 @@ public void notify(String method, Object parameter) { handler.apply(parameter); return; } - + // Ask the delegate objects whether they can handle the notification generically int notifiedDelegates = 0; for (Object delegate : delegates) { @@ -169,7 +169,7 @@ public void notify(String method, Object parameter) { notifiedDelegates++; } } - + if (notifiedDelegates == 0) { // Create a log message about the unsupported method String message = "Unsupported notification method: " + method; @@ -180,7 +180,7 @@ public void notify(String method, Object parameter) { } } } - + protected boolean isOptionalMethod(String method) { return method != null && method.startsWith("$/"); } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/ServiceEndpoints.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/ServiceEndpoints.java index 0d67dda9..ef6a041d 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/ServiceEndpoints.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/services/ServiceEndpoints.java @@ -86,8 +86,8 @@ public static Map getSupportedMethods(Class type) { * Finds all Json RPC methods on a given type */ private static Map getSupportedMethods(Class type, Set> visitedTypes) { - Map result = new LinkedHashMap(); - AnnotationUtil.findRpcMethods(type, visitedTypes, (methodInfo) -> { + Map result = new LinkedHashMap<>(); + AnnotationUtil.findRpcMethods(type, visitedTypes, methodInfo -> { JsonRpcMethod meth; if (methodInfo.isNotification) { meth = JsonRpcMethod.notification(methodInfo.name, methodInfo.parameterTypes); @@ -111,15 +111,15 @@ private static Map getSupportedMethods(Class type, Set } if (result.put(methodInfo.name, meth) != null) { throw new IllegalStateException("Duplicate RPC method "+methodInfo.name+"."); - }; + } }); - AnnotationUtil.findDelegateSegments(type, new HashSet<>(), (method)-> { + AnnotationUtil.findDelegateSegments(type, new HashSet<>(), method -> { Map supportedDelegateMethods = getSupportedMethods(method.getReturnType(), visitedTypes); for (JsonRpcMethod meth : supportedDelegateMethods.values()) { if (result.put(meth.getMethodName(), meth) != null) { throw new IllegalStateException("Duplicate RPC method "+meth.getMethodName()+"."); - }; + } } }); return result; diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/ToStringBuilder.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/ToStringBuilder.java index 02252840..7bf3e770 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/ToStringBuilder.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/util/ToStringBuilder.java @@ -25,19 +25,19 @@ *

The builder will automatically handle cycles in the object tree. It also pretty prints arrays and Iterables.

* * This class is not thread safe. - * + * * @implNote This class originally came from xbase.lib and has been extended for LSP4J purposes with some additional functionality. */ public final class ToStringBuilder { - + public static class ToStringContext { public final static ToStringContext INSTANCE = new ToStringContext(); - private final static ThreadLocal> currentlyProcessed = new ThreadLocal>() { + private final static ThreadLocal> currentlyProcessed = new ThreadLocal<>() { @Override public IdentityHashMap initialValue() { - return new IdentityHashMap(); + return new IdentityHashMap<>(); } }; @@ -49,9 +49,9 @@ public void endProcessing(final Object obj) { ToStringContext.currentlyProcessed.get().remove(obj); } } - + private static ToStringContext toStringContext = ToStringContext.INSTANCE; - + private final Object instance; private final String typeName; @@ -64,7 +64,7 @@ public void endProcessing(final Object obj) { private boolean prettyPrint = true; - private final List parts = new ArrayList(); + private final List parts = new ArrayList<>(); /** * Creates a new ToStringBuilder for the given object. If you don't use reflection, then this instance @@ -197,7 +197,7 @@ private ToStringBuilder addField(final Field field) { } return this; } - + @SuppressWarnings("unchecked") private static void sneakyThrow(Throwable t) throws T { throw (T) t; @@ -249,7 +249,7 @@ public String toString() { return this.toSimpleReferenceString(this.instance); } try { - final IndentationAwareStringBuilder builder = new IndentationAwareStringBuilder(); + final var builder = new IndentationAwareStringBuilder(); builder.append(typeName).append(" "); builder.append("["); String nextSeparator = ""; @@ -345,12 +345,12 @@ private String toSimpleReferenceString(final Object obj) { } private List getAllDeclaredFields(final Class clazz) { - final ArrayList result = new ArrayList<>(); + final var result = new ArrayList(); for(Class current = clazz; current != null; current = current.getSuperclass()) { Field[] declaredFields = current.getDeclaredFields(); result.addAll(Arrays.asList(declaredFields)); - + } return result; } @@ -402,9 +402,9 @@ public IndentationAwareStringBuilder newLine() { public String toString() { return this.builder.toString(); } - + private String repeat(String string, int count) { - StringBuilder result = new StringBuilder(); + final var result = new StringBuilder(); for(int i=0; i < count; i++) { result.append(string); } diff --git a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/validation/ReflectiveMessageValidator.java b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/validation/ReflectiveMessageValidator.java index 965c8113..8f235583 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/validation/ReflectiveMessageValidator.java +++ b/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/validation/ReflectiveMessageValidator.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.validation; @@ -15,6 +15,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Deque; import java.util.Iterator; import java.util.LinkedList; @@ -42,7 +43,7 @@ public class ReflectiveMessageValidator implements MessageConsumer { private static final Logger LOG = Logger.getLogger(ReflectiveMessageValidator.class.getName()); private final MessageConsumer delegate; - + /** * When created with this constructor, the validator acts as a message sink. */ @@ -62,13 +63,13 @@ public void consume(Message message) throws MessageIssueException, JsonRpcExcept List issues = validate(message); if (!issues.isEmpty()) { // Sort the messages in order to get a stable order (otherwise it depends on the JVM's reflection implementation) - Collections.sort(issues, (issue1, issue2) -> issue1.getText().compareTo(issue2.getText())); + Collections.sort(issues, Comparator.comparing(MessageIssue::getText)); throw new MessageIssueException(message, issues); } else if (delegate != null) { delegate.consume(message); } } - + /** * Check whether the given object is valid. If it is not valid, its issues are not reported. */ @@ -76,9 +77,9 @@ public boolean isValid(Object object) { List issues = validate(object); return issues.isEmpty(); } - + protected List validate(Object object) { - List result = new ArrayList<>(); + final var result = new ArrayList(); try { validate(object, result, new LinkedList<>(), new LinkedList<>()); } catch (Exception e) { @@ -88,14 +89,14 @@ protected List validate(Object object) { } return result; } - + /** * Validate all fields of the given object. */ protected void validate(Object object, List issues, Deque objectStack, Deque accessorStack) throws Exception { - if (object == null - || object instanceof Enum - || object instanceof String + if (object == null + || object instanceof Enum + || object instanceof String || object instanceof Number || object instanceof Boolean || object instanceof JsonElement @@ -123,7 +124,7 @@ protected void validate(Object object, List issues, Deque accessorStack.pop(); } } else if (object instanceof Either) { - Either either = (Either) object; + final var either = (Either) object; if (either.isLeft()) { validate(either.getLeft(), issues, objectStack, accessorStack); } else if (either.isRight()) { @@ -151,9 +152,9 @@ protected void validate(Object object, List issues, Deque } objectStack.pop(); } - + protected String createPathString(Deque accessorStack) { - StringBuilder result = new StringBuilder("$"); + final var result = new StringBuilder("$"); Iterator resultIter = accessorStack.descendingIterator(); while(resultIter.hasNext()) { Object accessor = resultIter.next(); @@ -173,13 +174,12 @@ protected boolean isGetter(Method method) { && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()); } - + protected String getPropertyName(Method method) { String methodName = method.getName(); if (methodName.startsWith("get") && methodName.length() > 3) return methodName.substring(3, 4).toLowerCase() + methodName.substring(4); - else - return methodName; + return methodName; } - + } diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/ExtendableConcurrentMessageProcessorTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/ExtendableConcurrentMessageProcessorTest.java index fdfd6b15..2de4753e 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/ExtendableConcurrentMessageProcessorTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/ExtendableConcurrentMessageProcessorTest.java @@ -92,11 +92,11 @@ static Launcher createLauncher(Builder builder, Object localService, C * The custom builder to be used when creating a launcher */ static Builder createBuilder(MessageContextStore store) { - return new Builder() { + return new Builder<>() { @Override protected ConcurrentMessageProcessor createMessageProcessor(MessageProducer reader, MessageConsumer messageConsumer, T remoteProxy) { - return new CustomConcurrentMessageProcessor(reader, messageConsumer, remoteProxy, store); + return new CustomConcurrentMessageProcessor<>(reader, messageConsumer, remoteProxy, store); } }; } @@ -107,7 +107,7 @@ protected ConcurrentMessageProcessor createMessageProcessor(MessageProducer read */ public static class CustomConcurrentMessageProcessor extends ConcurrentMessageProcessor { - private T remoteProxy; + private final T remoteProxy; private final MessageContextStore threadMap; public CustomConcurrentMessageProcessor(MessageProducer reader, MessageConsumer messageConsumer, T remoteProxy, MessageContextStore threadMap) { @@ -116,13 +116,15 @@ public CustomConcurrentMessageProcessor(MessageProducer reader, MessageConsumer this.threadMap = threadMap; } + @Override protected void processingStarted() { super.processingStarted(); if (threadMap != null) { - threadMap.setContext(new MessageContext(remoteProxy)); + threadMap.setContext(new MessageContext<>(remoteProxy)); } } + @Override protected void processingEnded() { super.processingEnded(); if (threadMap != null) @@ -135,12 +137,12 @@ protected void processingEnded() { * Server and client interfaces are below, along with any parameters required */ - public static interface MyServer { + public interface MyServer { @JsonRequest CompletableFuture askServer(MyParam param); } - public static interface MyClient { + public interface MyClient { @JsonRequest CompletableFuture askClient(MyParam param); } @@ -194,7 +196,7 @@ public CompletableFuture askServer(MyParam param) { TestContextWrapper.setError(false); return CompletableFuture.completedFuture(param); } - }; + } public static class MyClientImpl implements MyClient { @@ -202,14 +204,14 @@ public static class MyClientImpl implements MyClient { public CompletableFuture askClient(MyParam param) { return CompletableFuture.completedFuture(param); } - }; + } /* * A custom class for storing the context for any given message */ public static class MessageContextStore { - private ThreadLocal> messageContext = new ThreadLocal<>(); + private final ThreadLocal> messageContext = new ThreadLocal<>(); public void setContext(MessageContext context) { messageContext.set(context); @@ -246,7 +248,7 @@ public MessageContext(T remoteProxy) { public T getRemoteProxy() { return this.remoteProxy; } - }; + } } /* diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/IntegrationTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/IntegrationTest.java index 7bcd8823..b164fef1 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/IntegrationTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/IntegrationTest.java @@ -100,12 +100,12 @@ public void setPath(Path path) { } } - public static interface MyServer { + public interface MyServer { @JsonRequest CompletableFuture askServer(MyParam param); } - public static interface MyVoidServer { + public interface MyVoidServer { @JsonRequest CompletableFuture askServer(MyParam param); } @@ -115,9 +115,9 @@ public static class MyServerImpl implements MyServer { public CompletableFuture askServer(MyParam param) { return CompletableFuture.completedFuture(param); } - }; + } - public static interface MyClient { + public interface MyClient { @JsonRequest CompletableFuture askClient(MyParam param); } @@ -127,7 +127,7 @@ public static class MyClientImpl implements MyClient { public CompletableFuture askClient(MyParam param) { return CompletableFuture.completedFuture(param); } - }; + } @Test public void testBothDirectionRequests() throws Exception { @@ -634,7 +634,7 @@ public void testUnknownOptionalMessages() throws Exception { } } - public static interface UnexpectedParamsTestServer { + public interface UnexpectedParamsTestServer { @JsonNotification void myNotification(); } @@ -657,6 +657,7 @@ public void testUnexpectedParams() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); UnexpectedParamsTestServer server = new UnexpectedParamsTestServer() { + @Override public void myNotification() { } }; diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/LauncherTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/LauncherTest.java index c7d9924a..7279fd35 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/LauncherTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/LauncherTest.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.test; @@ -34,9 +34,9 @@ import com.google.gson.stream.JsonWriter; public class LauncherTest { - + private static final long TIMEOUT = 2000; - + static class Param { Param() { } @@ -45,15 +45,13 @@ static class Param { } public String message; } - - static interface A { - @JsonNotification - public void say(Param p); + + interface A { + @JsonNotification void say(Param p); } - - static interface B { - @JsonRequest - public CompletableFuture ask(Param p); + + interface B { + @JsonRequest CompletableFuture ask(Param p); } @Test public void testDone() throws Exception { @@ -68,7 +66,7 @@ public void say(Param p) { Assert.assertTrue(startListening.isDone()); Assert.assertFalse(startListening.isCancelled()); } - + @Test public void testCanceled() throws Exception { A a = new A() { @Override @@ -91,15 +89,15 @@ public int read() throws IOException { Assert.assertTrue(startListening.isDone()); Assert.assertTrue(startListening.isCancelled()); } - + @Test public void testCustomGson() throws Exception { A a = new A() { @Override public void say(Param p) { } }; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - TypeAdapter typeAdapter = new TypeAdapter() { + final var out = new ByteArrayOutputStream(); + final var typeAdapter = new TypeAdapter() { @Override public void write(JsonWriter out, Param value) throws IOException { out.beginObject(); @@ -116,13 +114,13 @@ public Param read(JsonReader in) throws IOException { Executors.newCachedThreadPool(), c -> c, gsonBuilder -> {gsonBuilder.registerTypeAdapter(Param.class, typeAdapter);}); A remoteProxy = launcher.getRemoteProxy(); - + remoteProxy.say(new Param("foo")); Assert.assertEquals("Content-Length: 59\r\n\r\n" + "{\"jsonrpc\":\"2.0\",\"method\":\"say\",\"params\":{\"message\":\"bar\"}}", out.toString()); } - + @Test public void testMultipleServices() throws Exception { final String[] paramA = new String[1]; A a = new A() { @@ -145,19 +143,19 @@ public CompletableFuture ask(Param p) { + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"ask\",\"params\":{\"message\":\"bar1\"}}"; ByteArrayInputStream in = new ByteArrayInputStream(inputMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); - + ClassLoader classLoader = getClass().getClassLoader(); Launcher launcher = Launcher.createIoLauncher(Arrays.asList(a, b), Arrays.asList(A.class, B.class), classLoader, in, out, Executors.newCachedThreadPool(), c -> c, null); - + launcher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); assertEquals("foo1", paramA[0]); assertEquals("bar1", paramB[0]); - + Object remoteProxy = launcher.getRemoteProxy(); ((A) remoteProxy).say(new Param("foo2")); ((B) remoteProxy).ask(new Param("bar2")); - Assert.assertEquals("Content-Length: 47\r\n\r\n" + Assert.assertEquals("Content-Length: 47\r\n\r\n" + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":\"echo bar1\"}" + "Content-Length: 60\r\n\r\n" + "{\"jsonrpc\":\"2.0\",\"method\":\"say\",\"params\":{\"message\":\"foo2\"}}" @@ -165,5 +163,5 @@ public CompletableFuture ask(Param p) { + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"ask\",\"params\":{\"message\":\"bar2\"}}", out.toString()); } - + } diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/RemoteEndpointTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/RemoteEndpointTest.java index 8218d219..4f30368d 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/RemoteEndpointTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/RemoteEndpointTest.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2016, 2024 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.jsonrpc.test; @@ -47,78 +47,79 @@ import org.junit.Test; public class RemoteEndpointTest { - + private static final long TIMEOUT = 2000; - + static class TestEndpoint implements Endpoint { - + List notifications = new ArrayList<>(); Map> requests = new LinkedHashMap<>(); - + + @Override public void notify(String method, Object parameter) { notifications.add(init(new NotificationMessage(), it -> { it.setMethod(method); it.setParams(parameter); })); } - + @Override public CompletableFuture request(String method, Object parameter) { - CompletableFuture completableFuture = new CompletableFuture(); + final var completableFuture = new CompletableFuture<>(); requests.put(init(new RequestMessage(), it -> { it.setMethod(method); it.setParams(parameter); }), completableFuture); return completableFuture; } - + } - + static class TestMessageConsumer implements MessageConsumer { - + List messages = new ArrayList<>(); @Override public void consume(Message message) { messages.add(message); } - + } - + static T init(T value, Consumer initializer) { initializer.accept(value); return value; } - + @Test public void testNotification() { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.consume(init(new NotificationMessage(), it -> { it.setMethod("foo"); it.setParams("myparam"); })); - + NotificationMessage notificationMessage = endp.notifications.get(0); assertEquals("foo", notificationMessage.getMethod()); assertEquals("myparam", notificationMessage.getParams()); assertTrue(consumer.messages.isEmpty()); } - + @Test public void testRequest1() { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); - + Entry> entry = endp.requests.entrySet().iterator().next(); entry.getValue().complete("success"); assertEquals("foo", entry.getKey().getMethod()); @@ -127,19 +128,19 @@ public void testRequest1() { assertEquals("success", responseMessage.getResult()); assertEquals(Either.forLeft("1"), responseMessage.getRawId()); } - + @Test public void testRequest2() { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.consume(init(new RequestMessage(), it -> { it.setId(1); it.setMethod("foo"); it.setParams("myparam"); })); - + Entry> entry = endp.requests.entrySet().iterator().next(); entry.getValue().complete("success"); assertEquals("foo", entry.getKey().getMethod()); @@ -148,36 +149,36 @@ public void testRequest2() { assertEquals("success", responseMessage.getResult()); assertEquals(Either.forRight(1), responseMessage.getRawId()); } - + @Test public void testHandleRequestIssues() { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.handle(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); }), Collections.singletonList(new MessageIssue("bar"))); - + ResponseMessage responseMessage = (ResponseMessage) consumer.messages.get(0); assertNotNull(responseMessage.getError()); assertEquals("bar", responseMessage.getError().getMessage()); } - + @Test public void testCancellation() { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); - + Entry> entry = endp.requests.entrySet().iterator().next(); entry.getValue().cancel(true); ResponseMessage message = (ResponseMessage) consumer.messages.get(0); @@ -187,29 +188,29 @@ public void testCancellation() { assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue()); assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled"); } - + @Test public void testExceptionInEndpoint() { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); - - TestEndpoint endp = new TestEndpoint() { + + final var endp = new TestEndpoint() { @Override public CompletableFuture request(String method, Object parameter) { throw new RuntimeException("BAAZ"); } }; - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); - + ResponseMessage response = (ResponseMessage) consumer.messages.get(0); assertEquals("Internal error.", response.getError().getMessage()); assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); @@ -223,7 +224,7 @@ public CompletableFuture request(String method, Object parameter) { @Test public void testResponseErrorExceptionInEndpoint() { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); @@ -234,8 +235,8 @@ public CompletableFuture request(String method, Object parameter) { throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidParams, "Direct Throw", "data")); } }; - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); @@ -255,7 +256,7 @@ public CompletableFuture request(String method, Object parameter) { @Test public void testResponseErrorExceptionFromFutureInEndpoint() { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); @@ -269,8 +270,8 @@ public CompletableFuture request(String method, Object parameter) { return future; } }; - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); @@ -278,7 +279,7 @@ public CompletableFuture request(String method, Object parameter) { it.setParams("myparam"); })); - ResponseMessage response = (ResponseMessage) consumer.messages.get(0); + final var response = (ResponseMessage) consumer.messages.get(0); assertEquals("completeExceptionally", response.getError().getMessage()); assertEquals(ResponseErrorCode.InvalidParams.getValue(), response.getError().getCode()); String data = (String) response.getError().getData(); @@ -287,15 +288,15 @@ public CompletableFuture request(String method, Object parameter) { logMessages.unregister(); } } - + @Test public void testExceptionInConsumer() throws Exception { - TestEndpoint endp = new TestEndpoint(); + final var endp = new TestEndpoint(); MessageConsumer consumer = message -> { throw new RuntimeException("BAAZ"); }; - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endpoint = new RemoteEndpoint(consumer, endp); + CompletableFuture future = endpoint.request("foo", "myparam"); future.whenComplete((result, exception) -> { assertNull(result); @@ -309,13 +310,13 @@ public void testExceptionInConsumer() throws Exception { assertEquals("java.lang.RuntimeException: BAAZ", exception.getMessage()); } } - + @Test public void testExceptionInCompletableFuture() throws Exception { - TestEndpoint endp = new TestEndpoint(); - TestMessageConsumer consumer = new TestMessageConsumer(); - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); - + final var endp = new TestEndpoint(); + final var consumer = new TestMessageConsumer(); + final var endpoint = new RemoteEndpoint(consumer, endp); + CompletableFuture future = endpoint.request("foo", "myparam"); CompletableFuture chained = future.thenAccept(result -> { throw new RuntimeException("BAAZ"); @@ -331,45 +332,45 @@ public void testExceptionInCompletableFuture() throws Exception { assertEquals("java.lang.RuntimeException: BAAZ", exception.getMessage()); } } - + @Test public void testExceptionInOutputStream() throws Exception { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(RemoteEndpoint.class); - - TestEndpoint endp = new TestEndpoint(); - MessageConsumer consumer = new MessageConsumer() { + + final var endp = new TestEndpoint(); + final var consumer = new MessageConsumer() { @Override public void consume(Message message) throws JsonRpcException { throw new JsonRpcException(new SocketException("Permission denied: connect")); } }; - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); + final var endpoint = new RemoteEndpoint(consumer, endp); endpoint.notify("foo", null); - + logMessages.await(Level.WARNING, "Failed to send notification message."); } finally { logMessages.unregister(); } } - + @Test public void testOutputStreamClosed() throws Exception { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(RemoteEndpoint.class); - - TestEndpoint endp = new TestEndpoint(); - MessageConsumer consumer = new MessageConsumer() { + + final var endp = new TestEndpoint(); + final var consumer = new MessageConsumer() { @Override public void consume(Message message) throws JsonRpcException { throw new JsonRpcException(new SocketException("Socket closed")); } }; - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); + final var endpoint = new RemoteEndpoint(consumer, endp); endpoint.notify("foo", null); - + logMessages.await(Level.INFO, "Failed to send notification message."); } finally { logMessages.unregister(); @@ -378,20 +379,20 @@ public void consume(Message message) throws JsonRpcException { @Test public void testExceptionHandlerMisbehaving1() { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); - TestEndpoint endp = new TestEndpoint() { + final var endp = new TestEndpoint() { @Override public CompletableFuture request(String method, Object parameter) { throw new RuntimeException("BAAZ"); } }; - TestMessageConsumer consumer = new TestMessageConsumer(); + final var consumer = new TestMessageConsumer(); // Misbehaving exception handler that returns null - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp, (e) -> null); + final var endpoint = new RemoteEndpoint(consumer, endp, e -> null); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); @@ -400,7 +401,7 @@ public CompletableFuture request(String method, Object parameter) { })); assertEquals("Check some response received", 1, consumer.messages.size()); - ResponseMessage response = (ResponseMessage) consumer.messages.get(0); + final var response = (ResponseMessage) consumer.messages.get(0); assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); } finally { logMessages.unregister(); @@ -424,23 +425,23 @@ public void consume(Message message) { } } - + @Test public void testExceptionHandlerMisbehaving2() throws Exception { - LogMessageAccumulator logMessages = new LogMessageAccumulator(); + final var logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); - TestEndpoint endp = new TestEndpoint() { + final var endp = new TestEndpoint() { @Override public CompletableFuture request(String method, Object parameter) { return CompletableFuture.supplyAsync(() -> "baz"); } }; - TestMessageConsumer2 consumer = new TestMessageConsumer2(); + final var consumer = new TestMessageConsumer2(); // Misbehaving exception handler that returns null - RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp, (e) -> null); + final var endpoint = new RemoteEndpoint(consumer, endp, e -> null); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/EndpointsTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/EndpointsTest.java index bf6e8a9f..7c968a24 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/EndpointsTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/EndpointsTest.java @@ -38,39 +38,31 @@ public class EndpointsTest { private static final long TIMEOUT = 2000; @JsonSegment("foo") - public static interface Foo { - @JsonRequest - public CompletableFuture doStuff(String arg); + public interface Foo { + @JsonRequest CompletableFuture doStuff(String arg); - @JsonNotification - public void myNotification(String someArg); + @JsonNotification void myNotification(String someArg); - @JsonDelegate - public Delegated getDelegate(); + @JsonDelegate Delegated getDelegate(); } - public static interface Delegated { + public interface Delegated { - @JsonNotification("hubba") - public void myNotification(String someArg); + @JsonNotification("hubba") void myNotification(String someArg); } @JsonSegment("bar") - public static interface Bar { - @JsonRequest - public CompletableFuture doStuff2(String arg, Integer arg2); + public interface Bar { + @JsonRequest CompletableFuture doStuff2(String arg, Integer arg2); - @JsonNotification - public void myNotification2(String someArg, Integer someArg2); + @JsonNotification void myNotification2(String someArg, Integer someArg2); - @JsonDelegate - public BarDelegated getDelegate2(); + @JsonDelegate BarDelegated getDelegate2(); } - public static interface BarDelegated { + public interface BarDelegated { - @JsonNotification("hubba") - public void myNotification(String someArg, Integer someArg2); + @JsonNotification("hubba") void myNotification(String someArg, Integer someArg2); } @Test public void testProxy_01() throws Exception { @@ -219,7 +211,7 @@ public void notify(String method, Object parameter) { } @JsonSegment("consumer") - public static interface StringConsumer extends Consumer { + public interface StringConsumer extends Consumer { @JsonNotification @Override void accept(String message); diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/impl/GenericEndpointTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/impl/GenericEndpointTest.java index 9fed737e..975cc33c 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/impl/GenericEndpointTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/annotations/impl/GenericEndpointTest.java @@ -74,20 +74,17 @@ public void barrr() { } - public static interface MyIf { + public interface MyIf { - @JsonNotification - public void myNotification(); + @JsonNotification void myNotification(); - @JsonDelegate - public OtherThing doDelegate(); + @JsonDelegate OtherThing doDelegate(); } @JsonSegment("other") - public static interface OtherThing { + public interface OtherThing { - @JsonNotification - public void myNotification(); + @JsonNotification void myNotification(); } @Test diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/EitherTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/EitherTest.java index 6c12780e..2cf69c58 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/EitherTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/EitherTest.java @@ -124,7 +124,7 @@ public void testMap() { @Test public void testMapEither3() { Either3 either3; - Function mapFirst = s -> s.toUpperCase(); + Function mapFirst = String::toUpperCase; Function mapSecond = x -> x.toString(); Function mapThird = b -> b.toString(); diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MessageJsonHandlerTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MessageJsonHandlerTest.java index 38dc5e79..fbb403a1 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MessageJsonHandlerTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MessageJsonHandlerTest.java @@ -60,7 +60,7 @@ public void testParseList_01() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": [\n" @@ -85,7 +85,7 @@ public void testParseList_02() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": [\n" @@ -109,7 +109,7 @@ public void testParseNullList() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": null}"); @@ -124,7 +124,7 @@ public void testParseEmptyList() { new TypeToken>() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id)->"foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": []}"); @@ -176,7 +176,7 @@ public void testMessageToString() { @Override public String format(Object object) { throw new JsonIOException("TEST"); - }; + } }; message.setJsonHandler(handler); Assert.assertEquals("NotificationMessage [\n" @@ -197,7 +197,7 @@ public void testEither_01() { new TypeToken>>>() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + " \"result\": [\n" @@ -224,9 +224,9 @@ public void testEither_02() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"result\": 2\n" @@ -242,9 +242,9 @@ public void testEither_03() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>, List>>>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -296,9 +296,9 @@ public void testEither_04() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -325,9 +325,9 @@ public void testEither_05() { Map supportedMethods = new LinkedHashMap<>(); supportedMethods.put("foo", JsonRpcMethod.request("foo", new TypeToken, MyClassList>>() {}.getType(), - new TypeToken() {}.getType())); + new TypeToken<>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); Message message = handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -356,7 +356,7 @@ public void testParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -373,7 +373,7 @@ public void testParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -390,7 +390,7 @@ public void testParamsParsing_03() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -407,7 +407,7 @@ public void testParamsParsing_04() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -425,7 +425,7 @@ public void testRawMultiParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -448,7 +448,7 @@ public void testRawMultiParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -467,7 +467,7 @@ public void testRawMultiParamsParsing_03() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -492,7 +492,7 @@ public void testRawMultiParamsParsing_04() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -516,7 +516,7 @@ public void testMultiParamsParsing_01() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -539,7 +539,7 @@ public void testMultiParamsParsing_02() { new TypeToken() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -558,7 +558,7 @@ public void testMultiParamsParsing_03() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -583,7 +583,7 @@ public void testMultiParamsParsing_04() { new TypeToken>() {}.getType(), new TypeToken() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" @@ -606,7 +606,7 @@ public void testEnumParam() { new TypeToken() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"params\": [1, 2, 3],\n" @@ -626,7 +626,7 @@ public void testEnumParamNull() { new TypeToken() {}.getType(), new TypeToken>() {}.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\"," + "\"id\":\"2\",\n" + "\"params\": [1, 2, null],\n" @@ -730,7 +730,7 @@ public void testRequest_AllOrders() { new TypeToken() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"id\":2", @@ -754,7 +754,7 @@ public void testNormalResponse_AllOrders() { new TypeToken() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"id\":2", @@ -778,7 +778,7 @@ public void testErrorResponse_AllOrders() { new TypeToken() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"id\":2", @@ -804,7 +804,7 @@ public void testNotification_AllOrders() { new TypeToken() { }.getType())); MessageJsonHandler handler = new MessageJsonHandler(supportedMethods); - handler.setMethodProvider((id) -> "foo"); + handler.setMethodProvider(id -> "foo"); String[] properties = new String[] { "\"jsonrpc\":\"2.0\"", "\"method\":\"foo\"", @@ -985,7 +985,7 @@ public void testUnwrapMultipleParamsWithArray_JsonRpc2_0() { private static MessageJsonHandler createSimpleRequestHandler(Class returnType, Type... paramType) { JsonRpcMethod requestMethod = JsonRpcMethod.request("testMethod", returnType, paramType); MessageJsonHandler handler = new MessageJsonHandler(Map.of(requestMethod.getMethodName(), requestMethod)); - handler.setMethodProvider((id) -> requestMethod.getMethodName()); + handler.setMethodProvider(id -> requestMethod.getMethodName()); return handler; } } diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClass.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClass.java index fa0a6cd0..d6a7ef45 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClass.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClass.java @@ -23,17 +23,20 @@ public void setValue(String value) { this.value = value; } + @Override public String toString() { return "MyClass [value=" + value + "]"; } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); + result = prime * result + (value == null ? 0 : value.hashCode()); return result; } + @Override public boolean equals(Object obj) { if (this == obj) return true; diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClassList.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClassList.java index 718856d0..7009b4c1 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClassList.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/MyClassList.java @@ -26,13 +26,15 @@ public void setItems(List items) { this.items = items; } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((items == null) ? 0 : items.hashCode()); + result = prime * result + (items == null ? 0 : items.hashCode()); return result; } + @Override public boolean equals(Object obj) { if (this == obj) return true; @@ -49,6 +51,7 @@ public boolean equals(Object obj) { return true; } + @Override public String toString() { return "MyClassList [items=" + items + "]"; } diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/ThrowableTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/ThrowableTest.java index 445cf166..addc57b8 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/ThrowableTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/ThrowableTest.java @@ -35,7 +35,7 @@ protected void assertSerialize(Object object, String expected) { protected void assertParse(MyObjectA expected, String string) { Gson gson = createGson(); - MyObjectA actual = (MyObjectA)gson.fromJson(string, expected.getClass()); + MyObjectA actual = gson.fromJson(string, expected.getClass()); Assert.assertEquals(expected.otherProperty, actual.otherProperty); assertEquals(expected.myThrowable, actual.myThrowable); } diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/TypeUtilsTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/TypeUtilsTest.java index b163f078..0430b694 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/TypeUtilsTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/json/TypeUtilsTest.java @@ -43,7 +43,7 @@ public void testCollectionElement2() { assertElementTypes(token, Collection.class, Number.class); } - private static interface MyCollection extends Collection { + private interface MyCollection extends Collection { } @Test diff --git a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/validation/ReflectiveMessageValidatorTest.java b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/validation/ReflectiveMessageValidatorTest.java index 207cfe3b..7c0548e4 100644 --- a/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/validation/ReflectiveMessageValidatorTest.java +++ b/org.eclipse.lsp4j.jsonrpc/src/test/java/org/eclipse/lsp4j/jsonrpc/test/validation/ReflectiveMessageValidatorTest.java @@ -138,7 +138,7 @@ public List getFoos() { @Test public void testSkipJsonElement() { final AtomicBoolean result = new AtomicBoolean(false); - ReflectiveMessageValidator validator = new ReflectiveMessageValidator((message) -> { + ReflectiveMessageValidator validator = new ReflectiveMessageValidator(message -> { result.set(true); }); NotificationMessage message = new NotificationMessage(); diff --git a/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketEndpoint.java b/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketEndpoint.java index e0833cee..eb628e99 100644 --- a/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketEndpoint.java +++ b/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketEndpoint.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2019, 2021 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.websocket.jakarta; @@ -25,27 +25,27 @@ * @param remote service interface type */ public abstract class WebSocketEndpoint extends Endpoint { - + @Override public void onOpen(Session session, EndpointConfig config) { - WebSocketLauncherBuilder builder = new WebSocketLauncherBuilder<>(); + final var builder = new WebSocketLauncherBuilder(); builder.setSession(session); configure(builder); Launcher launcher = builder.create(); connect(builder.getLocalServices(), launcher.getRemoteProxy()); } - + /** * Configure the JSON-RPC launcher. Implementations should set at least the * {@link Launcher.Builder#setLocalService(Object) local service} and the * {@link Launcher.Builder#setRemoteInterface(Class) remote interface}. */ protected abstract void configure(Launcher.Builder builder); - + /** * Override this in order to connect the local services to the remote service proxy. */ protected void connect(Collection localServices, T remoteProxy) { } - + } diff --git a/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketMessageHandler.java b/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketMessageHandler.java index 686987b8..5ed529e5 100644 --- a/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketMessageHandler.java +++ b/org.eclipse.lsp4j.websocket.jakarta/src/main/java/org/eclipse/lsp4j/websocket/jakarta/WebSocketMessageHandler.java @@ -34,6 +34,7 @@ public WebSocketMessageHandler(MessageConsumer callback, MessageJsonHandler json this.issueHandler = issueHandler; } + @Override public void onMessage(String content) { try { Message message = jsonHandler.parseMessage(content); diff --git a/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockConnectionTest.java b/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockConnectionTest.java index 610e61b0..c4be5b4d 100644 --- a/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockConnectionTest.java +++ b/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockConnectionTest.java @@ -110,7 +110,7 @@ private void await(Supplier condition) throws InterruptedException { } } - private static interface ClientInterface { + private interface ClientInterface { @JsonNotification("client/notify") void notify(String arg); @@ -127,7 +127,7 @@ public void notify(String arg) { } } - private static interface ServerInterface { + private interface ServerInterface { @JsonRequest("server/request") CompletableFuture request(String arg); diff --git a/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockSession.java b/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockSession.java index 55e4770b..3f750f78 100644 --- a/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockSession.java +++ b/org.eclipse.lsp4j.websocket.jakarta/src/test/java/org/eclipse/lsp4j/websocket/jakarta/test/MockSession.java @@ -123,7 +123,7 @@ protected void dispatch(String message, boolean lastChunk) { ((MessageHandler.Whole) h).onMessage(wholeMessage); else ((MessageHandler.Partial) h).onMessage(message, true); - }; + } } else { if (partialMessage == null) { partialMessage = new StringBuilder(); @@ -131,7 +131,7 @@ protected void dispatch(String message, boolean lastChunk) { for (MessageHandler h : connectedSession.messageHandlers) { if (h instanceof MessageHandler.Partial) ((MessageHandler.Partial) h).onMessage(message, false); - }; + } partialMessage.append(message); } } diff --git a/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketEndpoint.java b/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketEndpoint.java index 84490a03..cfeb323c 100644 --- a/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketEndpoint.java +++ b/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketEndpoint.java @@ -30,7 +30,7 @@ public abstract class WebSocketEndpoint extends Endpoint { @Override public void onOpen(Session session, EndpointConfig config) { - WebSocketLauncherBuilder builder = new WebSocketLauncherBuilder(); + WebSocketLauncherBuilder builder = new WebSocketLauncherBuilder<>(); builder.setSession(session); configure(builder); Launcher launcher = builder.create(); diff --git a/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketMessageHandler.java b/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketMessageHandler.java index 7d95d999..332e7f66 100644 --- a/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketMessageHandler.java +++ b/org.eclipse.lsp4j.websocket/src/main/java/org/eclipse/lsp4j/websocket/WebSocketMessageHandler.java @@ -36,6 +36,7 @@ public WebSocketMessageHandler(MessageConsumer callback, MessageJsonHandler json this.issueHandler = issueHandler; } + @Override public void onMessage(String content) { try { Message message = jsonHandler.parseMessage(content); diff --git a/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockConnectionTest.java b/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockConnectionTest.java index 289b0195..67b84623 100644 --- a/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockConnectionTest.java +++ b/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockConnectionTest.java @@ -110,7 +110,7 @@ private void await(Supplier condition) throws InterruptedException { } } - private static interface ClientInterface { + private interface ClientInterface { @JsonNotification("client/notify") void notify(String arg); @@ -127,7 +127,7 @@ public void notify(String arg) { } } - private static interface ServerInterface { + private interface ServerInterface { @JsonRequest("server/request") CompletableFuture request(String arg); diff --git a/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockSession.java b/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockSession.java index 6d7039c7..6ec812cb 100644 --- a/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockSession.java +++ b/org.eclipse.lsp4j.websocket/src/test/java/org/eclipse/lsp4j/websocket/test/MockSession.java @@ -110,7 +110,7 @@ protected void dispatch(String message, boolean lastChunk) { ((MessageHandler.Whole) h).onMessage(wholeMessage); else ((MessageHandler.Partial) h).onMessage(message, true); - }; + } } else { if (partialMessage == null) { partialMessage = new StringBuilder(); @@ -118,7 +118,7 @@ protected void dispatch(String message, boolean lastChunk) { for (MessageHandler h : connectedSession.messageHandlers) { if (h instanceof MessageHandler.Partial) ((MessageHandler.Partial) h).onMessage(message, false); - }; + } partialMessage.append(message); } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CodeActionResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CodeActionResponseAdapter.java index aec24522..899cfa85 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CodeActionResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CodeActionResponseAdapter.java @@ -12,7 +12,6 @@ package org.eclipse.lsp4j.adapters; import java.util.ArrayList; -import java.util.function.Predicate; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Command; @@ -22,7 +21,6 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; @@ -31,16 +29,15 @@ public class CodeActionResponseAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("command", JsonPrimitive.class); - Predicate rightChecker = new PropertyChecker("title"); - TypeAdapter> elementTypeAdapter = new EitherTypeAdapter<>(gson, - ELEMENT_TYPE, leftChecker, rightChecker); + final var leftChecker = new PropertyChecker("command", JsonPrimitive.class); + final var rightChecker = new PropertyChecker("title"); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); return (TypeAdapter) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, ArrayList::new); } - + } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java index c1018702..9f8038c1 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java @@ -1,18 +1,16 @@ /****************************************************************************** * Copyright (c) 2022 itemis AG and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; -import java.util.function.Predicate; - import org.eclipse.lsp4j.InsertReplaceRange; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter; @@ -20,20 +18,19 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; public class CompletionItemDefaultsEditRangeTypeAdapter implements TypeAdapterFactory { - private static final TypeToken> ELEMENT_TYPE = new TypeToken>() { + private static final TypeToken> ELEMENT_TYPE = new TypeToken<>() { }; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("start"); - Predicate rightChecker = new PropertyChecker("insert"); + final var leftChecker = new PropertyChecker("start"); + final var rightChecker = new PropertyChecker("insert"); return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); } } \ No newline at end of file diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemTextEditTypeAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemTextEditTypeAdapter.java index 68cc1c5b..627888fb 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemTextEditTypeAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemTextEditTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2020 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ @@ -25,13 +25,13 @@ public class CompletionItemTextEditTypeAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - PropertyChecker leftChecker = new PropertyChecker("range"); - PropertyChecker rightChecker = new PropertyChecker("insert"); + final var leftChecker = new PropertyChecker("range"); + final var rightChecker = new PropertyChecker("insert"); return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java index 68d9474e..3dddc13e 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentChangeListAdapter.java @@ -1,19 +1,18 @@ /****************************************************************************** * Copyright (c) 2018 Microsoft Corporation and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; import java.util.ArrayList; -import java.util.function.Predicate; import org.eclipse.lsp4j.ResourceOperation; import org.eclipse.lsp4j.TextDocumentEdit; @@ -23,23 +22,21 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; public class DocumentChangeListAdapter implements TypeAdapterFactory { - + private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("textDocument").and(new PropertyChecker("edits")); - Predicate rightChecker = new PropertyChecker("kind"); - TypeAdapter> elementTypeAdapter = new EitherTypeAdapter<>(gson, - ELEMENT_TYPE, leftChecker, rightChecker); + final var leftChecker = new PropertyChecker("textDocument").and(new PropertyChecker("edits")); + final var rightChecker = new PropertyChecker("kind"); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); return (TypeAdapter) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, ArrayList::new); } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentDiagnosticReportTypeAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentDiagnosticReportTypeAdapter.java index ff19c4a5..503543ba 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentDiagnosticReportTypeAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentDiagnosticReportTypeAdapter.java @@ -1,18 +1,17 @@ /****************************************************************************** * Copyright (c) 2022 1C-Soft LLC and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; import java.io.IOException; -import java.util.function.Predicate; import org.eclipse.lsp4j.DocumentDiagnosticReport; import org.eclipse.lsp4j.RelatedFullDocumentDiagnosticReport; @@ -21,7 +20,6 @@ import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter.PropertyChecker; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -33,9 +31,9 @@ public class DocumentDiagnosticReportTypeAdapter implements TypeAdapterFactory { @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("kind", "full"); - Predicate rightChecker = new PropertyChecker("kind", "unchanged"); - return (TypeAdapter) new EitherTypeAdapter( + final var leftChecker = new PropertyChecker("kind", "full"); + final var rightChecker = new PropertyChecker("kind", "unchanged"); + return (TypeAdapter) new EitherTypeAdapter<>( gson, ELEMENT_TYPE, leftChecker, rightChecker) { @Override diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentSymbolResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentSymbolResponseAdapter.java index 0a4d7bab..883dd9d0 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentSymbolResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/DocumentSymbolResponseAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2018 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; @@ -26,18 +26,17 @@ import com.google.gson.reflect.TypeToken; public class DocumentSymbolResponseAdapter implements TypeAdapterFactory { - + private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - PropertyChecker leftChecker = new PropertyChecker("location"); - PropertyChecker rightChecker = new PropertyChecker("range"); - TypeAdapter> elementTypeAdapter = new EitherTypeAdapter<>(gson, - ELEMENT_TYPE, leftChecker, rightChecker); + final var leftChecker = new PropertyChecker("location"); + final var rightChecker = new PropertyChecker("range"); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); return (TypeAdapter) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, ArrayList::new); } - + } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/InlineValueResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/InlineValueResponseAdapter.java index edbc36bf..9ae94a2c 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/InlineValueResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/InlineValueResponseAdapter.java @@ -1,18 +1,17 @@ /****************************************************************************** * Copyright (c) 2023 1C-Soft LLC and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; import java.util.ArrayList; -import java.util.function.Predicate; import org.eclipse.lsp4j.InlineValueEvaluatableExpression; import org.eclipse.lsp4j.InlineValueText; @@ -24,7 +23,6 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either3; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -32,19 +30,18 @@ public class InlineValueResponseAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; private static final TypeToken> R_ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate firstChecker = new PropertyChecker("text"); - Predicate secondChecker = new PropertyChecker("caseSensitiveLookup"); - Predicate thirdChecker = new PropertyChecker("range"); - EitherTypeAdapter> elementTypeAdapter = - new EitherTypeAdapter<>(gson, ELEMENT_TYPE, firstChecker, secondChecker.or(thirdChecker), + final var firstChecker = new PropertyChecker("text"); + final var secondChecker = new PropertyChecker("caseSensitiveLookup"); + final var thirdChecker = new PropertyChecker("range"); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, firstChecker, secondChecker.or(thirdChecker), null, new EitherTypeAdapter<>(gson, R_ELEMENT_TYPE, secondChecker, thirdChecker)); return (TypeAdapter) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, ArrayList::new); } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/LocationLinkListAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/LocationLinkListAdapter.java index 50ac6505..55fb0c6b 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/LocationLinkListAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/LocationLinkListAdapter.java @@ -15,15 +15,15 @@ import com.google.gson.reflect.TypeToken; public class LocationLinkListAdapter implements TypeAdapterFactory { - + private static final TypeToken, List>> EITHER_TYPE - = new TypeToken, List>>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - ListChecker leftChecker = new ListChecker(new PropertyChecker("uri"), true); - ListChecker rightChecker = new ListChecker(new PropertyChecker("targetUri"), false); + final var leftChecker = new ListChecker(new PropertyChecker("uri"), true); + final var rightChecker = new ListChecker(new PropertyChecker("targetUri"), false); return (TypeAdapter) new EitherTypeAdapter<>(gson, EITHER_TYPE, leftChecker, rightChecker); } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java index 89eb316a..8d67f37d 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.java @@ -1,18 +1,16 @@ /****************************************************************************** * Copyright (c) 2018-2019 Microsoft Corporation and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; -import java.util.function.Predicate; - import org.eclipse.lsp4j.PrepareRenameDefaultBehavior; import org.eclipse.lsp4j.PrepareRenameResult; import org.eclipse.lsp4j.Range; @@ -22,25 +20,24 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either3; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; public class PrepareRenameResponseAdapter implements TypeAdapterFactory { - + private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; private static final TypeToken> R_ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate firstChecker = new PropertyChecker("start"); - Predicate secondChecker = new PropertyChecker("range"); - Predicate thirdChecker = new PropertyChecker("defaultBehavior"); + final var firstChecker = new PropertyChecker("start"); + final var secondChecker = new PropertyChecker("range"); + final var thirdChecker = new PropertyChecker("defaultBehavior"); return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, firstChecker, secondChecker.or(thirdChecker), null, new EitherTypeAdapter<>(gson, R_ELEMENT_TYPE, secondChecker, thirdChecker)); } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ProgressNotificationAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ProgressNotificationAdapter.java index 64a4f6f4..e49b170e 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ProgressNotificationAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/ProgressNotificationAdapter.java @@ -25,7 +25,7 @@ public class ProgressNotificationAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/SemanticTokensFullDeltaResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/SemanticTokensFullDeltaResponseAdapter.java index 4850a86f..ef5129a6 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/SemanticTokensFullDeltaResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/SemanticTokensFullDeltaResponseAdapter.java @@ -11,10 +11,7 @@ ******************************************************************************/ package org.eclipse.lsp4j.adapters; -import java.util.function.Predicate; - import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -27,14 +24,14 @@ public class SemanticTokensFullDeltaResponseAdapter implements TypeAdapterFactory { - private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + private static final TypeToken> ELEMENT_TYPE + = new TypeToken<>() {}; - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("data"); - Predicate rightChecker = new PropertyChecker("edits"); - return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); - } + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + final var leftChecker = new PropertyChecker("data"); + final var rightChecker = new PropertyChecker("edits"); + return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); + } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkDoneProgressNotificationAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkDoneProgressNotificationAdapter.java index 44ac0dd4..e66a2aad 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkDoneProgressNotificationAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkDoneProgressNotificationAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2020 TypeFox and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; @@ -59,13 +59,13 @@ public WorkDoneProgressNotification read(JsonReader in) throws IOException { in.nextNull(); return null; } - + in.beginObject(); String kind = null, message = null, title = null; Boolean cancellable = null; Integer percentage = null; try { - + while (in.hasNext()) { String name = in.nextName(); switch (name) { @@ -95,13 +95,12 @@ public WorkDoneProgressNotification read(JsonReader in) throws IOException { } in.endObject(); return createNotification(kind, message, title, cancellable, percentage); - + } catch (JsonSyntaxException | MalformedJsonException | EOFException exception) { if (kind != null) { throw new JsonParseException(exception); - } else { - throw exception; } + throw exception; } } @@ -112,20 +111,20 @@ private WorkDoneProgressNotification createNotification(String kind, String mess } switch (kind) { case "begin": - WorkDoneProgressBegin begin = new WorkDoneProgressBegin(); + final var begin = new WorkDoneProgressBegin(); begin.setMessage(message); begin.setCancellable(cancellable); begin.setPercentage(percentage); begin.setTitle(title); return begin; case "report": - WorkDoneProgressReport report = new WorkDoneProgressReport(); + final var report = new WorkDoneProgressReport(); report.setMessage(message); report.setCancellable(cancellable); report.setPercentage(percentage); return report; case "end": - WorkDoneProgressEnd end = new WorkDoneProgressEnd(); + final var end = new WorkDoneProgressEnd(); end.setMessage(message); return end; default: @@ -139,10 +138,10 @@ public void write(JsonWriter out, WorkDoneProgressNotification notification) thr out.name("kind"); WorkDoneProgressKind kind = notification.getKind(); out.value(kind.toString()); - + switch (kind) { case begin: - WorkDoneProgressBegin begin = (WorkDoneProgressBegin) notification; + final var begin = (WorkDoneProgressBegin) notification; out.name("title"); out.value(begin.getTitle()); out.name("cancellable"); @@ -153,7 +152,7 @@ public void write(JsonWriter out, WorkDoneProgressNotification notification) thr out.value(begin.getPercentage()); break; case report: - WorkDoneProgressReport report = (WorkDoneProgressReport) notification; + final var report = (WorkDoneProgressReport) notification; out.name("cancellable"); out.value(report.getCancellable()); out.name("message"); @@ -162,7 +161,7 @@ public void write(JsonWriter out, WorkDoneProgressNotification notification) thr out.value(report.getPercentage()); break; case end: - WorkDoneProgressEnd end = (WorkDoneProgressEnd) notification; + final var end = (WorkDoneProgressEnd) notification; out.name("message"); out.value(end.getMessage()); break; diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceDocumentDiagnosticReportListAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceDocumentDiagnosticReportListAdapter.java index 2a1be3d3..31fab550 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceDocumentDiagnosticReportListAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceDocumentDiagnosticReportListAdapter.java @@ -1,19 +1,18 @@ /****************************************************************************** * Copyright (c) 2022 1C-Soft LLC and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; import java.io.IOException; import java.util.ArrayList; -import java.util.function.Predicate; import org.eclipse.lsp4j.WorkspaceDocumentDiagnosticReport; import org.eclipse.lsp4j.WorkspaceFullDocumentDiagnosticReport; @@ -23,7 +22,6 @@ import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter.PropertyChecker; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; @@ -35,11 +33,9 @@ public class WorkspaceDocumentDiagnosticReportListAdapter implements TypeAdapter @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - Predicate leftChecker = new PropertyChecker("kind", "full"); - Predicate rightChecker = new PropertyChecker("kind", "unchanged"); - EitherTypeAdapter elementTypeAdapter = - new EitherTypeAdapter( - gson, ELEMENT_TYPE, leftChecker, rightChecker) { + final var leftChecker = new PropertyChecker("kind", "full"); + final var rightChecker = new PropertyChecker("kind", "unchanged"); + final var elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker) { @Override protected WorkspaceDocumentDiagnosticReport createLeft(WorkspaceFullDocumentDiagnosticReport obj) throws IOException { return new WorkspaceDocumentDiagnosticReport(obj); diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolLocationTypeAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolLocationTypeAdapter.java index 30c26e20..05e25e2f 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolLocationTypeAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolLocationTypeAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2022 KamasamaK and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ @@ -25,13 +25,13 @@ public class WorkspaceSymbolLocationTypeAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE - = new TypeToken>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - PropertyChecker leftChecker = new PropertyChecker("range"); - PropertyChecker rightChecker = new PropertyChecker("uri"); + final var leftChecker = new PropertyChecker("range"); + final var rightChecker = new PropertyChecker("uri"); return (TypeAdapter) new EitherTypeAdapter<>(gson, ELEMENT_TYPE, leftChecker, rightChecker); } } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolResponseAdapter.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolResponseAdapter.java index c6a7697a..330d538e 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolResponseAdapter.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/WorkspaceSymbolResponseAdapter.java @@ -1,12 +1,12 @@ /****************************************************************************** * Copyright (c) 2022 KamasamaK and others. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0, * or the Eclipse Distribution License v. 1.0 which is available at * http://www.eclipse.org/org/documents/edl-v10.php. - * + * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ package org.eclipse.lsp4j.adapters; @@ -28,14 +28,14 @@ public class WorkspaceSymbolResponseAdapter implements TypeAdapterFactory { private static final TypeToken, List>> EITHER_TYPE - = new TypeToken, List>>() {}; + = new TypeToken<>() {}; @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { - ListChecker leftChecker = new ListChecker(new PropertyChecker("deprecated"), false); - ListChecker rightChecker = new ListChecker(new PropertyChecker("name"), true); + final var leftChecker = new ListChecker(new PropertyChecker("deprecated"), false); + final var rightChecker = new ListChecker(new PropertyChecker("name"), true); return (TypeAdapter) new EitherTypeAdapter<>(gson, EITHER_TYPE, leftChecker, rightChecker); } - + } diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java index 30b16397..7aeaa122 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/DocumentSymbols.java @@ -51,7 +51,7 @@ protected Iterable getChildren(DocumentSymbol node) { protected abstract static class BreadthFirstIterator implements Iterator { - private Queue queue; + private final Queue queue; protected BreadthFirstIterator(T root) { Preconditions.checkNotNull(root, "root"); diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java index 246d72f8..640ce4aa 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/util/Ranges.java @@ -37,8 +37,8 @@ public static boolean containsRange(Range bigger, Range smaller) { public static boolean containsPosition(Range range, Position position) { Preconditions.checkNotNull(range, "range"); Preconditions.checkNotNull(position, "position"); - return (range.getStart().equals(position) || Positions.isBefore(range.getStart(), position) - && (range.getEnd().equals(position) || Positions.isBefore(position, range.getEnd()))); + return range.getStart().equals(position) || Positions.isBefore(range.getStart(), position) + && (range.getEnd().equals(position) || Positions.isBefore(position, range.getEnd())); } private Ranges() { diff --git a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/NullResponseTest.java b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/NullResponseTest.java index 9075faff..bf854fa6 100644 --- a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/NullResponseTest.java +++ b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/NullResponseTest.java @@ -50,7 +50,7 @@ public void testNullResponse() throws InterruptedException, ExecutionException { Map methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class); MessageJsonHandler handler = new MessageJsonHandler(methods); List msgs = new ArrayList<>(); - MessageConsumer consumer = (message) -> { + MessageConsumer consumer = message -> { msgs.add(message); }; RemoteEndpoint re = new RemoteEndpoint(consumer, endpoint); diff --git a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/ProtocolTest.java b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/ProtocolTest.java index de69b861..4e5b99cb 100644 --- a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/ProtocolTest.java +++ b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/ProtocolTest.java @@ -39,9 +39,7 @@ public class ProtocolTest { LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() { @Override public CompletableFuture> documentLink(DocumentLinkParams params) { - return CompletableFutures.computeAsync(canceler -> { - return new ArrayList<>(); - }); + return CompletableFutures.computeAsync(canceler -> new ArrayList<>()); } }); @@ -55,9 +53,7 @@ public CompletableFuture> documentLink(DocumentLinkParams par LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() { @Override public CompletableFuture> documentLink(DocumentLinkParams params) { - return CompletableFutures.computeAsync(canceler -> { - return null; - }); + return CompletableFutures.computeAsync(canceler -> null); } }); diff --git a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/util/DocumentSymbolsTest.java b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/util/DocumentSymbolsTest.java index 33addfc6..39bff1e7 100644 --- a/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/util/DocumentSymbolsTest.java +++ b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/util/DocumentSymbolsTest.java @@ -65,7 +65,7 @@ public void asIterator() { Iterator iterator = DocumentSymbols.asIterator(depth0); Iterable iterable = () -> iterator; Stream stream = StreamSupport.stream(iterable.spliterator(), false); - List actual = stream.map(symbol -> symbol.getName()).collect(toList()); + List actual = stream.map(DocumentSymbol::getName).collect(toList()); List expected = Arrays.asList("root, A1", "B1", "C1", "A11", "A12", "B11", "B12", "C11", "C12"); Assert.assertEquals(Arrays.toString(expected.toArray()), Arrays.toString(actual.toArray()));