From: Joshua Maurice on 27 May 2010 23:44 This is probably one of the last updates for a while. It appears that the "magic code" which I wanted from the start is simply the following. When you transitively close the dependencies this gives over super types, I think that it is sufficient to do an incrementally correct, incremental, cascading rebuild with possible early termination. At least, the tests I have thus far tell me so. package com.informatica.devops.jicb.incr_java; import java.util.HashSet; import java.util.Set; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Tree; import com.sun.source.util.TreeScanner; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeInfo; public class CompileDependencies { //must call this after JavacTask.analyze to get useful information public static Set<String> get(final CompilationUnitTree tree) { final Visitor visitor = new Visitor(); visitor.scan(tree, null); return visitor.fullNamesOfAllFoundTypes; } private static class Visitor extends TreeScanner<Void, Void> { public final Set<String> fullNamesOfAllFoundTypes = new HashSet<String>(); @Override public Void scan(Tree node, Void v) { if (node != null) { Element ele = TreeInfo.symbol((JCTree)node); for ( ; ele != null; ele = ele.getEnclosingElement()) { final ElementKind kind = ele.getKind(); if (ElementKind.CLASS == kind || ElementKind.INTERFACE == kind || ElementKind.ANNOTATION_TYPE == kind || ElementKind.ENUM == kind) { fullNamesOfAllFoundTypes.add(ele.toString()); } } } super.scan(node, null); return null; } } } |