GROOVY-7955: Groovydoc fails to parse Java source files containing the diamond operator
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5e74067e Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5e74067e Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5e74067e Branch: refs/heads/parrot Commit: 5e74067e817d4f4237f0daec5112796087c8d2c8 Parents: 94137c9 Author: paulk <pa...@asert.com.au> Authored: Tue Oct 4 22:20:08 2016 +1000 Committer: paulk <pa...@asert.com.au> Committed: Tue Oct 4 22:20:08 2016 +1000 ---------------------------------------------------------------------- src/main/org/codehaus/groovy/antlr/java/java.g | 8 +++++- .../tools/groovydoc/GroovyDocToolTest.java | 16 ++++++++++-- .../testfiles/JavaClassWithDiamond.java | 26 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/5e74067e/src/main/org/codehaus/groovy/antlr/java/java.g ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/antlr/java/java.g b/src/main/org/codehaus/groovy/antlr/java/java.g index ac2ced6..1f09715 100644 --- a/src/main/org/codehaus/groovy/antlr/java/java.g +++ b/src/main/org/codehaus/groovy/antlr/java/java.g @@ -370,7 +370,7 @@ 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)? + : IDENT^ (typeArguments|typeArgumentsDiamond)? (options{greedy=true;}: // match as many as possible DOT^ IDENT (typeArguments)? @@ -402,6 +402,12 @@ wildcardType (("extends" | "super")=> typeArgumentBounds)? ; +typeArgumentsDiamond +{Token first = LT(1);} + : LT! GT! + {#typeArgumentsDiamond = #(create(TYPE_ARGUMENTS, "TYPE_ARGUMENTS",first,LT(1)), #typeArgumentsDiamond);} + ; + // Type arguments to a class or interface type typeArguments {int currentLtLevel = 0; Token first = LT(1);} http://git-wip-us.apache.org/repos/asf/groovy/blob/5e74067e/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 9326c85..6b68ef4 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 @@ -292,9 +292,9 @@ public class GroovyDocToolTest extends GroovyTestCase { xmlToolForTests.add(srcList); MockOutputTool output = new MockOutputTool(); xmlToolForTests.renderToOutput(output, MOCK_DIR); - String doc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/MultiCatchExample.html"); + String doc = output.getText(MOCK_DIR + "/" + base + ".html"); assertNotNull("No GroovyDoc found for " + base, doc); - assertTrue(doc, doc.indexOf("foo has a multi-catch exception inside") > 0); + assertTrue(doc, doc.contains("foo has a multi-catch exception inside")); } public void testStaticModifier() throws Exception { @@ -321,6 +321,18 @@ public class GroovyDocToolTest extends GroovyTestCase { assertTrue("innerClassMethod found in: \"" + classWithAnonymousInnerClassDoc + "\"", !classWithAnonymousInnerClassDoc.contains("innerClassMethod")); } + public void testJavaClassWithDiamondOperator() throws Exception { + List<String> srcList = new ArrayList<String>(); + String base = "org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond"; + 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 " + base, doc); + assertTrue("stringList not found in: \"" + doc + "\"", doc.contains("stringList")); + } + public void testVisibilityPublic() throws Exception { Properties props = new Properties(); props.put("publicScope", "true"); http://git-wip-us.apache.org/repos/asf/groovy/blob/5e74067e/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.java new file mode 100644 index 0000000..832543e --- /dev/null +++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.java @@ -0,0 +1,26 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +public abstract class JavaClassWithDiamond { + public List<String> stringList = new ArrayList<>(); +}