use of org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method getCallHierarchyElement.
private IMember getCallHierarchyElement(String uri, int line, int character, IProgressMonitor monitor) throws JavaModelException {
Assert.isNotNull(uri, "uri");
ITypeRoot root = JDTUtils.resolveTypeRoot(uri);
if (root == null) {
return null;
}
if (root instanceof ICompilationUnit) {
ICompilationUnit unit = (ICompilationUnit) root;
if (root.getResource() == null) {
return null;
}
reconcile(unit, monitor);
}
checkMonitor(monitor);
// Try to locate the member at the given position.
IMember candidate = null;
int offset = JsonRpcHelpers.toOffset(root, line, character);
List<IJavaElement> selectedElements = codeResolve(root, offset);
Stream<IJavaElement> possibleElements = selectedElements.stream().filter(CallHierarchyCore::isPossibleInputElement);
Optional<IJavaElement> firstElement = possibleElements.findFirst();
if (firstElement.isPresent() && firstElement.get() instanceof IMember) {
candidate = (IMember) firstElement.get();
}
// If the member cannot be resolved, retrieve the enclosing method.
if (candidate == null) {
candidate = getEnclosingMember(root, offset);
}
return candidate;
}
use of org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore in project eclipse.jdt.ls by eclipse.
the class CallHierarchyHandler method getCallRoot.
private MethodWrapper getCallRoot(IMember member, boolean isIncomingCall) {
Assert.isNotNull(member, "member");
IMember[] members = { member };
CallHierarchyCore callHierarchy = CallHierarchyCore.getDefault();
final MethodWrapper[] result;
if (isIncomingCall) {
result = callHierarchy.getCallerRoots(members);
} else {
result = callHierarchy.getCalleeRoots(members);
}
if (result == null || result.length < 1) {
return null;
}
return result[0];
}
Aggregations