Search in sources :

Example 1 with CallHierarchyCore

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) CallHierarchyCore(org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore) IMember(org.eclipse.jdt.core.IMember)

Example 2 with CallHierarchyCore

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];
}
Also used : CallHierarchyCore(org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore) MethodWrapper(org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper) IMember(org.eclipse.jdt.core.IMember)

Aggregations

IMember (org.eclipse.jdt.core.IMember)2 CallHierarchyCore (org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)1 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)1