-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqScanForClasses
-
find the ClassPath on which the subtypes should be found. Use e.g. ClassPath.getClassPath(<file>, ClassPath.SOURCE)
-
if the supertype is given as a FQN, convert to ElementHandle<TypeElement> via ElementHandle.create inside a Task or CancellableTask.
All subtypes of a given type on a given ClassPath can be found using ClassIndex. As ClassIndex contains only direct subtypes, the indirect subtypes need to be found on the client side:
private Set<ElementHandle<TypeElement>> findAllSubTypes(ClassPath on, ElementHandle<TypeElement> of) {
ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, on);
List<ElementHandle<TypeElement>> todo = new LinkedList<ElementHandle<TypeElement>>(of);
Set<ElementHandle<TypeElement>> result = new HashSet<ElementHandle<TypeElement>>();
while (!todo.isEmpty()) {
//TODO: if cancellable, check for cancel here
ElementHandle<TypeElement> curr = todo.remove(0);
result.add(curr);
Set<ElementHandle<TypeElement>> typeElements = cpInfo.getClassIndex().getElements(eh, EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.of(ClassIndex.SearchScope.SOURCE));
if (typeElements != null) { //can be null for cancellable tasks
todo.addAll(typeElements);
}
}
return result;
}
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqScanForClasses , that was last modified by NetBeans user Jlahoda on 2011-12-15T08:29:15Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.