From eec8a7d4cf010f44c2e60a92b51dce77d733191c Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Tue, 17 May 2022 17:35:55 +0200 Subject: [PATCH] Added missing Type Adaper for RestartArguments.arguments Signed-off-by: Christian Dietrich --- .../eclipse/lsp4j/debug/DebugProtocol.xtend | 3 ++ .../adapters/RestartArgumentsTypeAdapter.java | 43 +++++++++++++++++++ ...estartArgumentsTypeAdapterFactoryTest.java | 38 ++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java create mode 100644 org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.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 0da48cad..462bebf6 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 @@ -12,8 +12,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 @@ -938,6 +940,7 @@ class RestartArguments { *

* Since 1.47 */ + @JsonAdapter(RestartArgumentsTypeAdapter) 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/RestartArgumentsTypeAdapter.java new file mode 100644 index 00000000..5e3f8927 --- /dev/null +++ b/org.eclipse.lsp4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java @@ -0,0 +1,43 @@ +/****************************************************************************** + * 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; +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 RestartArgumentsTypeAdapter implements TypeAdapterFactory { + + 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); + return (TypeAdapter) elementTypeAdapter; + } + +} 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/RestartArgumentsTypeAdapterFactoryTest.java new file mode 100644 index 00000000..2a37f400 --- /dev/null +++ b/org.eclipse.lsp4j.debug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.java @@ -0,0 +1,38 @@ +/****************************************************************************** + * 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.test; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.lsp4j.debug.RestartArguments; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class RestartArgumentsTypeAdapterFactoryTest { + + @Test + public void test() { + GsonBuilder builder = new GsonBuilder(); + Gson gson = builder.create(); + RestartArguments object = gson.fromJson("{\"arguments\": {\"noDebug\":true}}", RestartArguments.class); + assertTrue(object.toString(), object.getArguments().isLeft()); + object = gson.fromJson("{\"arguments\": {\"noDebug\":true, \"__restart\":{}}}", RestartArguments.class); + assertTrue(object.toString(), object.getArguments().isLeft()); + object = gson.fromJson("{\"arguments\": {}}", RestartArguments.class); + assertTrue(object.toString(), object.getArguments().isRight()); + object = gson.fromJson("{\"arguments\": {\"__restart\":{\"dunno\": true}}}", RestartArguments.class); + assertTrue(object.toString(), object.getArguments().isRight()); + } + +}