-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing Type Adaper for RestartArguments.arguments
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...p4j.debug/src/main/java/org/eclipse/lsp4j/debug/adapters/RestartArgumentsTypeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Either<LaunchRequestArguments, AttachRequestArguments>> ELEMENT_TYPE = new TypeToken<Either<LaunchRequestArguments, AttachRequestArguments>>() { | ||
}; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | ||
Predicate<JsonElement> leftChecker = new PropertyChecker("noDebug"); | ||
Predicate<JsonElement> rightChecker = leftChecker.negate(); | ||
TypeAdapter<Either<LaunchRequestArguments, AttachRequestArguments>> elementTypeAdapter = new EitherTypeAdapter<>( | ||
gson, ELEMENT_TYPE, leftChecker, rightChecker); | ||
return (TypeAdapter<T>) elementTypeAdapter; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...ug/src/test/java/org/eclipse/lsp4j/debug/test/RestartArgumentsTypeAdapterFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |