Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6AC26200D08 for ; Thu, 7 Sep 2017 01:59:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 691791609E2; Wed, 6 Sep 2017 23:59:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 88FA11609DB for ; Thu, 7 Sep 2017 01:59:19 +0200 (CEST) Received: (qmail 8025 invoked by uid 500); 6 Sep 2017 23:59:18 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 8016 invoked by uid 99); 6 Sep 2017 23:59:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2017 23:59:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2430EF3280; Wed, 6 Sep 2017 23:59:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: <278fd290efd94209816955fc756b5ac0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: Minor refactoring Date: Wed, 6 Sep 2017 23:59:18 +0000 (UTC) archived-at: Wed, 06 Sep 2017 23:59:20 -0000 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 Authored: Thu Sep 7 02:01:44 2017 +0800 Committer: sunlan 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 implements GroovyParserVisitor { - public AstBuilder(SourceUnit sourceUnit, ClassLoader classLoader) { this.sourceUnit = sourceUnit; this.moduleNode = new ModuleNode(sourceUnit); @@ -2352,17 +2351,17 @@ public class AstBuilder extends GroovyParserBaseVisitor 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 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 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 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 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";