Search in sources :

Example 6 with TypeHierarchyItem

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

the class TypeHierarchyCommand method resolveTypeHierarchy.

public TypeHierarchyItem resolveTypeHierarchy(ResolveTypeHierarchyItemParams params, IProgressMonitor monitor) {
    if (params == null) {
        return null;
    }
    TypeHierarchyItem item = params.getItem();
    if (item == null) {
        return null;
    }
    Range range = item.getRange();
    if (range == null) {
        return null;
    }
    Position position = range.getStart();
    String uri = item.getUri();
    TypeHierarchyDirection direction = params.getDirection();
    int resolve = params.getResolve();
    return getTypeHierarchy(uri, position, direction, resolve, item, monitor);
}
Also used : Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) TypeHierarchyDirection(org.eclipse.lsp4j.TypeHierarchyDirection) Range(org.eclipse.lsp4j.Range)

Example 7 with TypeHierarchyItem

use of org.eclipse.lsp4j.TypeHierarchyItem 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 8 with TypeHierarchyItem

use of org.eclipse.lsp4j.TypeHierarchyItem 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)8 Position (org.eclipse.lsp4j.Position)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 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 Test (org.junit.Test)3 IType (org.eclipse.jdt.core.IType)2 TypeHierarchyDirection (org.eclipse.lsp4j.TypeHierarchyDirection)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IOrdinaryClassFile (org.eclipse.jdt.core.IOrdinaryClassFile)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)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