groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Refine compile-time and runtime groovydoc
Date Tue, 20 Mar 2018 05:36:48 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 90cda8cf0 -> 47927ad2b


Refine compile-time and runtime groovydoc

(cherry picked from commit 1263867)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/47927ad2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/47927ad2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/47927ad2

Branch: refs/heads/GROOVY_2_6_X
Commit: 47927ad2bb3447e7a6bf4c37620cc5f1d8753ab0
Parents: 90cda8c
Author: sunlan <sunlan@apache.org>
Authored: Tue Mar 20 13:34:41 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Mar 20 13:36:42 2018 +0800

----------------------------------------------------------------------
 .../groovy/groovy/lang/groovydoc/Groovydoc.java    |  4 +++-
 .../org/codehaus/groovy/ast/AnnotatedNode.java     | 17 ++++++++++++++++-
 .../java/org/codehaus/groovy/ast/ClassNode.java    | 12 +-----------
 .../java/org/codehaus/groovy/ast/FieldNode.java    | 14 +-------------
 .../java/org/codehaus/groovy/ast/MethodNode.java   | 15 +--------------
 .../groovy/runtime/DefaultGroovyMethods.java       |  4 +++-
 6 files changed, 25 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java b/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
index d7d4204..8b10050 100644
--- a/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
+++ b/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
@@ -19,6 +19,7 @@
 package groovy.lang.groovydoc;
 
 import java.lang.reflect.AnnotatedElement;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 
@@ -27,8 +28,9 @@ import java.util.Objects;
  */
 public class Groovydoc {
     private final String content;
-    private List<GroovydocTag> tagList;
+    private List<GroovydocTag> tagList = new LinkedList<>();
     private final GroovydocHolder holder;
+    public static final Groovydoc EMPTY_GROOVYDOC = new Groovydoc("", (GroovydocHolder) null);
 
     public Groovydoc(String content, GroovydocHolder groovydocHolder) {
         this.content = content;

http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/java/org/codehaus/groovy/ast/AnnotatedNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/AnnotatedNode.java b/src/main/java/org/codehaus/groovy/ast/AnnotatedNode.java
index ab5f2eb..0992455 100644
--- a/src/main/java/org/codehaus/groovy/ast/AnnotatedNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/AnnotatedNode.java
@@ -18,6 +18,9 @@
  */
 package org.codehaus.groovy.ast;
 
+import groovy.lang.groovydoc.Groovydoc;
+import groovy.lang.groovydoc.GroovydocHolder;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -27,7 +30,7 @@ import java.util.List;
  *
  * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
  */
-public class AnnotatedNode extends ASTNode {
+public class AnnotatedNode extends ASTNode implements GroovydocHolder<AnnotatedNode>
{
     private List<AnnotationNode> annotations = Collections.emptyList();
     private boolean synthetic;
     ClassNode declaringClass;
@@ -109,4 +112,16 @@ public class AnnotatedNode extends ASTNode {
     public void setHasNoRealSourcePosition(boolean value) {
         this.hasNoRealSourcePositionFlag = value;
     }
+
+    @Override
+    public Groovydoc getGroovydoc() {
+        Groovydoc groovydoc = this.<Groovydoc>getNodeMetaData(DOC_COMMENT);
+
+        return null == groovydoc ? Groovydoc.EMPTY_GROOVYDOC : groovydoc;
+    }
+
+    @Override
+    public AnnotatedNode getInstance() {
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/java/org/codehaus/groovy/ast/ClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index d6ddb83..a22d9f9 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -105,7 +105,7 @@ import java.util.Set;
  *
  * @see org.codehaus.groovy.ast.ClassHelper
  */
-public class ClassNode extends AnnotatedNode implements Opcodes, GroovydocHolder<ClassNode>
{
+public class ClassNode extends AnnotatedNode implements Opcodes {
 
     private static class MapOfLists {
         private Map<Object, List<MethodNode>> map;
@@ -1521,14 +1521,4 @@ public class ClassNode extends AnnotatedNode implements Opcodes, GroovydocHolder
     public String getText() {
         return getName();
     }
-
-    @Override
-    public Groovydoc getGroovydoc() {
-        return this.<Groovydoc>getNodeMetaData(DOC_COMMENT);
-    }
-
-    @Override
-    public ClassNode getInstance() {
-        return this;
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/java/org/codehaus/groovy/ast/FieldNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/FieldNode.java b/src/main/java/org/codehaus/groovy/ast/FieldNode.java
index 18dd09e..6799a14 100644
--- a/src/main/java/org/codehaus/groovy/ast/FieldNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/FieldNode.java
@@ -18,8 +18,6 @@
  */
 package org.codehaus.groovy.ast;
 
-import groovy.lang.groovydoc.Groovydoc;
-import groovy.lang.groovydoc.GroovydocHolder;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.objectweb.asm.Opcodes;
 
@@ -30,7 +28,7 @@ import java.lang.reflect.Field;
  *
  * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
  */
-public class FieldNode extends AnnotatedNode implements Opcodes, Variable, GroovydocHolder<FieldNode>
{
+public class FieldNode extends AnnotatedNode implements Opcodes, Variable {
 
     private String name;
     private int modifiers;
@@ -200,14 +198,4 @@ public class FieldNode extends AnnotatedNode implements Opcodes, Variable,
Groov
         declaringClass.renameField(this.name, name);
         this.name = name;
     }
-
-    @Override
-    public Groovydoc getGroovydoc() {
-        return this.<Groovydoc>getNodeMetaData(DOC_COMMENT);
-    }
-
-    @Override
-    public FieldNode getInstance() {
-        return this;
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/java/org/codehaus/groovy/ast/MethodNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/MethodNode.java b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
index a43286f..902502e 100644
--- a/src/main/java/org/codehaus/groovy/ast/MethodNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/MethodNode.java
@@ -18,8 +18,6 @@
  */
 package org.codehaus.groovy.ast;
 
-import groovy.lang.groovydoc.Groovydoc;
-import groovy.lang.groovydoc.GroovydocHolder;
 import org.apache.groovy.ast.tools.MethodNodeUtils;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
@@ -33,8 +31,7 @@ import java.util.List;
  * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
  * @author Hamlet D'Arcy
  */
-public class MethodNode extends AnnotatedNode implements Opcodes, GroovydocHolder<MethodNode>
{
-
+public class MethodNode extends AnnotatedNode implements Opcodes {
     public static final String SCRIPT_BODY_METHOD_KEY = "org.codehaus.groovy.ast.MethodNode.isScriptBody";
     private final String name;
     private int modifiers;
@@ -271,14 +268,4 @@ public class MethodNode extends AnnotatedNode implements Opcodes, GroovydocHolde
         String parms = AstToTextHelper.getParametersText(parameters);
         return AstToTextHelper.getModifiersText(modifiers) + " " + retType + " " + name +
"(" + parms + ") " + exceptionTypes + " { ... }";
     }
-
-    @Override
-    public Groovydoc getGroovydoc() {
-        return this.<Groovydoc>getNodeMetaData(DOC_COMMENT);
-    }
-
-    @Override
-    public MethodNode getInstance() {
-        return this;
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/47927ad2/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 274ed8c..d8b7950 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -167,6 +167,8 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC;
+
 /**
  * This class defines new groovy methods which appear on normal JDK
  * classes inside the Groovy environment. Static methods are used with the
@@ -19534,7 +19536,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
         Groovydoc groovydocAnnotation = holder.<Groovydoc>getAnnotation(Groovydoc.class);
 
         return null == groovydocAnnotation
-                    ? null
+                    ? EMPTY_GROOVYDOC
                     : new groovy.lang.groovydoc.Groovydoc(groovydocAnnotation.value(), holder);
     }
 }


Mime
View raw message