private SymbolInformation[] getOutline(ITypeRoot unit, IProgressMonitor monitor) { try { IJavaElement[] elements = unit.getChildren(); ArrayList<SymbolInformation> symbols = new ArrayList<>(elements.length); collectChildren(unit, elements, symbols, monitor); return symbols.toArray(new SymbolInformation[symbols.size()]); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e); } return new SymbolInformation[0]; }
private List<DocumentSymbol> getHierarchicalOutline(ITypeRoot unit, IProgressMonitor monitor) { try { return Stream.of(filter(unit.getChildren())).map(child -> toDocumentSymbol(child, monitor)).filter(Objects::nonNull).collect(Collectors.toList()); } catch (OperationCanceledException e) { logInfo("User abort while collecting the document symbols."); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem getting outline for" + unit.getElementName(), e); } return emptyList(); }
public List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(DocumentSymbolParams params, IProgressMonitor monitor) { ITypeRoot unit = JDTUtils.resolveTypeRoot(params.getTextDocument().getUri()); if (unit == null) { return Collections.emptyList(); } if (hierarchicalDocumentSymbolSupported) { List<DocumentSymbol> symbols = this.getHierarchicalOutline(unit, monitor); return symbols.stream().map(Either::<SymbolInformation, DocumentSymbol>forRight).collect(toList()); } else { SymbolInformation[] elements = this.getOutline(unit, monitor); return Arrays.asList(elements).stream().map(Either::<SymbolInformation, DocumentSymbol>forLeft).collect(toList()); } }
String name = getName(unit); symbol.setName(name); symbol.setRange(getRange(unit)); symbol.setSelectionRange(getSelectionRange(unit)); symbol.setKind(mapKind(unit)); symbol.setDeprecated(isDeprecated(unit)); symbol.setDetail(getDetail(unit, name)); if (unit instanceof IParent) { IJavaElement[] children = filter(((IParent) unit).getChildren()); symbol.setChildren(Stream.of(children) .map(child -> toDocumentSymbol(child, monitor)) .filter(Objects::nonNull) .collect(Collectors.toList()));
collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor); String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); si.setName(name == null ? element.getElementName() : name); si.setKind(mapKind(element)); if (element.getParent() != null) { si.setContainerName(element.getParent().getElementName());
@Override public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) { logInfo(">> document/documentSymbol"); boolean hierarchicalDocumentSymbolSupported = preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported(); DocumentSymbolHandler handler = new DocumentSymbolHandler(hierarchicalDocumentSymbolSupported); return computeAsync((monitor) -> { waitForLifecycleJobs(monitor); return handler.documentSymbol(params, monitor); }); }