use of org.eclipse.lsp4j.CallHierarchyItem in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method toCallHierarchyItem.
private CallHierarchyItem toCallHierarchyItem(IMember member) throws JavaModelException {
Location fullLocation = getLocation(member, LocationType.FULL_RANGE);
Range range = fullLocation.getRange();
String uri = fullLocation.getUri();
CallHierarchyItem item = new CallHierarchyItem();
item.setName(JDTUtils.getName(member));
item.setKind(DocumentSymbolHandler.mapKind(member));
item.setRange(range);
item.setSelectionRange(getLocation(member, LocationType.NAME_RANGE).getRange());
item.setUri(uri);
IType declaringType = member.getDeclaringType();
item.setDetail(declaringType == null ? null : declaringType.getFullyQualifiedName());
if (JDTUtils.isDeprecated(member)) {
item.setTags(Arrays.asList(SymbolTag.Deprecated));
}
return item;
}
use of org.eclipse.lsp4j.CallHierarchyItem 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.CallHierarchyItem in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method callHierarchyOutgoingCalls.
public List<CallHierarchyOutgoingCall> callHierarchyOutgoingCalls(CallHierarchyOutgoingCallsParams params, IProgressMonitor monitor) {
Assert.isNotNull(params, "params");
CallHierarchyItem item = params.getItem();
Assert.isNotNull(item, "call item");
Position position = item.getRange().getStart();
int line = position.getLine();
int character = position.getCharacter();
try {
return getOutgoingCallItemsAt(item.getUri(), line, character, monitor);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.log(e);
} catch (OperationCanceledException e) {
// do nothing
}
return null;
}
use of org.eclipse.lsp4j.CallHierarchyItem in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method callHierarchyIncomingCalls.
public List<CallHierarchyIncomingCall> callHierarchyIncomingCalls(CallHierarchyIncomingCallsParams params, IProgressMonitor monitor) {
Assert.isNotNull(params, "params");
CallHierarchyItem item = params.getItem();
Assert.isNotNull(item, "call item");
Position position;
switch(item.getKind()) {
case Class:
case Enum:
case Interface:
position = item.getSelectionRange().getStart();
break;
default:
position = item.getRange().getStart();
break;
}
int line = position.getLine();
int character = position.getCharacter();
try {
return getIncomingCallItemsAt(item.getUri(), line, character, monitor);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.log(e);
} catch (OperationCanceledException e) {
// do nothing
}
return null;
}
use of org.eclipse.lsp4j.CallHierarchyItem in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method getOutgoingCallItemsAt.
private List<CallHierarchyOutgoingCall> getOutgoingCallItemsAt(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 = outgoingMethodWrapperCache.containsKey(candidate) ? outgoingMethodWrapperCache.get(candidate) : getCallRoot(candidate, false);
if (wrapper == null) {
return null;
}
MethodWrapper[] calls = wrapper.getCalls(sub.split(1));
if (calls == null) {
return null;
}
List<CallHierarchyOutgoingCall> result = new ArrayList<>();
for (MethodWrapper call : calls) {
Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
if (callLocations != null && !callLocations.isEmpty()) {
List<Range> ranges = toCallRanges(callLocations);
for (int i = 0; i < callLocations.size(); i++) {
CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
result.add(new CallHierarchyOutgoingCall(symbol, ranges));
}
}
IMember member = call.getMember();
if (member != null) {
outgoingMethodWrapperCache.put(member, call);
}
}
return result;
}
Aggregations