提交 54641c7a 编写于 作者: J jjg

7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error

Reviewed-by: mcimadamore
上级 7a8667bf
......@@ -406,10 +406,17 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
? names.fromString(options.get("failcomplete"))
: null;
shouldStopPolicy =
options.isSet("shouldStopPolicy")
shouldStopPolicyIfError =
options.isSet("shouldStopPolicy") // backwards compatible
? CompileState.valueOf(options.get("shouldStopPolicy"))
: null;
: options.isSet("shouldStopPolicyIfError")
? CompileState.valueOf(options.get("shouldStopPolicyIfError"))
: CompileState.INIT;
shouldStopPolicyIfNoError =
options.isSet("shouldStopPolicyIfNoError")
? CompileState.valueOf(options.get("shouldStopPolicyIfNoError"))
: CompileState.GENERATE;
if (options.isUnset("oldDiags"))
log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
}
......@@ -486,12 +493,20 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
public boolean verboseCompilePolicy;
/**
* Policy of how far to continue processing. null means until first
* error.
* Policy of how far to continue compilation after errors have occurred.
* Set this to minimum CompileState (INIT) to stop as soon as possible
* after errors.
*/
public CompileState shouldStopPolicy;
public CompileState shouldStopPolicyIfError;
/** A queue of all as yet unattributed classes.
/**
* Policy of how far to continue compilation when no errors have occurred.
* Set this to maximum CompileState (GENERATE) to perform full compilation.
* Set this lower to perform partial compilation, such as -proc:only.
*/
public CompileState shouldStopPolicyIfNoError;
/** A queue of all as yet unattributed classes.oLo
*/
public Todo todo;
......@@ -501,6 +516,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
/** Ordered list of compiler phases for each compilation unit. */
public enum CompileState {
INIT(0),
PARSE(1),
ENTER(2),
PROCESS(3),
......@@ -512,8 +528,11 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
CompileState(int value) {
this.value = value;
}
boolean isDone(CompileState other) {
return value >= other.value;
boolean isAfter(CompileState other) {
return value > other.value;
}
public static CompileState max(CompileState a, CompileState b) {
return a.value > b.value ? a : b;
}
private int value;
};
......@@ -524,7 +543,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
private static final long serialVersionUID = 1812267524140424433L;
boolean isDone(Env<AttrContext> env, CompileState cs) {
CompileState ecs = get(env);
return ecs != null && ecs.isDone(cs);
return (ecs != null) && !cs.isAfter(ecs);
}
}
private CompileStates compileStates = new CompileStates();
......@@ -536,10 +555,10 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>();
protected boolean shouldStop(CompileState cs) {
if (shouldStopPolicy == null)
return (errorCount() > 0 || unrecoverableError());
else
return cs.ordinal() > shouldStopPolicy.ordinal();
CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError())
? shouldStopPolicyIfError
: shouldStopPolicyIfNoError;
return cs.isAfter(shouldStopPolicy);
}
/** The number of errors reported so far.
......@@ -923,6 +942,18 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
return trees.toList();
}
/**
* Enter the symbols found in a list of parse trees if the compilation
* is expected to proceed beyond anno processing into attr.
* As a side-effect, this puts elements on the "todo" list.
* Also stores a list of all top level classes in rootClasses.
*/
public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) {
if (shouldStop(CompileState.ATTR))
return List.nil();
return enterTrees(roots);
}
/**
* Enter the symbols found in a list of parse trees.
* As a side-effect, this puts elements on the "todo" list.
......@@ -1648,6 +1679,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
hasBeenUsed = true;
closeables = prev.closeables;
prev.closeables = List.nil();
shouldStopPolicyIfError = prev.shouldStopPolicyIfError;
shouldStopPolicyIfNoError = prev.shouldStopPolicyIfNoError;
}
public static void enableLogging() {
......
......@@ -97,11 +97,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
private final boolean printRounds;
private final boolean verbose;
private final boolean lint;
private final boolean procOnly;
private final boolean fatalErrors;
private final boolean werror;
private final boolean showResolveErrors;
private boolean foundTypeProcessors;
private final JavacFiler filer;
private final JavacMessager messager;
......@@ -167,12 +165,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
printRounds = options.isSet(XPRINTROUNDS);
verbose = options.isSet(VERBOSE);
lint = Lint.instance(context).isEnabled(PROCESSING);
procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
if (options.isSet(PROC, "only") || options.isSet(XPRINT)) {
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.shouldStopPolicyIfNoError = CompileState.PROCESS;
}
fatalErrors = options.isSet("fatalEnterError");
showResolveErrors = options.isSet("showResolveErrors");
werror = options.isSet(WERROR);
platformAnnotations = initPlatformAnnotations();
foundTypeProcessors = false;
// Initialize services before any processors are initialized
// in case processors use them.
......@@ -462,7 +462,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
* State about how a processor has been used by the tool. If a
* processor has been used on a prior round, its process method is
* called on all subsequent rounds, perhaps with an empty set of
* annotations to process. The {@code annotatedSupported} method
* annotations to process. The {@code annotationSupported} method
* caches the supported annotation information from the first (and
* only) getSupportedAnnotationTypes call to the processor.
*/
......@@ -882,7 +882,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
/** Create the compiler to be used for the final compilation. */
JavaCompiler finalCompiler(boolean errorStatus) {
try {
JavaCompiler c = JavaCompiler.instance(nextContext());
Context nextCtx = nextContext();
JavacProcessingEnvironment.this.context = nextCtx;
JavaCompiler c = JavaCompiler.instance(nextCtx);
c.log.nwarnings += compiler.log.nwarnings;
if (errorStatus) {
c.log.nerrors += compiler.log.nerrors;
......@@ -1021,7 +1023,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
}
/** Get the context for the next round of processing.
* Important values are propogated from round to round;
* Important values are propagated from round to round;
* other values are implicitly reset.
*/
private Context nextContext() {
......@@ -1190,14 +1192,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return compiler;
}
if (procOnly && !foundTypeProcessors) {
compiler.todo.clear();
} else {
if (procOnly && foundTypeProcessors)
compiler.shouldStopPolicy = CompileState.FLOW;
compiler.enterTrees(roots);
}
compiler.enterTreesIfNeeded(roots);
return compiler;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册