Search in sources :

Example 1 with CallHierarchyIncomingCall

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

the class CallHierarchyHandler method getIncomingCallItemsAt.

private List<CallHierarchyIncomingCall> getIncomingCallItemsAt(String uri, int line, int character, IProgressMonitor monitor) throws JavaModelException {
    SubMonitor sub = SubMonitor.convert(monitor, 2);
    IMember candidate = getCallHierarchyElement(uri, line, character, sub.split(1));
    if (candidate == null) {
        return null;
    }
    checkMonitor(monitor);
    MethodWrapper wrapper = incomingMethodWrapperCache.containsKey(candidate) ? incomingMethodWrapperCache.get(candidate) : getCallRoot(candidate, true);
    if (wrapper == null || !wrapper.canHaveChildren()) {
        return null;
    }
    MethodWrapper[] calls = wrapper.getCalls(sub.split(1));
    if (calls == null) {
        return null;
    }
    List<CallHierarchyIncomingCall> result = new ArrayList<>();
    for (MethodWrapper call : calls) {
        Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
        if (callLocations != null) {
            for (CallLocation location : callLocations) {
                IOpenable openable = getOpenable(location);
                Range callRange = getRange(openable, location);
                CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
                symbol.setSelectionRange(callRange);
                List<Range> ranges = toCallRanges(callLocations);
                result.add(new CallHierarchyIncomingCall(symbol, ranges));
            }
        }
        IMember member = call.getMember();
        if (member != null) {
            incomingMethodWrapperCache.put(member, call);
        }
    }
    return result;
}
Also used : IOpenable(org.eclipse.jdt.core.IOpenable) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) Range(org.eclipse.lsp4j.Range) IMember(org.eclipse.jdt.core.IMember) CallHierarchyIncomingCall(org.eclipse.lsp4j.CallHierarchyIncomingCall) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) MethodWrapper(org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)

Example 2 with CallHierarchyIncomingCall

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

the class CallHierarchyHandlerTest method testSelectionRange.

@Test
public void testSelectionRange() throws Exception {
    // Line  from `org.sample.Foo`
    // public void <|>someMethod() {}
    String uri = getUriFromSrcProject("org.sample.Foo");
    List<CallHierarchyItem> items = prepareCallHierarchy(uri, 8, 13);
    assertNotNull(items);
    assertEquals(1, items.size());
    assertItem(items.get(0), "someMethod()" + JavaElementLabels.DECL_STRING + "void", Method, "org.sample.Foo", false, 8);
    List<CallHierarchyIncomingCall> calls = getIncomingCalls(items.get(0));
    assertNotNull(calls);
    assertEquals(4, calls.size());
    assertItem(calls.get(2).getFrom(), "main(String[]) : void", Method, "org.sample.Call", false, 7);
    assertItem(calls.get(3).getFrom(), "main(String[]) : void", Method, "org.sample.Call", false, 10);
    Range selectionRange = calls.get(2).getFrom().getSelectionRange();
    assertEquals(new Range(new Position(7, 18), new Position(7, 30)), selectionRange);
    selectionRange = calls.get(3).getFrom().getSelectionRange();
    assertEquals(new Range(new Position(10, 18), new Position(10, 30)), selectionRange);
}
Also used : CallHierarchyIncomingCall(org.eclipse.lsp4j.CallHierarchyIncomingCall) Position(org.eclipse.lsp4j.Position) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) Range(org.eclipse.lsp4j.Range) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

CallHierarchyIncomingCall (org.eclipse.lsp4j.CallHierarchyIncomingCall)2 CallHierarchyItem (org.eclipse.lsp4j.CallHierarchyItem)2 Range (org.eclipse.lsp4j.Range)2 ArrayList (java.util.ArrayList)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IMember (org.eclipse.jdt.core.IMember)1 IOpenable (org.eclipse.jdt.core.IOpenable)1 CallLocation (org.eclipse.jdt.internal.corext.callhierarchy.CallLocation)1 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)1 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)1 Position (org.eclipse.lsp4j.Position)1 Test (org.junit.Test)1