From 524957d4ec495864cd50fa51625181d4c7e78cdc Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Wed, 18 May 2022 07:16:44 +0200 Subject: [PATCH] Introduced type adapter for CompletionItemDefaults.editRange Harmonized Naming convention and package structure Fixes #624 Signed-off-by: Christian Dietrich --- .../eclipse/lsp4j/debug/DebugProtocol.xtend | 4 +- ...RestartArgumentsArgumentsTypeAdapter.java} | 2 +- ...artArgumentsArgumentsTypeAdapterTest.java} | 4 +- .../java/org/eclipse/lsp4j/Protocol.xtend | 2 + ...etionItemDefaultsEditRangeTypeAdapter.java | 39 +++++++++++++++++++ ...nItemDefaultsEditRangeTypeAdapterTest.java | 33 ++++++++++++++++ 6 files changed, 79 insertions(+), 5 deletions(-) rename org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/{RestartArgumentsTypeAdapter.java => RestartArgumentsArgumentsTypeAdapter.java} (95%) rename org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/{RestartArgumentsTypeAdapterFactoryTest.java => adapters/RestartArgumentsArgumentsTypeAdapterTest.java} (93%) create mode 100644 org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java create mode 100644 org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/adapters/CompletionItemDefaultsEditRangeTypeAdapterTest.java diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/DebugProtocol.xtend b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/DebugProtocol.xtend index b6e8c4acf..06e928f2b 100644 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/DebugProtocol.xtend +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/DebugProtocol.xtend @@ -15,10 +15,10 @@ package org.eclipse.lsp4j.debug; import com.google.gson.annotations.JsonAdapter import com.google.gson.annotations.SerializedName import java.util.Map -import org.eclipse.lsp4j.debug.adapters.RestartArgumentsTypeAdapter import org.eclipse.lsp4j.generator.JsonRpcData import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.lsp4j.jsonrpc.validation.NonNull +import org.eclipse.lsp4j.debug.adapters.RestartArgumentsArgumentsTypeAdapter /** * Declaration of parameters, response bodies, and event bodies for @@ -940,7 +940,7 @@ class RestartArguments { *

* Since 1.47 */ - @JsonAdapter(RestartArgumentsTypeAdapter) + @JsonAdapter(RestartArgumentsArgumentsTypeAdapter) Either arguments; } diff --git a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java similarity index 95% rename from org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java rename to org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java index 5e3f8927c..b094ff740 100644 --- a/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsArgumentsTypeAdapter.java @@ -25,7 +25,7 @@ import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; -public class RestartArgumentsTypeAdapter implements TypeAdapterFactory { +public class RestartArgumentsArgumentsTypeAdapter implements TypeAdapterFactory { private static final TypeToken> ELEMENT_TYPE = new TypeToken>() { }; diff --git a/org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.java b/org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/adapters/RestartArgumentsArgumentsTypeAdapterTest.java similarity index 93% rename from org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.java rename to org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/adapters/RestartArgumentsArgumentsTypeAdapterTest.java index 2a37f4006..9e412a1ad 100644 --- a/org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.java +++ b/org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/adapters/RestartArgumentsArgumentsTypeAdapterTest.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause ******************************************************************************/ -package org.eclipse.lsp4j.debug.test; +package org.eclipse.lsp4j.debug.test.adapters; import static org.junit.Assert.assertTrue; @@ -19,7 +19,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -public class RestartArgumentsTypeAdapterFactoryTest { +public class RestartArgumentsArgumentsTypeAdapterTest { @Test public void test() { diff --git a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend index f64e226b9..5405b7559 100644 --- a/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend @@ -35,6 +35,7 @@ import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode import org.eclipse.lsp4j.jsonrpc.messages.Tuple import org.eclipse.lsp4j.jsonrpc.validation.NonNull import org.eclipse.lsp4j.util.Preconditions +import org.eclipse.lsp4j.adapters.CompletionItemDefaultsEditRangeTypeAdapter @JsonRpcData class DynamicRegistrationCapabilities { @@ -3111,6 +3112,7 @@ class CompletionItemDefaults { /** * A default edit range */ + @JsonAdapter(CompletionItemDefaultsEditRangeTypeAdapter) Either editRange /** 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 new file mode 100644 index 000000000..c10187023 --- /dev/null +++ b/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CompletionItemDefaultsEditRangeTypeAdapter.java @@ -0,0 +1,39 @@ +/****************************************************************************** + * 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; +import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter.PropertyChecker; +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>() { + }; + + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + Predicate leftChecker = new PropertyChecker("start"); + Predicate 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/test/java/org/eclipse/lsp4j/test/adapters/CompletionItemDefaultsEditRangeTypeAdapterTest.java b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/adapters/CompletionItemDefaultsEditRangeTypeAdapterTest.java new file mode 100644 index 000000000..cea39a3c2 --- /dev/null +++ b/org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/adapters/CompletionItemDefaultsEditRangeTypeAdapterTest.java @@ -0,0 +1,33 @@ +/****************************************************************************** + * 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.test.adapters; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.lsp4j.CompletionItemDefaults; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class CompletionItemDefaultsEditRangeTypeAdapterTest { + + @Test + public void test() { + GsonBuilder builder = new GsonBuilder(); + Gson gson = builder.create(); + CompletionItemDefaults object = gson.fromJson("{\"editRange\":{\"start\":{\"line\":0,\"character\":1},\"end\":{\"line\":0,\"character\":2}}}", CompletionItemDefaults.class); + assertTrue(object.toString(), object.getEditRange().isLeft()); + object = gson.fromJson("{\"editRange\":{\"insert\":{\"start\":{\"line\":0,\"character\":1},\"end\":{\"line\":0,\"character\":2}},\"replace\":{\"start\":{\"line\":1,\"character\":1},\"end\":{\"line\":1,\"character\":2}}}}", CompletionItemDefaults.class); + assertTrue(object.toString(), object.getEditRange().isRight()); + } +}