groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/02: Remove redundant fields and reduce the visibility of lazy nodes
Date Mon, 23 Dec 2019 00:30:19 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 0820faeba736a376194cd9a80835f8d6813026f9
Author: Daniel.Sun <realbluesun@hotmail.com>
AuthorDate: Mon Dec 23 08:03:29 2019 +0800

    Remove redundant fields and reduce the visibility of lazy nodes
---
 .../org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java    | 7 ++-----
 .../java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java     | 7 ++-----
 .../java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java    | 7 ++-----
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
index a4b08b4..50bef15 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyConstructorNode.java
@@ -41,23 +41,20 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyConstructorNode extends ConstructorNode {
+class LazyConstructorNode extends ConstructorNode {
     private final Supplier<ConstructorNode> constructorNodeSupplier;
     private ConstructorNode delegate;
-    private boolean initialized;
 
     public LazyConstructorNode(Supplier<ConstructorNode> constructorNodeSupplier) {
         this.constructorNodeSupplier = constructorNodeSupplier;
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = constructorNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
         if (null != declaringClass) delegate.setDeclaringClass(declaringClass);
-
-        initialized = true;
     }
 
     @Override
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
index 4dea774..94d2ed5 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyFieldNode.java
@@ -38,10 +38,9 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyFieldNode extends FieldNode {
+class LazyFieldNode extends FieldNode {
     private final Supplier<FieldNode> fieldNodeSupplier;
     private FieldNode delegate;
-    private boolean initialized;
 
     private String name;
 
@@ -51,7 +50,7 @@ public class LazyFieldNode extends FieldNode {
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = fieldNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
@@ -59,8 +58,6 @@ public class LazyFieldNode extends FieldNode {
 
         ClassNode owner = super.getOwner();
         if (null != owner) delegate.setOwner(owner);
-
-        initialized = true;
     }
 
     @Override
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
index 2cd8fd0..11f12da 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/LazyMethodNode.java
@@ -41,10 +41,9 @@ import java.util.function.Supplier;
  *
  * @since 2.5.9
  */
-public class LazyMethodNode extends MethodNode {
+class LazyMethodNode extends MethodNode {
     private final Supplier<MethodNode> methodNodeSupplier;
     private MethodNode delegate;
-    private boolean initialized;
 
     private String name;
 
@@ -54,13 +53,11 @@ public class LazyMethodNode extends MethodNode {
     }
 
     private void init() {
-        if (initialized) return;
+        if (null != delegate) return;
         delegate = methodNodeSupplier.get();
 
         ClassNode declaringClass = super.getDeclaringClass();
         if (null != declaringClass) delegate.setDeclaringClass(declaringClass);
-
-        initialized = true;
     }
 
     @Override


Mime
View raw message