Search in sources :

Example 1 with TypeHierarchyParams

use of org.eclipse.lsp4j.TypeHierarchyParams in project eclipse.jdt.ls by eclipse.

the class TypeHierarchyCommandTest method testSubTypeHierarchy.

@Test
public void testSubTypeHierarchy() throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    TypeHierarchyParams params = new TypeHierarchyParams();
    String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
    Position position = new Position(2, 43);
    params.setTextDocument(identifier);
    params.setResolve(2);
    params.setDirection(TypeHierarchyDirection.Children);
    params.setPosition(position);
    TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
    assertNotNull(item);
    assertEquals(item.getName(), "Builder");
    assertNull(item.getParents());
    assertEquals(item.getChildren().size(), 9);
    for (TypeHierarchyItem child : item.getChildren()) {
        List<TypeHierarchyItem> subChild = child.getChildren();
        assertNotNull(subChild);
        if (subChild.size() == 1) {
            assertEquals(subChild.get(0).getName(), "ReflectionToStringBuilder");
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 2 with TypeHierarchyParams

use of org.eclipse.lsp4j.TypeHierarchyParams in project eclipse.jdt.ls by eclipse.

the class JDTDelegateCommandHandler method executeCommand.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler#executeCommand(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception {
    if (!StringUtils.isBlank(commandId)) {
        switch(commandId) {
            case "java.edit.organizeImports":
                final OrganizeImportsCommand c = new OrganizeImportsCommand();
                final Object result = c.organizeImports(arguments);
                final boolean applyNow = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isWorkspaceApplyEditSupported();
                if (applyNow) {
                    JavaLanguageServerPlugin.getInstance().getClientConnection().applyWorkspaceEdit((WorkspaceEdit) result);
                    // return an empty object to avoid errors on client
                    return new Object();
                } else {
                    // workspaceEdit on the custom command.
                    return result;
                }
            case "java.edit.stringFormatting":
                FormatterHandler handler = new FormatterHandler(JavaLanguageServerPlugin.getPreferencesManager());
                return handler.stringFormatting((String) arguments.get(0), JSONUtility.toModel(arguments.get(1), Map.class), Integer.parseInt((String) arguments.get(2)), monitor);
            case "java.project.resolveSourceAttachment":
                return SourceAttachmentCommand.resolveSourceAttachment(arguments, monitor);
            case "java.project.updateSourceAttachment":
                return SourceAttachmentCommand.updateSourceAttachment(arguments, monitor);
            case "java.project.addToSourcePath":
                String sourceFolder = (String) arguments.get(0);
                return BuildPathCommand.addToSourcePath(sourceFolder);
            case "java.project.removeFromSourcePath":
                String sourceFolder1 = (String) arguments.get(0);
                return BuildPathCommand.removeFromSourcePath(sourceFolder1);
            case "java.project.listSourcePaths":
                return BuildPathCommand.listSourcePaths();
            case "java.project.getSettings":
                return ProjectCommand.getProjectSettings((String) arguments.get(0), (ArrayList<String>) arguments.get(1));
            case "java.project.getClasspaths":
                return ProjectCommand.getClasspaths((String) arguments.get(0), JSONUtility.toModel(arguments.get(1), ClasspathOptions.class));
            case "java.project.isTestFile":
                return ProjectCommand.isTestFile((String) arguments.get(0));
            case "java.project.getAll":
                return ProjectCommand.getAllJavaProjects();
            case "java.project.refreshDiagnostics":
                return DiagnosticsCommand.refreshDiagnostics((String) arguments.get(0), (String) arguments.get(1), (boolean) arguments.get(2));
            case "java.project.import":
                ProjectCommand.importProject(monitor);
                return null;
            case "java.project.resolveStackTraceLocation":
                List<String> projectNames = null;
                if (arguments.size() > 1) {
                    projectNames = (ArrayList<String>) arguments.get(1);
                }
                return ResolveSourceMappingHandler.resolveStackTraceLocation((String) arguments.get(0), projectNames);
            case "java.navigate.resolveTypeHierarchy":
                TypeHierarchyCommand resolveTypeHierarchyCommand = new TypeHierarchyCommand();
                TypeHierarchyItem toResolve = JSONUtility.toModel(arguments.get(0), TypeHierarchyItem.class);
                TypeHierarchyDirection resolveDirection = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
                int resolveDepth = JSONUtility.toModel(arguments.get(2), Integer.class);
                ResolveTypeHierarchyItemParams resolveParams = new ResolveTypeHierarchyItemParams();
                resolveParams.setItem(toResolve);
                resolveParams.setDirection(resolveDirection);
                resolveParams.setResolve(resolveDepth);
                TypeHierarchyItem resolvedItem = resolveTypeHierarchyCommand.resolveTypeHierarchy(resolveParams, monitor);
                return resolvedItem;
            case "java.navigate.openTypeHierarchy":
                TypeHierarchyCommand typeHierarchyCommand = new TypeHierarchyCommand();
                TypeHierarchyParams params = new TypeHierarchyParams();
                TextDocumentPositionParams textParams = JSONUtility.toModel(arguments.get(0), TextDocumentPositionParams.class);
                TypeHierarchyDirection direction = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
                int resolve = JSONUtility.toModel(arguments.get(2), Integer.class);
                params.setResolve(resolve);
                params.setDirection(direction);
                params.setTextDocument(textParams.getTextDocument());
                params.setPosition(textParams.getPosition());
                TypeHierarchyItem typeHierarchyItem = typeHierarchyCommand.typeHierarchy(params, monitor);
                return typeHierarchyItem;
            case "java.project.upgradeGradle":
                String projectUri = (String) arguments.get(0);
                return GradleProjectImporter.upgradeGradleVersion(projectUri, monitor);
            default:
                break;
        }
    }
    throw new UnsupportedOperationException(String.format("Java language server doesn't support the command '%s'.", commandId));
}
Also used : TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) OrganizeImportsCommand(org.eclipse.jdt.ls.core.internal.commands.OrganizeImportsCommand) TypeHierarchyDirection(org.eclipse.lsp4j.TypeHierarchyDirection) ResolveTypeHierarchyItemParams(org.eclipse.lsp4j.ResolveTypeHierarchyItemParams) ClasspathOptions(org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions) TypeHierarchyCommand(org.eclipse.jdt.ls.core.internal.commands.TypeHierarchyCommand) FormatterHandler(org.eclipse.jdt.ls.core.internal.handlers.FormatterHandler) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Map(java.util.Map)

Example 3 with TypeHierarchyParams

use of org.eclipse.lsp4j.TypeHierarchyParams in project eclipse.jdt.ls by eclipse.

the class TypeHierarchyCommandTest method testTypeHierarchy.

@Test
public void testTypeHierarchy() throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    TypeHierarchyParams params = new TypeHierarchyParams();
    String uriString = fJProject.getFile("src/main/java/org/sample/TestJavadoc.java").getLocationURI().toString();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
    Position position = new Position(4, 20);
    params.setTextDocument(identifier);
    params.setResolve(1);
    params.setDirection(TypeHierarchyDirection.Both);
    params.setPosition(position);
    TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
    assertNotNull(item);
    assertEquals(item.getName(), "TestJavadoc");
    assertNotNull(item.getChildren());
    assertEquals(item.getChildren().size(), 0);
    assertNotNull(item.getParents());
    assertEquals(item.getParents().size(), 1);
    assertEquals(item.getParents().get(0).getName(), "Object");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Example 4 with TypeHierarchyParams

use of org.eclipse.lsp4j.TypeHierarchyParams in project eclipse.jdt.ls by eclipse.

the class TypeHierarchyCommandTest method testSuperTypeHierarchy.

@Test
public void testSuperTypeHierarchy() throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    TypeHierarchyParams params = new TypeHierarchyParams();
    String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
    Position position = new Position(7, 27);
    params.setTextDocument(identifier);
    params.setResolve(1);
    params.setDirection(TypeHierarchyDirection.Parents);
    params.setPosition(position);
    TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
    assertNotNull(item);
    assertEquals(item.getName(), "CallHierarchy$FooBuilder");
    assertNull(item.getChildren());
    assertEquals(item.getParents().size(), 2);
    TypeHierarchyItem builder = item.getParents().get(0);
    assertNotNull(builder);
    assertEquals(builder.getName(), "Builder");
    assertNull(builder.getParents());
    TypeHierarchyItem object = item.getParents().get(1);
    assertNotNull(object);
    assertEquals(object.getName(), "Object");
    assertNull(object.getParents());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

Aggregations

TypeHierarchyItem (org.eclipse.lsp4j.TypeHierarchyItem)4 TypeHierarchyParams (org.eclipse.lsp4j.TypeHierarchyParams)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 AbstractInvisibleProjectBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)3 Position (org.eclipse.lsp4j.Position)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 Test (org.junit.Test)3 Map (java.util.Map)1 OrganizeImportsCommand (org.eclipse.jdt.ls.core.internal.commands.OrganizeImportsCommand)1 ClasspathOptions (org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions)1 TypeHierarchyCommand (org.eclipse.jdt.ls.core.internal.commands.TypeHierarchyCommand)1 FormatterHandler (org.eclipse.jdt.ls.core.internal.handlers.FormatterHandler)1 ResolveTypeHierarchyItemParams (org.eclipse.lsp4j.ResolveTypeHierarchyItemParams)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 TypeHierarchyDirection (org.eclipse.lsp4j.TypeHierarchyDirection)1