groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch master updated: minor refactor: remove duplication, improve clarify
Date Sun, 21 Apr 2019 22:02:45 GMT
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


The following commit(s) were added to refs/heads/master by this push:
     new 48f00c9  minor refactor: remove duplication, improve clarify
48f00c9 is described below

commit 48f00c9c9890bf7a175df394adbba14d2502d053
Author: Paul King <paulk@asert.com.au>
AuthorDate: Mon Apr 22 08:02:28 2019 +1000

    minor refactor: remove duplication, improve clarify
---
 .../groovy/classgen/VariableScopeVisitor.java      | 23 ++++++++++------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 508665f..059480a 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -61,7 +61,7 @@ import static java.lang.reflect.Modifier.isFinal;
 import static org.apache.groovy.ast.tools.MethodNodeUtils.getPropertyName;
 
 /**
- * goes through an AST and initializes the scopes
+ * Goes through an AST and initializes the scopes.
  */
 public class VariableScopeVisitor extends ClassCodeVisitorSupport {
 
@@ -207,6 +207,10 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
         return findClassMember(cn.getOuterClass(), name);
     }
 
+    private static boolean isAnonymous(ClassNode node) {
+        return (!node.isEnum() && node instanceof InnerClassNode && ((InnerClassNode)
node).isAnonymous());
+    }
+
     // -------------------------------
     // different Variable based checks
     // -------------------------------
@@ -221,9 +225,8 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
         boolean crossingStaticContext = false;
         while (true) {
             crossingStaticContext = crossingStaticContext || scope.isInStaticContext();
-            Variable var1;
-            var1 = scope.getDeclaredVariable(var.getName());
 
+            Variable var1 = scope.getDeclaredVariable(var.getName());
             if (var1 != null) {
                 var = var1;
                 break;
@@ -268,7 +271,6 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
                     (end.isReferencedClassVariable(name) && end.getDeclaredVariable(name)
== null)) {
                 scope.putReferencedClassVariable(var);
             } else {
-                //var.setClosureSharedVariable(var.isClosureSharedVariable() || inClosure);
                 scope.putReferencedLocalVariable(var);
             }
             scope = scope.getParent();
@@ -411,8 +413,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
         expression.setVariableScope(currentScope);
 
         if (expression.isParameterSpecified()) {
-            Parameter[] parameters = expression.getParameters();
-            for (Parameter parameter : parameters) {
+            for (Parameter parameter : expression.getParameters()) {
                 parameter.setInStaticContext(currentScope.isInStaticContext());
                 if (parameter.hasInitialExpression()) {
                     parameter.getInitialExpression().visit(this);
@@ -460,10 +461,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
 
     public void visitClass(ClassNode node) {
         // AIC are already done, doing them here again will lead to wrong scopes
-        if (node instanceof InnerClassNode) {
-            InnerClassNode in = (InnerClassNode) node;
-            if (in.isAnonymous() && !in.isEnum()) return;
-        }
+        if (isAnonymous(node)) return;
 
         pushState();
 
@@ -480,8 +478,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
     }
 
     /**
-     * Setup the current class node context.
-     * @param node
+     * Sets the current class node context.
      */
     public void prepareVisit(ClassNode node) {
         currentClass = node;
@@ -493,7 +490,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
         inConstructor = isConstructor;
         node.setVariableScope(currentScope);
         visitAnnotations(node);
-        
+
         // GROOVY-2156
         Parameter[] parameters = node.getParameters();
         for (Parameter parameter : parameters) {


Mime
View raw message