groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring
Date Wed, 06 Sep 2017 23:59:18 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 1a2aff345 -> 6fd3f95e4


Minor refactoring

(cherry picked from commit 1f2ca64)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 6fd3f95e4eec58c5732f04038c55fd075fb60698
Parents: 1a2aff3
Author: sunlan <sunlan@apache.org>
Authored: Thu Sep 7 02:01:44 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Sep 7 07:57:42 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6fd3f95e/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 2766c02..9cd91c8 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -147,7 +147,6 @@ import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last;
  *         Created on 2016/08/14
  */
 public class AstBuilder extends GroovyParserBaseVisitor<Object> implements GroovyParserVisitor<Object>
{
-
     public AstBuilder(SourceUnit sourceUnit, ClassLoader classLoader) {
         this.sourceUnit = sourceUnit;
         this.moduleNode = new ModuleNode(sourceUnit);
@@ -2352,17 +2351,17 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         int slashyType = getSlashyType(text);
         boolean startsWithSlash = false;
 
-        if (text.startsWith("'''") || text.startsWith("\"\"\"")) {
+        if (text.startsWith(TSQ_STR) || text.startsWith(TDQ_STR)) {
             text = StringUtils.removeCR(text); // remove CR in the multiline string
 
             text = StringUtils.trimQuotations(text, 3);
-        } else if (text.startsWith("'") || text.startsWith("\"") || (startsWithSlash = text.startsWith("/")))
{
+        } else if (text.startsWith(SQ_STR) || text.startsWith(DQ_STR) || (startsWithSlash
= text.startsWith(SLASH_STR))) {
             if (startsWithSlash) { // the slashy string can span rows, so we have to remove
CR for it
                 text = StringUtils.removeCR(text); // remove CR in the multiline string
             }
 
             text = StringUtils.trimQuotations(text, 1);
-        } else if (text.startsWith("$/")) {
+        } else if (text.startsWith(DOLLAR_SLASH_STR)) {
             text = StringUtils.removeCR(text);
 
             text = StringUtils.trimQuotations(text, 2);
@@ -2378,8 +2377,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
     }
 
     private int getSlashyType(String text) {
-        return text.startsWith("/") ? StringUtils.SLASHY :
-                    text.startsWith("$/") ? StringUtils.DOLLAR_SLASHY : StringUtils.NONE_SLASHY;
+        return text.startsWith(SLASH_STR) ? StringUtils.SLASHY :
+                    text.startsWith(DOLLAR_SLASH_STR) ? StringUtils.DOLLAR_SLASHY : StringUtils.NONE_SLASHY;
     }
 
     @Override
@@ -3198,13 +3197,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
         {
             String it = begin;
-            if (it.startsWith("\"\"\"")) {
+            if (it.startsWith(TDQ_STR)) {
                 it = StringUtils.removeCR(it);
                 it = it.substring(2); // translate leading """ to "
-            } else if (it.startsWith("$/")) {
+            } else if (it.startsWith(DOLLAR_SLASH_STR)) {
                 it = StringUtils.removeCR(it);
-                it = "\"" + it.substring(2); // translate leading $/ to "
-            } else if (it.startsWith("/")) {
+                it = DQ_STR + it.substring(2); // translate leading $/ to "
+            } else if (it.startsWith(SLASH_STR)) {
                 it = StringUtils.removeCR(it);
             }
 
@@ -3230,13 +3229,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
         {
             String it = ctx.GStringEnd().getText();
-            if (it.endsWith("\"\"\"")) {
+            if (it.endsWith(TDQ_STR)) {
                 it = StringUtils.removeCR(it);
                 it = StringGroovyMethods.getAt(it, new IntRange(true, 0, -3)); // translate
tailing """ to "
-            } else if (it.endsWith("/$")) {
+            } else if (it.endsWith(SLASH_DOLLAR_STR)) {
                 it = StringUtils.removeCR(it);
-                it = StringGroovyMethods.getAt(it, new IntRange(false, 0, -2)) + "\""; //
translate tailing /$ to "
-            } else if (it.endsWith("/")) {
+                it = StringGroovyMethods.getAt(it, new IntRange(false, 0, -2)) + DQ_STR;
// translate tailing /$ to "
+            } else if (it.endsWith(SLASH_STR)) {
                 it = StringUtils.removeCR(it);
             }
 
@@ -4601,6 +4600,14 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
     private static final String THIS_STR = "this";
     private static final String SUPER_STR = "super";
     private static final String VOID_STR = "void";
+    private static final String SLASH_STR = "/";
+    private static final String SLASH_DOLLAR_STR = "/$";
+    private static final String TDQ_STR = "\"\"\"";
+    private static final String TSQ_STR = "'''";
+    private static final String SQ_STR = "'";
+    private static final String DQ_STR = "\"";
+    private static final String DOLLAR_SLASH_STR = "$/";
+
     private static final String PACKAGE_INFO = "package-info";
     private static final String PACKAGE_INFO_FILE_NAME = PACKAGE_INFO + ".groovy";
     private static final String GROOVY_TRANSFORM_TRAIT = "groovy.transform.Trait";


Mime
View raw message