groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Add `isPresent` method to `Groovydoc`
Date Tue, 20 Mar 2018 09:20:59 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 9b6f86c8f -> 73b094291


Add `isPresent` method to `Groovydoc`


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

Branch: refs/heads/master
Commit: 73b094291ab155f1453fe309b4196f03e47016f1
Parents: 9b6f86c
Author: sunlan <sunlan@apache.org>
Authored: Tue Mar 20 17:20:53 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Mar 20 17:20:53 2018 +0800

----------------------------------------------------------------------
 .../groovy/groovy/lang/groovydoc/Groovydoc.java | 25 ++++++++++++++++----
 .../parser/antlr4/GroovyParserTest.groovy       | 14 +++++------
 2 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/73b09429/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 93f33d4..5923cfa 100644
--- a/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
+++ b/src/main/groovy/groovy/lang/groovydoc/Groovydoc.java
@@ -29,16 +29,25 @@ import java.util.Objects;
 public class Groovydoc {
     private final String content;
     private List<GroovydocTag> tagList = Collections.emptyList();
-    private final GroovydocHolder holder;
-    public static final Groovydoc EMPTY_GROOVYDOC = new Groovydoc("", (GroovydocHolder) null);
+    private GroovydocHolder holder;
+    public static final Groovydoc EMPTY_GROOVYDOC = new Groovydoc("") {
+        @Override
+        public List<GroovydocTag> getTagList() {
+            return Collections.emptyList();
+        }
+    };
 
-    public Groovydoc(String content, GroovydocHolder groovydocHolder) {
+    private Groovydoc(String content) {
         this.content = content;
+    }
+
+    public Groovydoc(String content, GroovydocHolder groovydocHolder) {
+        this(content);
         this.holder = groovydocHolder;
     }
 
     public Groovydoc(final String content, final AnnotatedElement annotatedElement) {
-        this.content = content;
+        this(content);
         this.holder = new GroovydocHolder<AnnotatedElement>() {
             @Override
             public Groovydoc getGroovydoc() {
@@ -53,6 +62,14 @@ public class Groovydoc {
     }
 
     /**
+     * Tests if groovydoc is present
+     * @return {@code true} if groovydoc is present
+     */
+    public boolean isPresent() {
+        return EMPTY_GROOVYDOC != this;
+    }
+
+    /**
      * Get the content of groovydoc
      * @return the text content
      */

http://git-wip-us.apache.org/repos/asf/groovy/blob/73b09429/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 6638941..a4a12e3 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -53,11 +53,11 @@ class GroovyParserTest extends GroovyTestCase {
         assert classes[0].groovydoc.content.replaceAll(/\r?\n/, '')            == '/** *
test class Comments */'
         assert classes[0].fields[0].groovydoc.content.replaceAll(/\r?\n/, '')  == '/**  
  * test Comments.SOME_VAR     */'
         assert classes[0].fields[1].groovydoc.content.replaceAll(/\r?\n/, '')  == '/**  
  * test Comments.SOME_VAR2     */'
-        assert classes[0].fields[2].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
-        assert classes[0].fields[3].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !classes[0].fields[2].groovydoc.isPresent()
+        assert !classes[0].fields[3].groovydoc.isPresent()
         assert classes[0].declaredConstructors[0].groovydoc.content.replaceAll(/\r?\n/, '')
== '/**     * test Comments.constructor1     */'
         assert classes[0].methods[0].groovydoc.content.replaceAll(/\r?\n/, '') == '/**  
  * test Comments.m1     */'
-        assert classes[0].methods[1].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !classes[0].methods[1].groovydoc.isPresent()
         assert classes[0].methods[2].groovydoc.content.replaceAll(/\r?\n/, '') == '/**  
  * test Comments.m3     */'
 
         assert classes[1].groovydoc.content.replaceAll(/\r?\n/, '')            == '/**  
  * test class InnerClazz     */'
@@ -70,14 +70,14 @@ class GroovyParserTest extends GroovyTestCase {
         assert classes[2].fields[0].groovydoc.content.replaceAll(/\r?\n/, '')  == '/**  
      * InnerEnum.NEW         */'
         assert classes[2].fields[1].groovydoc.content.replaceAll(/\r?\n/, '')  == '/**  
      * InnerEnum.OLD         */'
 
-        assert classes[3].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !classes[3].groovydoc.isPresent()
 
-        assert classes[4].fields[0].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !classes[4].fields[0].groovydoc.isPresent()
 
-        assert classes[5].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !classes[5].groovydoc.isPresent()
 
         assert methods[0].groovydoc.content.replaceAll(/\r?\n/, '') == '/** * test someScriptMethod1
*/'
-        assert methods[1].groovydoc == groovy.lang.groovydoc.Groovydoc.EMPTY_GROOVYDOC
+        assert !methods[1].groovydoc.isPresent()
     }
 
     void "test groovy core - PackageDeclaration"() {


Mime
View raw message