PT #171932358 Flag for detailed java type data for sub/super types
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -15,6 +15,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.MarkupContent;
|
||||
import org.eclipse.lsp4j.jsonrpc.json.ResponseJsonAdapter;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
@@ -68,10 +70,12 @@ public interface STS4LanguageClient extends LanguageClient {
|
||||
CompletableFuture<List<String>> javaSearchPackages(JavaSearchParams params);
|
||||
|
||||
@JsonRequest("sts/javaSubTypes")
|
||||
CompletableFuture<List<TypeDescriptorData>> javaSubTypes(JavaTypeHierarchyParams params);
|
||||
@ResponseJsonAdapter(TypeHierarchyResponseAdapter.class)
|
||||
CompletableFuture<List<Either<TypeDescriptorData, TypeData>>> javaSubTypes(JavaTypeHierarchyParams params);
|
||||
|
||||
@JsonRequest("sts/javaSuperTypes")
|
||||
CompletableFuture<List<TypeDescriptorData>> javaSuperTypes(JavaTypeHierarchyParams params);
|
||||
@ResponseJsonAdapter(TypeHierarchyResponseAdapter.class)
|
||||
CompletableFuture<List<Either<TypeDescriptorData, TypeData>>> javaSuperTypes(JavaTypeHierarchyParams params);
|
||||
|
||||
@JsonRequest("sts/javaCodeComplete")
|
||||
CompletableFuture<List<JavaCodeCompleteData>> javaCodeComplete(JavaCodeCompleteParams params);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
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 org.springframework.ide.vscode.commons.protocol.java.TypeData;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Helps to parse JSON for <code>Either<TypeDescriptorData, TypeData></code>.
|
||||
* Creates either {@link TypeData} or {@link TypeDescriptorData} based on
|
||||
* {@link JsonObject} properties.
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class TypeHierarchyResponseAdapter implements TypeAdapterFactory {
|
||||
|
||||
private static final TypeToken<Either<TypeDescriptorData, TypeData>> ELEMENT_TYPE = new TypeToken<Either<TypeDescriptorData, TypeData>>() {
|
||||
};
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
Predicate<JsonElement> rightChecker = new PropertyChecker("classpathEntry", JsonObject.class)
|
||||
.or(new PropertyChecker("bindingKey", JsonPrimitive.class));
|
||||
Predicate<JsonElement> leftChecker = new PropertyChecker("fqName", JsonPrimitive.class)
|
||||
.and(rightChecker.negate());
|
||||
TypeAdapter<Either<TypeDescriptorData, TypeData>> elementTypeAdapter = new EitherTypeAdapter<>(gson,
|
||||
ELEMENT_TYPE, leftChecker, rightChecker);
|
||||
return (TypeAdapter<T>) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter,
|
||||
ArrayList::new);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -15,16 +15,18 @@ public class JavaTypeHierarchyParams {
|
||||
private String projectUri;
|
||||
private String fqName;
|
||||
private boolean includeFocusType;
|
||||
private boolean detailed;
|
||||
|
||||
public JavaTypeHierarchyParams(String projectUri, String fqName, boolean includeFocusType) {
|
||||
public JavaTypeHierarchyParams(String projectUri, String fqName, boolean includeFocusType, boolean detailed) {
|
||||
super();
|
||||
this.projectUri = projectUri;
|
||||
this.fqName = fqName;
|
||||
this.setDetailed(detailed);
|
||||
this.setIncludeFocusType(includeFocusType);
|
||||
}
|
||||
|
||||
public JavaTypeHierarchyParams(String projectUri, String fqName) {
|
||||
this(projectUri, fqName, false);
|
||||
this(projectUri, fqName, false, false);
|
||||
}
|
||||
|
||||
public String getProjectUri() {
|
||||
@@ -51,6 +53,17 @@ public class JavaTypeHierarchyParams {
|
||||
this.includeFocusType = includeFocusType;
|
||||
}
|
||||
|
||||
public boolean isDetailed() {
|
||||
return detailed;
|
||||
}
|
||||
|
||||
public void setDetailed(boolean detailed) {
|
||||
this.detailed = detailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* IMPORTANT: Do not include 'detailed' flag in the {@link #hashCode()} and {@link #equals(Object)}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -61,6 +74,9 @@ public class JavaTypeHierarchyParams {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* IMPORTANT: Do not include 'detailed' flag in the {@link #hashCode()} and {@link #equals(Object)}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
@@ -84,5 +100,5 @@ public class JavaTypeHierarchyParams {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user