OpenJDK / amber / amber
changeset 14957:ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
Reviewed-by: jjg, mcimadamore
author | ohrstrom |
---|---|
date | Tue, 18 Dec 2012 10:23:40 +0100 |
parents | 185bd7c693d8 |
children | cffa218ca1ed |
files | langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java |
diffstat | 3 files changed, 40 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Dec 18 00:24:54 2012 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Tue Dec 18 10:23:40 2012 +0100 @@ -159,7 +159,7 @@ } } - private static void processOptions(Context context, + public static void processOptions(Context context, JavaFileManager fileManager, Iterable<String> options) {
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Dec 18 00:24:54 2012 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Dec 18 10:23:40 2012 +0100 @@ -1798,6 +1798,9 @@ if ((kind & TYP) != 0) { sym = findType(env, name); + if (sym.kind==TYP) { + reportDependence(env.enclClass.sym, sym); + } if (sym.exists()) return sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym; } @@ -1806,6 +1809,14 @@ else return bestSoFar; } + /** Report dependencies. + * @param from The enclosing class sym + * @param to The found identifier that the class depends on. + */ + public void reportDependence(Symbol from, Symbol to) { + // Override if you want to collect the reported dependencies. + } + /** Find an identifier in a package which matches a specified kind set. * @param env The current environment. * @param name The identifier's name.
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Dec 18 00:24:54 2012 -0800 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Dec 18 10:23:40 2012 +0100 @@ -928,6 +928,16 @@ } } + /** + * Set needRootClasses to true, in JavaCompiler subclass constructor + * that want to collect public apis of classes supplied on the command line. + */ + protected boolean needRootClasses = false; + + /** + * The list of classes explicitly supplied on the command line for compilation. + * Not always populated. + */ private List<JCClassDecl> rootClasses; /** @@ -984,9 +994,10 @@ } } - //If generating source, remember the classes declared in - //the original compilation units listed on the command line. - if (sourceOutput || stubOutput) { + // If generating source, or if tracking public apis, + // then remember the classes declared in + // the original compilation units listed on the command line. + if (needRootClasses || sourceOutput || stubOutput) { ListBuffer<JCClassDecl> cdefs = lb(); for (JCCompilationUnit unit : roots) { for (List<JCTree> defs = unit.defs; @@ -1247,6 +1258,12 @@ attr.postAttr(env.tree); } compileStates.put(env, CompileState.ATTR); + if (rootClasses != null && rootClasses.contains(env.enclClass)) { + // This was a class that was explicitly supplied for compilation. + // If we want to capture the public api of this class, + // then now is a good time to do it. + reportPublicApi(env.enclClass.sym); + } } finally { log.useSource(prev); @@ -1255,6 +1272,14 @@ return env; } + /** Report the public api of a class that was supplied explicitly for compilation, + * for example on the command line to javac. + * @param sym The symbol of the class. + */ + public void reportPublicApi(ClassSymbol sym) { + // Override to collect the reported public api. + } + /** * Perform dataflow checks on attributed parse trees. * These include checks for definite assignment and unreachable statements.