Search in sources :

Example 1 with CallHierarchyItem

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;
}
Also used : CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) Range(org.eclipse.lsp4j.Range) Location(org.eclipse.lsp4j.Location) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) IType(org.eclipse.jdt.core.IType)

Example 2 with CallHierarchyItem

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;
}
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 3 with CallHierarchyItem

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;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Position(org.eclipse.lsp4j.Position) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem)

Example 4 with CallHierarchyItem

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;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Position(org.eclipse.lsp4j.Position) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem)

Example 5 with CallHierarchyItem

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;
}
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)

Aggregations

CallHierarchyItem (org.eclipse.lsp4j.CallHierarchyItem)6 Range (org.eclipse.lsp4j.Range)4 CallLocation (org.eclipse.jdt.internal.corext.callhierarchy.CallLocation)3 Position (org.eclipse.lsp4j.Position)3 ArrayList (java.util.ArrayList)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 IMember (org.eclipse.jdt.core.IMember)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)2 CallHierarchyIncomingCall (org.eclipse.lsp4j.CallHierarchyIncomingCall)2 IOpenable (org.eclipse.jdt.core.IOpenable)1 IType (org.eclipse.jdt.core.IType)1 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)1 CallHierarchyOutgoingCall (org.eclipse.lsp4j.CallHierarchyOutgoingCall)1 Location (org.eclipse.lsp4j.Location)1 Test (org.junit.Test)1