src/share/classes/com/sun/tools/javac/main/JavaCompiler.java

changeset 1340
99d23c0ef8ee
parent 1230
b14d9583ce92
child 1347
1408af4cd8b0
     1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Sep 25 13:06:58 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Sep 25 13:11:05 2012 -0700
     1.3 @@ -406,10 +406,17 @@
     1.4              ? names.fromString(options.get("failcomplete"))
     1.5              : null;
     1.6  
     1.7 -        shouldStopPolicy =
     1.8 -            options.isSet("shouldStopPolicy")
     1.9 +        shouldStopPolicyIfError =
    1.10 +            options.isSet("shouldStopPolicy") // backwards compatible
    1.11              ? CompileState.valueOf(options.get("shouldStopPolicy"))
    1.12 -            : null;
    1.13 +            : options.isSet("shouldStopPolicyIfError")
    1.14 +            ? CompileState.valueOf(options.get("shouldStopPolicyIfError"))
    1.15 +            : CompileState.INIT;
    1.16 +        shouldStopPolicyIfNoError =
    1.17 +            options.isSet("shouldStopPolicyIfNoError")
    1.18 +            ? CompileState.valueOf(options.get("shouldStopPolicyIfNoError"))
    1.19 +            : CompileState.GENERATE;
    1.20 +
    1.21          if (options.isUnset("oldDiags"))
    1.22              log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
    1.23      }
    1.24 @@ -486,12 +493,20 @@
    1.25      public boolean verboseCompilePolicy;
    1.26  
    1.27      /**
    1.28 -     * Policy of how far to continue processing. null means until first
    1.29 -     * error.
    1.30 +     * Policy of how far to continue compilation after errors have occurred.
    1.31 +     * Set this to minimum CompileState (INIT) to stop as soon as possible
    1.32 +     * after errors.
    1.33       */
    1.34 -    public CompileState shouldStopPolicy;
    1.35 +    public CompileState shouldStopPolicyIfError;
    1.36  
    1.37 -    /** A queue of all as yet unattributed classes.
    1.38 +    /**
    1.39 +     * Policy of how far to continue compilation when no errors have occurred.
    1.40 +     * Set this to maximum CompileState (GENERATE) to perform full compilation.
    1.41 +     * Set this lower to perform partial compilation, such as -proc:only.
    1.42 +     */
    1.43 +    public CompileState shouldStopPolicyIfNoError;
    1.44 +
    1.45 +    /** A queue of all as yet unattributed classes.oLo
    1.46       */
    1.47      public Todo todo;
    1.48  
    1.49 @@ -501,6 +516,7 @@
    1.50  
    1.51      /** Ordered list of compiler phases for each compilation unit. */
    1.52      public enum CompileState {
    1.53 +        INIT(0),
    1.54          PARSE(1),
    1.55          ENTER(2),
    1.56          PROCESS(3),
    1.57 @@ -512,8 +528,11 @@
    1.58          CompileState(int value) {
    1.59              this.value = value;
    1.60          }
    1.61 -        boolean isDone(CompileState other) {
    1.62 -            return value >= other.value;
    1.63 +        boolean isAfter(CompileState other) {
    1.64 +            return value > other.value;
    1.65 +        }
    1.66 +        public static CompileState max(CompileState a, CompileState b) {
    1.67 +            return a.value > b.value ? a : b;
    1.68          }
    1.69          private int value;
    1.70      };
    1.71 @@ -524,7 +543,7 @@
    1.72          private static final long serialVersionUID = 1812267524140424433L;
    1.73          boolean isDone(Env<AttrContext> env, CompileState cs) {
    1.74              CompileState ecs = get(env);
    1.75 -            return ecs != null && ecs.isDone(cs);
    1.76 +            return (ecs != null) && !cs.isAfter(ecs);
    1.77          }
    1.78      }
    1.79      private CompileStates compileStates = new CompileStates();
    1.80 @@ -536,10 +555,10 @@
    1.81      protected Set<JavaFileObject> inputFiles = new HashSet<JavaFileObject>();
    1.82  
    1.83      protected boolean shouldStop(CompileState cs) {
    1.84 -        if (shouldStopPolicy == null)
    1.85 -            return (errorCount() > 0 || unrecoverableError());
    1.86 -        else
    1.87 -            return cs.ordinal() > shouldStopPolicy.ordinal();
    1.88 +        CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError())
    1.89 +            ? shouldStopPolicyIfError
    1.90 +            : shouldStopPolicyIfNoError;
    1.91 +        return cs.isAfter(shouldStopPolicy);
    1.92      }
    1.93  
    1.94      /** The number of errors reported so far.
    1.95 @@ -924,6 +943,18 @@
    1.96      }
    1.97  
    1.98      /**
    1.99 +     * Enter the symbols found in a list of parse trees if the compilation
   1.100 +     * is expected to proceed beyond anno processing into attr.
   1.101 +     * As a side-effect, this puts elements on the "todo" list.
   1.102 +     * Also stores a list of all top level classes in rootClasses.
   1.103 +     */
   1.104 +    public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) {
   1.105 +       if (shouldStop(CompileState.ATTR))
   1.106 +           return List.nil();
   1.107 +        return enterTrees(roots);
   1.108 +    }
   1.109 +
   1.110 +    /**
   1.111       * Enter the symbols found in a list of parse trees.
   1.112       * As a side-effect, this puts elements on the "todo" list.
   1.113       * Also stores a list of all top level classes in rootClasses.
   1.114 @@ -1648,6 +1679,8 @@
   1.115          hasBeenUsed = true;
   1.116          closeables = prev.closeables;
   1.117          prev.closeables = List.nil();
   1.118 +        shouldStopPolicyIfError = prev.shouldStopPolicyIfError;
   1.119 +        shouldStopPolicyIfNoError = prev.shouldStopPolicyIfNoError;
   1.120      }
   1.121  
   1.122      public static void enableLogging() {

mercurial