Search in sources :

Example 1 with PACKAGE_DECLARATION

use of org.eclipse.jdt.core.IJavaElement.PACKAGE_DECLARATION in project eclipse.jdt.ls by eclipse.

the class DocumentSymbolHandler method toDocumentSymbol.

private DocumentSymbol toDocumentSymbol(IJavaElement unit, IProgressMonitor monitor) {
    int type = unit.getElementType();
    if (type != TYPE && type != FIELD && type != METHOD && type != PACKAGE_DECLARATION && type != COMPILATION_UNIT) {
        return null;
    }
    if (monitor.isCanceled()) {
        throw new OperationCanceledException("User abort");
    }
    DocumentSymbol symbol = new DocumentSymbol();
    try {
        String name = getName(unit);
        symbol.setName(name);
        symbol.setRange(getRange(unit));
        symbol.setSelectionRange(getSelectionRange(unit));
        symbol.setKind(mapKind(unit));
        if (JDTUtils.isDeprecated(unit)) {
            if (preferenceManager.getClientPreferences().isSymbolTagSupported()) {
                symbol.setTags(List.of(SymbolTag.Deprecated));
            } else {
                symbol.setDeprecated(true);
            }
        }
        symbol.setDetail(getDetail(unit, name));
        if (unit instanceof IParent) {
            // @formatter:off
            IJavaElement[] children = filter(((IParent) unit).getChildren());
            symbol.setChildren(Stream.of(children).map(child -> toDocumentSymbol(child, monitor)).filter(Objects::nonNull).collect(Collectors.toList()));
        // @formatter:off
        }
    } catch (JavaModelException e) {
        Exceptions.sneakyThrow(e);
    }
    return symbol;
}
Also used : M_APP_RETURNTYPE(org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels.M_APP_RETURNTYPE) METHOD(org.eclipse.jdt.core.IJavaElement.METHOD) Arrays(java.util.Arrays) Exceptions(org.eclipse.xtext.xbase.lib.Exceptions) IField(org.eclipse.jdt.core.IField) JavaModelException(org.eclipse.jdt.core.JavaModelException) SymbolKind(org.eclipse.lsp4j.SymbolKind) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) COMPILATION_UNIT(org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT) IMember(org.eclipse.jdt.core.IMember) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Flags(org.eclipse.jdt.core.Flags) IParent(org.eclipse.jdt.core.IParent) JavaLanguageServerPlugin.logInfo(org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Position(org.eclipse.lsp4j.Position) PACKAGE_DECLARATION(org.eclipse.jdt.core.IJavaElement.PACKAGE_DECLARATION) ResourceUtils(org.eclipse.jdt.ls.core.internal.ResourceUtils) ROOT_VARIABLE(org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels.ROOT_VARIABLE) JDTUtils(org.eclipse.jdt.ls.core.internal.JDTUtils) FIELD(org.eclipse.jdt.core.IJavaElement.FIELD) Collections.emptyList(java.util.Collections.emptyList) ALL_DEFAULT(org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels.ALL_DEFAULT) JavaLanguageServerPlugin(org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin) Collectors(java.util.stream.Collectors) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) IType(org.eclipse.jdt.core.IType) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SymbolTag(org.eclipse.lsp4j.SymbolTag) Stream(java.util.stream.Stream) IJavaElement(org.eclipse.jdt.core.IJavaElement) FULL_RANGE(org.eclipse.jdt.ls.core.internal.JDTUtils.LocationType.FULL_RANGE) IMethod(org.eclipse.jdt.core.IMethod) TYPE(org.eclipse.jdt.core.IJavaElement.TYPE) JavaElementLabels(org.eclipse.jdt.ls.core.internal.hover.JavaElementLabels) Collections(java.util.Collections) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IParent(org.eclipse.jdt.core.IParent) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Objects(java.util.Objects) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Flags (org.eclipse.jdt.core.Flags)1 IField (org.eclipse.jdt.core.IField)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 COMPILATION_UNIT (org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT)1 FIELD (org.eclipse.jdt.core.IJavaElement.FIELD)1 METHOD (org.eclipse.jdt.core.IJavaElement.METHOD)1 PACKAGE_DECLARATION (org.eclipse.jdt.core.IJavaElement.PACKAGE_DECLARATION)1 TYPE (org.eclipse.jdt.core.IJavaElement.TYPE)1 IMember (org.eclipse.jdt.core.IMember)1