8004657: Add hooks to javac to enable reporting dependency information
Reviewed-by: jjg, mcimadamore
This commit is contained in:
parent
da02d4f3d5
commit
d61f7ca328
@ -159,7 +159,7 @@ public final class JavacTool implements JavaCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
private static void processOptions(Context context,
|
||||
public static void processOptions(Context context,
|
||||
JavaFileManager fileManager,
|
||||
Iterable<String> options)
|
||||
{
|
||||
|
@ -1798,6 +1798,9 @@ public class Resolve {
|
||||
|
||||
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 @@ public class Resolve {
|
||||
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.
|
||||
|
@ -928,6 +928,16 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
}
|
||||
}
|
||||
|
||||
//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 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
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 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user