You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/05/17 02:45:11 UTC

[groovy] 02/05: minor refactor: formatting and style

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 1fd7f048226384f10a2635f8129c02b8937e57f3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri May 17 11:03:01 2019 +1000

    minor refactor: formatting and style
---
 .../codehaus/groovy/control/ProcessingUnit.java    | 53 ++++++++++------------
 1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
index 34c9439..f4509cd 100644
--- a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
@@ -32,10 +32,10 @@ public abstract class ProcessingUnit {
     /**
      * The current phase
      */
-    protected int phase;
+    protected int phase = Phases.INITIALIZATION;
 
     /**
-     * Set true if phase is finished
+     * True if phase is finished
      */
     protected boolean phaseComplete;
 
@@ -55,10 +55,9 @@ public abstract class ProcessingUnit {
     protected ErrorCollector errorCollector;
 
     /**
-     * Initialize the ProcessingUnit to the empty state.
+     * Initializes the ProcessingUnit to the empty state.
      */
     public ProcessingUnit(final CompilerConfiguration configuration, final GroovyClassLoader classLoader, final ErrorCollector errorCollector) {
-        this.phase = Phases.INITIALIZATION;
         setClassLoader(classLoader);
         configure(configuration != null ? configuration : CompilerConfiguration.DEFAULT);
         this.errorCollector = errorCollector != null ? errorCollector : new ErrorCollector(getConfiguration());
@@ -90,47 +89,44 @@ public abstract class ProcessingUnit {
      * Sets the class loader for use by this ProcessingUnit.
      */
     public void setClassLoader(final GroovyClassLoader loader) {
-        // Classloaders should only be created inside a doPrivileged block in case
-        // this method is invoked by code that does not have security permissions
+        // ClassLoaders should only be created inside a doPrivileged block in case
+        // this method is invoked by code that does not have security permissions.
         this.classLoader = loader != null ? loader : AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
             public GroovyClassLoader run() {
                 ClassLoader parent = Thread.currentThread().getContextClassLoader();
                 if (parent == null) parent = ProcessingUnit.class.getClassLoader();
-                return new GroovyClassLoader(parent, configuration);
+                return new GroovyClassLoader(parent, getConfiguration());
             }
         });
     }
 
     /**
+     * Errors found during the compilation should be reported through the ErrorCollector.
+     */
+    public ErrorCollector getErrorCollector() {
+        return errorCollector;
+    }
+
+    /**
      * Returns the current phase.
      */
     public int getPhase() {
-        return this.phase;
+        return phase;
     }
 
     /**
      * Returns the description for the current phase.
      */
     public String getPhaseDescription() {
-        return Phases.getDescription(this.phase);
+        return Phases.getDescription(phase);
     }
 
-    /**
-     * Errors found during the compilation should be reported through the ErrorCollector.
-     *
-     * @return the ErrorCollector for this ProcessingUnit
-     */
-    public ErrorCollector getErrorCollector() {
-        return errorCollector;
+    public boolean isPhaseComplete() {
+        return phaseComplete;
     }
 
-    //---------------------------------------------------------------------------
-    // PROCESSING
-
-
     /**
-     * Marks the current phase complete and processes any
-     * errors.
+     * Marks the current phase complete and processes any errors.
      */
     public void completePhase() throws CompilationFailedException {
         errorCollector.failIfErrors();
@@ -138,23 +134,20 @@ public abstract class ProcessingUnit {
     }
 
     /**
-     * A synonym for <code>gotoPhase( phase + 1 )</code>.
+     * A synonym for <code>gotoPhase(getPhase() + 1)</code>.
      */
     public void nextPhase() throws CompilationFailedException {
-        gotoPhase(this.phase + 1);
+        gotoPhase(phase + 1);
     }
 
     /**
-     * Wraps up any pending operations for the current phase
-     * and switches to the next phase.
+     * Wraps up any pending operations for the current phase and switches to the given phase.
      */
     public void gotoPhase(int phase) throws CompilationFailedException {
-        if (!this.phaseComplete) {
+        if (!phaseComplete) {
             completePhase();
         }
-
         this.phase = phase;
-        this.phaseComplete = false;
+        phaseComplete = false;
     }
-
 }