Search in sources :

Example 1 with MethodWrapper

use of org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper 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 MethodWrapper

use of org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper in project gemoc-studio by eclipse.

the class CallHierarchyHelper method getCallersOf.

/**
 * Find methods calling method 'm'
 */
public static HashSet<IMethod> getCallersOf(IMethod m) {
    CallHierarchy callHierarchy = CallHierarchy.getDefault();
    IMember[] members = { m };
    MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
    HashSet<IMethod> callers = new HashSet<IMethod>();
    for (MethodWrapper mw : methodWrappers) {
        MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
        HashSet<IMethod> temp = getIMethods(mw2);
        callers.addAll(temp);
    }
    return callers;
}
Also used : CallHierarchy(org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MethodWrapper(org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper) IMethod(org.eclipse.jdt.core.IMethod) IMember(org.eclipse.jdt.core.IMember) HashSet(java.util.HashSet)

Example 3 with MethodWrapper

use of org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper in project gemoc-studio by eclipse.

the class CallHierarchyHelper method getCallLocationsOf.

/**
 * Find calling sites for method 'm'
 */
public static HashSet<CallLocation> getCallLocationsOf(IMethod m) {
    CallHierarchy callHierarchy = CallHierarchy.getDefault();
    IMember[] members = { m };
    MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
    HashSet<CallLocation> callers = new HashSet<CallLocation>();
    for (MethodWrapper mw : methodWrappers) {
        MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
        HashSet<CallLocation> temp = getCallLocations(mw2);
        callers.addAll(temp);
    }
    return callers;
}
Also used : CallHierarchy(org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) MethodWrapper(org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper) IMember(org.eclipse.jdt.core.IMember) HashSet(java.util.HashSet)

Example 4 with MethodWrapper

use of org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper 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;
}
Also used : 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) CallHierarchyOutgoingCall(org.eclipse.lsp4j.CallHierarchyOutgoingCall) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) MethodWrapper(org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)

Example 5 with MethodWrapper

use of org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper 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)5 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)5 CallLocation (org.eclipse.jdt.internal.corext.callhierarchy.CallLocation)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 CallHierarchy (org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy)2 CallHierarchyItem (org.eclipse.lsp4j.CallHierarchyItem)2 Range (org.eclipse.lsp4j.Range)2 IMethod (org.eclipse.jdt.core.IMethod)1 IOpenable (org.eclipse.jdt.core.IOpenable)1 CallHierarchyCore (org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore)1 CallHierarchyIncomingCall (org.eclipse.lsp4j.CallHierarchyIncomingCall)1 CallHierarchyOutgoingCall (org.eclipse.lsp4j.CallHierarchyOutgoingCall)1