-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yaohai Zheng <[email protected]>
- Loading branch information
Showing
11 changed files
with
169 additions
and
61 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
45 changes: 45 additions & 0 deletions
45
org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/PrepareRenameResponseAdapter.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,45 @@ | ||
/****************************************************************************** | ||
* 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.PrepareRenameResult; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter; | ||
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 PrepareRenameResponseAdapter implements TypeAdapterFactory { | ||
|
||
private static final TypeToken<Either<Range, PrepareRenameResult>> ELEMENT_TYPE | ||
= new TypeToken<Either<Range, PrepareRenameResult>>() {}; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | ||
Predicate<JsonElement> leftChecker = new PropertyChecker("start"); | ||
Predicate<JsonElement> rightChecker = new PropertyChecker("range"); | ||
TypeAdapter<Either<Range, PrepareRenameResult>> elementTypeAdapter = new EitherTypeAdapter<>(gson, ELEMENT_TYPE, | ||
leftChecker, rightChecker); | ||
return (TypeAdapter<T>) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, | ||
ArrayList::new); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.