On Fri, Nov 15, 2013 at 11:56 AM, Matthew Dempsky <[email protected]>wrote:
> If I first collapse all source files into a single vertex, then our 502
> packages still form 394 SCCs.
>
Oops, that should be "collapse all source files *within a Java package*
into a single vertex". (Collapsing all source files should of course yield
1 SCC. ;))
Also, for anyone interested in replicating my results on their own,
attached is my simple Tool.java program. Invoke it like:
TOOLS=$(dirname $(which javac))/../lib/tools.jar
DEPS=...colon separated list of GWT_TOOLS jars to compile against...
SRCS=$(find user/src user/test dev/core/src dev/codeserver/java
dev/core/test dev/core/super '(' -name super -o -name intrinsic ')' -prune
-o -name '*.java' -print)
javac -cp ${TOOLS} Tool.java
java -cp ${TOOLS} Tool -cp ${DEPS} ${SRCS}
(I haven't actually tried this; I'm using Google's internal BUILD system
for simplicity, but the above should reasonably approximate what I'm doing.)
The output is a list of "file1: file2" lines, where file1 makes some
mention of a symbol defined in file2. I've then been post processing with
Python to do SCC analysis.
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeInfo;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class Tool {
public static void main(String[] args) throws Exception {
List<String> argv = Arrays.asList(args);
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null);
JavacTask task = (JavacTask) jc.getTask(null, fm, null, argv.subList(0, 2), null,
fm.getJavaFileObjectsFromStrings(argv.subList(2, argv.size())));
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
for (CompilationUnitTree tree : trees) {
final Set<String> refs = new HashSet<String>();
tree.accept(new TreeScanner<Void, Void>() {
@Override
public Void scan(Tree node, Void v) {
// Scan recurses until it hits null.
// Not all tree nodes have associated symbols.
// Package symbols don't have an enclosing class.
// Builtin symbols (e.g., Array) have no source or class file.
if (node != null) {
Symbol sym = TreeInfo.symbol((JCTree) node);
if (sym != null) {
ClassSymbol enclSym = sym.enclClass();
if (enclSym != null) {
if (enclSym.classfile != null) {
refs.add(enclSym.classfile.getName());
} else if (enclSym.sourcefile != null) {
refs.add(enclSym.sourcefile.getName());
}
}
}
}
return super.scan(node, v);
}
}, null);
String fn = tree.getSourceFile().getName();
for (String ref : refs) {
System.out.println(fn + ": " + ref);
}
}
}
}