--- a/java.source/src/org/netbeans/api/java/source/ElementUtilities.java +++ a/java.source/src/org/netbeans/api/java/source/ElementUtilities.java @@ -70,8 +70,11 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Names; import com.sun.tools.javadoc.DocEnv; +import java.io.IOException; +import java.net.URL; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; @@ -80,6 +83,8 @@ import java.util.LinkedList; import java.util.List; import java.util.ListIterator; +import java.util.Map; +import java.util.Set; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -96,6 +101,10 @@ import org.netbeans.modules.java.source.builder.ElementsService; import org.netbeans.modules.java.source.JavadocEnv; +import org.netbeans.modules.java.source.tasklist.TasklistSettings.DependencyTracking; +import org.netbeans.modules.java.source.util.FindUsagesUtils; +import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; /** * @@ -536,6 +545,34 @@ return findUnimplementedMethods(impl, impl); } + /** + * Finds all subtypes of given types in all known source roots that depend on the current source root. + * + * @param handles types for which the subtypes should be found + * @return all found subtypes for the given types, classified by source root and original type. null may be returned if current the task is canceled. + * @since 0.59 + */ + public Map, Set>>> findSubTypes(Collection> handles) { + FileObject owner = info.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE).findOwnerRoot(info.getFileObject()); + + if (owner == null) { + return Collections.emptyMap();//TODO: log? + } + + Map, Set>>> result = new HashMap, Set>>>(); + + try { + if (FindUsagesUtils.findUsages(owner.getURL(), new LinkedList>(handles), result, false, true, false, DependencyTracking.ENABLED) == null) { + return null; + } + } catch (IOException ex) { + //should not normally happen: + Exceptions.printStackTrace(ex); + } + + return result; + } + // private implementation --------------------------------------------------