groovy git commit: GROOVY-8628: Groovydoc fails to parse Java static nested classes with diamond operator(closes #748)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8628: Groovydoc fails to parse Java static nested classes with diamond operator(closes #748)

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X ab0e4ebdc -> 0eb512351


GROOVY-8628: Groovydoc fails to parse Java static nested classes with diamond operator(closes #748)

java.g grammar file:
* Added support for Java static nested class with diamond operator,
  e.g. new Class.Nested<>()
* Simplified classOrInterfaceType with typeArgumentsOrDiamond

groovydoc test:
* Added groovydoc tool test for Java static nested class with diamond
  operator

(cherry picked from commit a01322d)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 0eb5123519f2ac35ce45cce3b1800d993f41d6b4
Parents: ab0e4eb
Author: Marco-Antonio Avallone <[hidden email]>
Authored: Mon Jun 4 04:36:17 2018 +0800
Committer: sunlan <[hidden email]>
Committed: Fri Jun 8 10:40:46 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/antlr/java/java.g       | 10 +++---
 .../tools/groovydoc/GroovyDocToolTest.java      | 15 ++++++++
 .../JavaStaticNestedClassWithDiamond.java       | 38 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0eb51235/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
----------------------------------------------------------------------
diff --git a/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g b/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
index 1f09715..896c40b 100644
--- a/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
+++ b/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
@@ -16,6 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
+
 // Note: Please don't use physical tabs.  Logical tabs for indent are width 4.
 header {
 package org.codehaus.groovy.antlr.java;
@@ -370,10 +371,10 @@ classTypeSpec[boolean addImagNode]  {Token first = LT(1);}
 
 // A non-built in type name, with possible type parameters
 classOrInterfaceType[boolean addImagNode]  {Token first = LT(1);}
- : IDENT^ (typeArguments|typeArgumentsDiamond)?
+ : IDENT^ (typeArgumentsOrDiamond)?
  (options{greedy=true;}: // match as many as possible
  DOT^
- IDENT (typeArguments)?
+ IDENT (typeArgumentsOrDiamond)?
  )*
  {
  if ( addImagNode ) {
@@ -402,10 +403,9 @@ wildcardType
  (("extends" | "super")=> typeArgumentBounds)?
  ;
 
-typeArgumentsDiamond
-{Token first = LT(1);}
+typeArgumentsOrDiamond
     :   LT! GT!
-    {#typeArgumentsDiamond = #(create(TYPE_ARGUMENTS, "TYPE_ARGUMENTS",first,LT(1)), #typeArgumentsDiamond);}
+    |   typeArguments
     ;
 
 // Type arguments to a class or interface type

http://git-wip-us.apache.org/repos/asf/groovy/blob/0eb51235/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 491c964..bc72fc1 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -333,6 +333,21 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertTrue("stringList not found in: \"" + doc + "\"", doc.contains("stringList"));
     }
 
+    public void testJavaStaticNestedClassWithDiamondOperator() throws Exception {
+        List<String> srcList = new ArrayList<String>();
+        String base = "org/codehaus/groovy/tools/groovydoc/testfiles/JavaStaticNestedClassWithDiamond";
+        srcList.add(base + ".java");
+        xmlTool.add(srcList);
+        MockOutputTool output = new MockOutputTool();
+        xmlTool.renderToOutput(output, MOCK_DIR);
+        String doc = output.getText(MOCK_DIR + "/" + base + ".html");
+        assertNotNull("No GroovyDoc found for outer class " + base, doc);
+        assertTrue("Outer class expectedObject not found in: \"" + doc + "\"", doc.contains("expectedObject"));
+        String docNested = output.getText(MOCK_DIR + "/" + base + ".Nested.html");
+        assertNotNull("No GroovyDoc found for nested class " + base, docNested);
+        assertTrue("Nested class comment not found in: \"" + docNested + "\"", docNested.contains("static nested class comment"));
+    }
+
     public void testVisibilityPublic() throws Exception {
         Properties props = new Properties();
         props.put("publicScope", "true");

http://git-wip-us.apache.org/repos/asf/groovy/blob/0eb51235/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaStaticNestedClassWithDiamond.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaStaticNestedClassWithDiamond.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaStaticNestedClassWithDiamond.java
new file mode 100644
index 0000000..d9ee259
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaStaticNestedClassWithDiamond.java
@@ -0,0 +1,38 @@
+/*
+ *  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 org.codehaus.groovy.tools.groovydoc.testfiles;
+
+public class JavaStaticNestedClassWithDiamond<E> {
+
+    JavaStaticNestedClassWithDiamond() {
+    }
+
+    /**
+     * static nested class comment
+     *
+     * @param <E>
+     */
+    public static class Nested<E> extends JavaStaticNestedClassWithDiamond<E> {
+        Nested() {
+        }
+    }
+
+    public JavaStaticNestedClassWithDiamond<Object> expectedObject = new JavaStaticNestedClassWithDiamond.Nested<>();
+
+}

Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun