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;
}
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);
}
Aggregations