You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/01/28 16:08:17 UTC

[09/10] groovy git commit: GROOVY-5318: generic types in fully-qualified class names parsing error (closes #479)

GROOVY-5318: generic types in fully-qualified class names parsing error (closes #479)


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

Branch: refs/heads/parrot
Commit: 84462bb563b0c1c0faf1ef0af623561e60c557e7
Parents: cb2e2c2
Author: paulk <pa...@asert.com.au>
Authored: Wed Jan 25 21:15:17 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sat Jan 28 17:03:06 2017 +1000

----------------------------------------------------------------------
 .../groovy/antlr/AntlrParserPlugin.java         | 19 ++++++++++++-
 src/test/groovy/bugs/Groovy5318Bug.groovy       | 30 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/84462bb5/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 28a0395..6cacbfd 100644
--- a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -2907,13 +2907,14 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
             StringBuilder buffer = new StringBuilder();
             boolean first = true;
 
-            for (; node != null && !isType(TYPE_ARGUMENTS, node); node = node.getNextSibling()) {
+            while (node != null && !isType(TYPE_ARGUMENTS, node)) {
                 if (first) {
                     first = false;
                 } else {
                     buffer.append(".");
                 }
                 buffer.append(qualifiedName(node));
+                node = node.getNextSibling();
             }
             return buffer.toString();
         } else {
@@ -3038,6 +3039,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
             if (isType(INDEX_OP, node) || isType(ARRAY_DECLARATOR, node)) {
                 answer = makeType(node).makeArray();
             } else {
+                checkTypeArgs(node, false);
                 answer = ClassHelper.make(qualifiedName(node));
                 if (answer.isUsingGenerics()) {
                     ClassNode newAnswer = ClassHelper.makeWithoutCaching(answer.getName());
@@ -3050,6 +3052,21 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
         return answer;
     }
 
+    private boolean checkTypeArgs(AST node, boolean seenTypeArgs) {
+        if (isType(IDENT, node) && seenTypeArgs) {
+            throw new ASTRuntimeException(node, "Unexpected type arguments found prior to: " + qualifiedName(node));
+        }
+        if (isType(DOT, node)) {
+            AST next = node.getFirstChild();
+            while (next != null && !isType(TYPE_ARGUMENTS, next)) {
+                seenTypeArgs |= checkTypeArgs(next, seenTypeArgs);
+                seenTypeArgs |= isType(TYPE_ARGUMENTS, next.getFirstChild()) || isType(TYPE_ARGUMENTS, next.getNextSibling());
+                next = next.getNextSibling();
+            }
+        }
+        return seenTypeArgs;
+    }
+
     /**
      * Performs a name resolution to see if the given name is a type from imports,
      * aliases or newly created classes

http://git-wip-us.apache.org/repos/asf/groovy/blob/84462bb5/src/test/groovy/bugs/Groovy5318Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy5318Bug.groovy b/src/test/groovy/bugs/Groovy5318Bug.groovy
new file mode 100644
index 0000000..819dd58
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy5318Bug.groovy
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import gls.CompilableTestSupport
+
+class Groovy5318Bug extends CompilableTestSupport {
+    void testTypeArgumentsOnlyOnTheLastComponent() {
+        def message = shouldNotCompile """
+            def a = new java.util<Integer>.ArrayList<ArrayList<Integer>>()
+        """
+        assert message.contains('Unexpected type arguments found prior to: ArrayList')
+    }
+}