--- 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.