groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Avoid compiling regex repeatedly and update javadoc
Date Fri, 07 Dec 2018 17:26:47 GMT
Repository: groovy
Updated Branches:
  refs/heads/master ab0fc8133 -> 59efbe72a


Avoid compiling regex repeatedly and update javadoc


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

Branch: refs/heads/master
Commit: 59efbe72a7ec88e032f2f0f97fbc0f11f5afab50
Parents: ab0fc81
Author: Daniel Sun <sunlan@apache.org>
Authored: Sat Dec 8 01:24:57 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Sat Dec 8 01:26:47 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/Groovydoc.java            |  3 ++-
 .../apache/groovy/parser/antlr4/GroovydocManager.java | 14 ++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/59efbe72/src/main/groovy/groovy/lang/Groovydoc.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Groovydoc.java b/src/main/groovy/groovy/lang/Groovydoc.java
index 7327913..932b993 100644
--- a/src/main/groovy/groovy/lang/Groovydoc.java
+++ b/src/main/groovy/groovy/lang/Groovydoc.java
@@ -28,7 +28,8 @@ import java.lang.annotation.Target;
  * An annotation to hold the groovydoc for the annotated element at runtime, we call it "Runtime
Groovydoc".
  * Runtime Groovydoc is a bit like Python's Documentation Strings and will be useful for
IDE and developers who set a high value on documentations.
  *
- * The usage is very simple, just place @Groovydoc at the beginning of the content of groovydoc,
then the new parser Parrot will attach the annotation Groovydoc automatically
+ * The usage is very simple, just place @ at the beginning of the content of groovydoc, i.e.
starts with /**@,
+ * then the new parser Parrot will attach the annotation Groovydoc automatically
  *
  * @since 3.0.0
  */

http://git-wip-us.apache.org/repos/asf/groovy/blob/59efbe72/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
index c91b96f..ea73475 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/GroovydocManager.java
@@ -31,7 +31,9 @@ import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 
 import java.util.List;
+import java.util.regex.Pattern;
 
+import static org.apache.groovy.parser.antlr4.util.StringUtils.matches;
 import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
 
 /**
@@ -42,7 +44,8 @@ import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
  */
 public class GroovydocManager {
     public static final String DOC_COMMENT = GroovydocHolder.DOC_COMMENT; // keys for meta
data
-    private static final String DOC_COMMENT_PREFIX = "/**";
+    private static final String GROOVYDOC_PREFIX = "/**";
+    private static final String RUNTIME_GROOVYDOC_PREFIX = GROOVYDOC_PREFIX + "@";
     private static final String TRUE_STR = "true";
 
     @Deprecated
@@ -52,9 +55,8 @@ public class GroovydocManager {
     private static final String ATTACH_RUNTIME_GROOVYDOC = "groovy.attach.runtime.groovydoc";
     private static final boolean ATTACHING_RUNTIME_GROOVYDOC_ENABLED;
     private static final String VALUE = "value";
-    private static final String RUNTIME_GROOVYDOC_PATTERN = "(?s)/[*][*]@\\s+.*?[*]/";
-
     private static final GroovydocManager INSTANCE = new GroovydocManager();
+    private static final Pattern SPACES_PATTERN = Pattern.compile("\\s+");
 
     static {
         ATTACHING_GROOVYDOC_ENABLED = isFeatureEnabled(ATTACH_GROOVYDOC) || isFeatureEnabled(EXTRACT_DOC_COMMENT);
@@ -120,7 +122,7 @@ public class GroovydocManager {
             return;
         }
 
-        if (!(ATTACHING_RUNTIME_GROOVYDOC_ENABLED || docCommentNodeText.matches(RUNTIME_GROOVYDOC_PATTERN)))
{
+        if (!(ATTACHING_RUNTIME_GROOVYDOC_ENABLED || docCommentNodeText.startsWith(RUNTIME_GROOVYDOC_PREFIX)))
{
             return;
         }
 
@@ -183,11 +185,11 @@ public class GroovydocManager {
             for (int i = nlListSize - 1; i >= 0; i--) {
                 String text = nlList.get(i).getText();
 
-                if (text.matches("\\s+")) {
+                if (matches(text, SPACES_PATTERN)) {
                     continue;
                 }
 
-                if (text.startsWith(DOC_COMMENT_PREFIX)) {
+                if (text.startsWith(GROOVYDOC_PREFIX)) {
                     docCommentNodeText = text;
                 } else {
                     docCommentNodeText = null;


Mime
View raw message