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