use of org.eclipse.jdt.core.IParent 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;
}
use of org.eclipse.jdt.core.IParent in project che by eclipse.
the class JavaModelManager method putInfos.
/*
* Puts the infos in the given map (keys are IJavaElements and values are JavaElementInfos)
* in the Java model cache in an atomic way if the info is not already present in the cache.
* If the info is already present in the cache, it depends upon the forceAdd parameter.
* If forceAdd is false it just returns the existing info and if true, this element and it's children are closed and then
* this particular info is added to the cache.
*/
protected synchronized Object putInfos(IJavaElement openedElement, Object newInfo, boolean forceAdd, Map newElements) {
// remove existing children as the are replaced with the new children contained in newElements
Object existingInfo = this.cache.peekAtInfo(openedElement);
if (existingInfo != null && !forceAdd) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372687
return existingInfo;
}
if (openedElement instanceof IParent) {
closeChildren(existingInfo);
}
// (theodora)
for (Iterator it = newElements.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
IJavaElement element = (IJavaElement) entry.getKey();
if (element instanceof JarPackageFragmentRoot) {
Object info = entry.getValue();
it.remove();
this.cache.putInfo(element, info);
}
}
Iterator iterator = newElements.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
this.cache.putInfo((IJavaElement) entry.getKey(), entry.getValue());
}
return newInfo;
}
use of org.eclipse.jdt.core.IParent in project che by eclipse.
the class JavaModelManager method removeInfoAndChildren.
/*
* Removes all cached info for the given element (including all children)
* from the cache.
* Returns the info for the given element, or null if it was closed.
*/
public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
Object info = this.cache.peekAtInfo(element);
if (info != null) {
boolean wasVerbose = false;
try {
if (JavaModelCache.VERBOSE) {
String elementType;
switch(element.getElementType()) {
case IJavaElement.JAVA_PROJECT:
//$NON-NLS-1$
elementType = "project";
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
//$NON-NLS-1$
elementType = "root";
break;
case IJavaElement.PACKAGE_FRAGMENT:
//$NON-NLS-1$
elementType = "package";
break;
case IJavaElement.CLASS_FILE:
//$NON-NLS-1$
elementType = "class file";
break;
case IJavaElement.COMPILATION_UNIT:
//$NON-NLS-1$
elementType = "compilation unit";
break;
default:
//$NON-NLS-1$
elementType = "element";
}
System.out.println(Thread.currentThread() + " CLOSING " + elementType + " " + //$NON-NLS-1$//$NON-NLS-2$
element.toStringWithAncestors());
wasVerbose = true;
JavaModelCache.VERBOSE = false;
}
element.closing(info);
if (element instanceof IParent) {
closeChildren(info);
}
this.cache.removeInfo(element);
if (wasVerbose) {
//$NON-NLS-1$
System.out.println(this.cache.toStringFillingRation("-> "));
}
} finally {
JavaModelCache.VERBOSE = wasVerbose;
}
return info;
}
return null;
}
use of org.eclipse.jdt.core.IParent in project eclipse.jdt.ls by eclipse.
the class DocumentSymbolHandler method collectChildren.
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols, IProgressMonitor monitor) throws JavaModelException {
for (IJavaElement element : elements) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (element instanceof IParent) {
collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
}
int type = element.getElementType();
if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
continue;
}
Location location = JDTUtils.toLocation(element);
if (location != null) {
SymbolInformation si = new SymbolInformation();
String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
si.setName(name == null ? element.getElementName() : name);
si.setKind(mapKind(element));
if (JDTUtils.isDeprecated(element)) {
if (preferenceManager.getClientPreferences().isSymbolTagSupported()) {
si.setTags(List.of(SymbolTag.Deprecated));
} else {
si.setDeprecated(true);
}
}
if (element.getParent() != null) {
si.setContainerName(element.getParent().getElementName());
}
location.setUri(ResourceUtils.toClientUri(location.getUri()));
si.setLocation(location);
if (!symbols.contains(si)) {
symbols.add(si);
}
}
}
}
Aggregations