Search in sources :

Example 1 with CallLocation

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

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

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

use of org.eclipse.jdt.internal.corext.callhierarchy.CallLocation in project eclipse.jdt.ls by eclipse.

the class CallHierarchyHandler method toCallRanges.

private List<Range> toCallRanges(Collection<CallLocation> callLocations) {
    List<Range> ranges = new ArrayList<>();
    if (callLocations != null) {
        for (CallLocation location : callLocations) {
            IOpenable openable = getOpenable(location);
            Range callRange = getRange(openable, location);
            ranges.add(callRange);
        }
    }
    return ranges;
}
Also used : IOpenable(org.eclipse.jdt.core.IOpenable) ArrayList(java.util.ArrayList) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) Range(org.eclipse.lsp4j.Range)

Aggregations

CallLocation (org.eclipse.jdt.internal.corext.callhierarchy.CallLocation)4 ArrayList (java.util.ArrayList)3 IMember (org.eclipse.jdt.core.IMember)3 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)3 Range (org.eclipse.lsp4j.Range)3 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 IOpenable (org.eclipse.jdt.core.IOpenable)2 CallHierarchyItem (org.eclipse.lsp4j.CallHierarchyItem)2 HashSet (java.util.HashSet)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 CallHierarchy (org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy)1 CallHierarchyIncomingCall (org.eclipse.lsp4j.CallHierarchyIncomingCall)1 CallHierarchyOutgoingCall (org.eclipse.lsp4j.CallHierarchyOutgoingCall)1