Skip to content

Commit

Permalink
Support move instance method and static member (#1145)
Browse files Browse the repository at this point in the history
Signed-off-by: Jinbo Wang <[email protected]>
  • Loading branch information
testforstephen authored and fbricon committed Aug 22, 2019
1 parent c654ebf commit 9e54284
Show file tree
Hide file tree
Showing 11 changed files with 950 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal;

import java.util.HashMap;

import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

Expand All @@ -25,25 +29,36 @@ public class JSONUtility {
* @throws IllegalArgumentException if clazz is null
*/
public static <T> T toModel(Object object, Class<T> clazz){
return toModel(new Gson(), object, clazz);
}

/**
* Converts given JSON objects to given Model objects with the customized
* TypeAdapters from lsp4j.
*
* @throws IllegalArgumentException
* if clazz is null
*/
public static <T> T toLsp4jModel(Object object, Class<T> clazz) {
return toModel(new MessageJsonHandler(new HashMap<>()).getGson(), object, clazz);
}

private static <T> T toModel(Gson gson, Object object, Class<T> clazz) {
if(object == null){
return null;
}
if(clazz == null ){
throw new IllegalArgumentException("Class can not be null");
}
if(object instanceof JsonElement){
Gson gson = new Gson();
return gson.fromJson((JsonElement) object, clazz);
}
if (clazz.isInstance(object)) {
return clazz.cast(object);
}
if (object instanceof String) {
Gson gson = new Gson();
return gson.fromJson((String) object, clazz);
}
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.shared.utils.StringUtils;
import org.eclipse.buildship.core.internal.configuration.GradleProjectNature;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -118,6 +119,23 @@ public static IProject[] getAllProjects() {
return ResourcesPlugin.getWorkspace().getRoot().getProjects();
}

public static IProject getProject(String projectName) {
if (StringUtils.isBlank(projectName)) {
return null;
}

return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}

public static IJavaProject getJavaProject(String projectName) {
IProject project = getProject(projectName);
if (project != null && isJavaProject(project)) {
return JavaCore.create(project);
}

return null;
}

public static boolean addSourcePath(IPath sourcePath, IJavaProject project) throws CoreException {
return addSourcePath(sourcePath, null, project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.eclipse.jdt.ls.core.internal.handlers.MoveHandler.MoveParams;
import org.eclipse.jdt.ls.core.internal.handlers.OverrideMethodsHandler.AddOverridableMethodParams;
import org.eclipse.jdt.ls.core.internal.handlers.OverrideMethodsHandler.OverridableMethodsResponse;
import org.eclipse.jdt.ls.core.internal.handlers.WorkspaceSymbolHandler.SearchSymbolParams;
import org.eclipse.jdt.ls.core.internal.lsp.JavaProtocolExtensions;
import org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager;
import org.eclipse.jdt.ls.core.internal.managers.FormatterManager;
Expand Down Expand Up @@ -390,9 +391,8 @@ public JavaProtocolExtensions getJavaExtensions() {
@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
logInfo(">> workspace/symbol");
WorkspaceSymbolHandler handler = new WorkspaceSymbolHandler(preferenceManager);
return computeAsync((monitor) -> {
return handler.search(params.getQuery(), monitor);
return WorkspaceSymbolHandler.search(params.getQuery(), monitor);
});
}

Expand Down Expand Up @@ -889,6 +889,12 @@ public CompletableFuture<RefactorWorkspaceEdit> move(MoveParams params) {
return computeAsyncWithClientProgress((monitor) -> MoveHandler.move(params, monitor));
}

@Override
public CompletableFuture<List<SymbolInformation>> searchSymbols(SearchSymbolParams params) {
logInfo(">> java/searchSymbols");
return computeAsyncWithClientProgress((monitor) -> WorkspaceSymbolHandler.search(params.getQuery(), params.maxResults, params.projectName, params.sourceOnly, monitor));
}

public void sendStatus(ServiceStatus serverStatus, String status) {
if (client != null) {
client.sendStatus(serverStatus, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public static class LspVariableBinding {
public String bindingKey;
public String name;
public String type;
public boolean isField;

public LspVariableBinding(IVariableBinding binding) {
this.bindingKey = binding.getKey();
this.name = binding.getName();
this.type = binding.getType().getName();
this.isField = binding.isField();
}
}

Expand Down
Loading

0 comments on commit 9e54284

Please sign in to comment.