You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/05/11 23:54:56 UTC

[groovy] branch GROOVY_3_0_X updated (7cdcbf2 -> 040cc2b)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 7cdcbf2  GROOVY-9544: Bump gradle to 6.4
     new feb0967  GROOVY-9546: groovydoc: fix annotation rendering (closes #1243)
     new aeb4cec  GROOVY-9465: groovydoc: show class declaration header for all types (closes #1242)
     new e72c900  improved error message when parsing Java source file fails
     new 040cc2b  GROOVY-9547: groovydoc: resolve tags later for Groovy source code (closes #1244)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/groovy/antlr/GroovydocVisitor.java  |   4 +-
 .../tools/groovydoc/SimpleGroovyAnnotationRef.java |   4 +-
 .../tools/groovydoc/antlr4/GroovyDocParser.java    |  15 ++-
 .../groovydoc/antlr4/GroovydocJavaVisitor.java     |  11 +-
 .../gstringTemplates/classLevel/classDocName.html  |   6 +-
 .../groovy/tools/groovydoc/GroovyDocToolTest.java  | 134 +++++++++++++++++++++
 .../groovydoc/testfiles/GroovyInterface1.groovy    |  10 +-
 .../groovydoc/testfiles/JavaClassWithDiamond.java  |   9 ++
 .../tools/groovydoc/testfiles/anno/Groovy.groovy}  |  21 +++-
 .../tools/groovydoc/testfiles/anno/Java.java       |  33 ++---
 10 files changed, 210 insertions(+), 37 deletions(-)
 copy subprojects/{performance/src/jmh/groovy/org/apache/groovy/bench/GeneratedHashCode.groovy => groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Groovy.groovy} (59%)
 copy src/test/groovy/bugs/Groovy3784Bug.groovy => subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Java.java (61%)


[groovy] 02/04: GROOVY-9465: groovydoc: show class declaration header for all types (closes #1242)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit aeb4cecca7a7e01d09c6d4bb0d1a742725687f30
Author: Mikko Värri <vm...@linuxbox.fi>
AuthorDate: Mon May 11 02:03:31 2020 +0300

    GROOVY-9465: groovydoc: show class declaration header for all types (closes #1242)
---
 .../gstringTemplates/classLevel/classDocName.html   |  4 ++--
 .../groovy/tools/groovydoc/GroovyDocToolTest.java   | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
index 0091217..e3dfe10 100644
--- a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
+++ b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
@@ -225,6 +225,8 @@ if (classDoc.isInterface()) {
                 <dt>All Implemented Interfaces and Traits:</dt>
                 <dd>${interfaces.collect{ linkable(it) }.join(', ')}</dd>
             </dl>
+    <% } %>
+<% } %>
             <!-- todo: direct known subclasses -->
             <hr>
             <br>
@@ -235,8 +237,6 @@ if (classDoc.isInterface()) {
 %>extends ${linkable(classDoc.superclass())}
 <% } %>
 </pre>
-<% } %>
-<% } %>
 <% if (classDoc.commentText()) { %>
     <p>${classDoc.commentText()}</p>
 <% } %>
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 581c795..0292fb7 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
@@ -720,6 +720,27 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertEquals("The constructor parameter link text should be Foo", "Foo", constructor.group(3));
     }
 
+    public void testClassDeclarationHeader() throws Exception {
+        final String base = "org/codehaus/groovy/tools/groovydoc/testfiles/a";
+        htmlTool.add(Arrays.asList(
+                base + "/Base.groovy"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+
+        final String basedoc = output.getText(MOCK_DIR + "/" + base + "/Base.html");
+
+        final Matcher classDecl = Pattern.compile(Pattern.quote(
+                "<pre>class Base\n"+
+                        "extends <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html' title='Object'>Object</a>\n"+
+                        "\n"+
+                        "</pre>"
+        )).matcher(basedoc);
+
+        assertTrue("The class declaration header should exist in class description", classDecl.find());
+    }
+
     public void testJavaGenericsTitle() throws Exception {
         final String base = "org/codehaus/groovy/tools/groovydoc/testfiles/generics";
         htmlTool.add(Arrays.asList(


[groovy] 01/04: GROOVY-9546: groovydoc: fix annotation rendering (closes #1243)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit feb09671193177280ad592fa199f53252c175a94
Author: Mikko Värri <vm...@linuxbox.fi>
AuthorDate: Mon May 11 05:42:16 2020 +0300

    GROOVY-9546: groovydoc: fix annotation rendering (closes #1243)
---
 .../org/apache/groovy/antlr/GroovydocVisitor.java  |  4 +-
 .../tools/groovydoc/SimpleGroovyAnnotationRef.java |  4 +-
 .../groovydoc/antlr4/GroovydocJavaVisitor.java     | 11 +++-
 .../gstringTemplates/classLevel/classDocName.html  |  2 +-
 .../groovy/tools/groovydoc/GroovyDocToolTest.java  | 69 ++++++++++++++++++++++
 .../tools/groovydoc/testfiles/anno/Groovy.groovy   | 39 ++++++++++++
 .../tools/groovydoc/testfiles/anno/Java.java       | 40 +++++++++++++
 7 files changed, 163 insertions(+), 6 deletions(-)

diff --git a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
index 4275e03..a89b7e7 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/antlr/GroovydocVisitor.java
@@ -185,14 +185,14 @@ public class GroovydocVisitor extends ClassCodeVisitorSupport {
     private void processAnnotations(SimpleGroovyProgramElementDoc element, AnnotatedNode node) {
         for (AnnotationNode an : node.getAnnotations()) {
             String name = an.getClassNode().getName();
-            element.addAnnotationRef(new SimpleGroovyAnnotationRef(name, name));
+            element.addAnnotationRef(new SimpleGroovyAnnotationRef(name, an.getText()));
         }
     }
 
     private void processAnnotations(SimpleGroovyParameter param, AnnotatedNode node) {
         for (AnnotationNode an : node.getAnnotations()) {
             String name = an.getClassNode().getName();
-            param.addAnnotationRef(new SimpleGroovyAnnotationRef(name, name));
+            param.addAnnotationRef(new SimpleGroovyAnnotationRef(name, an.getText()));
         }
     }
 
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyAnnotationRef.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyAnnotationRef.java
index 07bdda0..9540bda 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyAnnotationRef.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyAnnotationRef.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.tools.groovydoc;
 
 import org.codehaus.groovy.groovydoc.GroovyAnnotationRef;
 import org.codehaus.groovy.groovydoc.GroovyClassDoc;
+import org.codehaus.groovy.runtime.StringGroovyMethods;
 
 public class SimpleGroovyAnnotationRef implements GroovyAnnotationRef {
     private GroovyClassDoc type;
@@ -27,8 +28,9 @@ public class SimpleGroovyAnnotationRef implements GroovyAnnotationRef {
     private String name;
 
     public SimpleGroovyAnnotationRef(String name, String desc) {
-        this.desc = desc;
         this.name = name;
+        final String params = StringGroovyMethods.minus(desc, "@" + name);
+        this.desc = "()".equals(params) ? "" : params;
     }
 
     public void setType(GroovyClassDoc type) {
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovydocJavaVisitor.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovydocJavaVisitor.java
index 834c068..1848631 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovydocJavaVisitor.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovydocJavaVisitor.java
@@ -218,16 +218,23 @@ public class GroovydocJavaVisitor extends VoidVisitorAdapter<Object> {
 
     private void processAnnotations(SimpleGroovyProgramElementDoc element, NodeWithAnnotations<?> n) {
         for (AnnotationExpr an : n.getAnnotations()) {
-            element.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getClass().getName(), an.getNameAsString()));
+            element.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getNameAsString(), getAnnotationText(an)));
         }
     }
 
     private void processAnnotations(SimpleGroovyParameter param, NodeWithAnnotations<?> n) {
         for (AnnotationExpr an : n.getAnnotations()) {
-            param.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getClass().getName(), an.getNameAsString()));
+            param.addAnnotationRef(new SimpleGroovyAnnotationRef(an.getNameAsString(), getAnnotationText(an)));
         }
     }
 
+    private String getAnnotationText(final AnnotationExpr an) {
+        if (an != null && an.getTokenRange().isPresent()) {
+            return an.getTokenRange().get().toString();
+        }
+        return "";
+    }
+
     private void setModifiers(NodeList<Modifier> modifiers, SimpleGroovyAbstractableElementDoc elementDoc) {
         if (modifiers.contains(Modifier.publicModifier())) {
             elementDoc.setPublic(true);
diff --git a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
index 2b8f5ea..0091217 100644
--- a/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
+++ b/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html
@@ -71,7 +71,7 @@
         (t.isStatic()?"static&nbsp;":"")
     }
     def annotations = { t, sepChar ->
-        t.annotations() ? t.annotations().collect{ it.isTypeAvailable()?'@'+linkable(it.type().typeName())+(it.description()-('@'+it.type().typeName())):it.description()}.join(sepChar) + sepChar : ''
+        t.annotations() ? t.annotations().collect{ it.isTypeAvailable()?'@'+linkable(it.type().typeName())+it.description():it.description()}.join(sepChar) + sepChar : ''
     }
     def elementTypes = [
         "required":"true",
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 6fcec54..581c795 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
@@ -850,6 +850,75 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertTrue("The Groovy method detail title should include type parameters", methodDetailTitle.matcher(groovydoc).find());
     }
 
+    public void testAnnotations() throws Exception {
+        final String base = "org/codehaus/groovy/tools/groovydoc/testfiles/anno";
+        htmlTool.add(Arrays.asList(
+                base + "/Groovy.groovy",
+                base + "/Java.java"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+
+        final String groovydoc = output.getText(MOCK_DIR + "/" + base + "/Groovy.html");
+        final String javadoc = output.getText(MOCK_DIR + "/" + base + "/Java.html");
+
+        assertTrue("The Groovy class declaration header should have the annotation", Pattern.compile(Pattern.quote(
+                "<pre>@groovy.transform.EqualsAndHashCode(cache: true)\n" +
+                        "class Groovy"
+        )).matcher(groovydoc).find());
+
+        assertTrue("The Java class declaration header should have the annotation", Pattern.compile(Pattern.quote(
+                "<pre>@<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Deprecated.html' title='Deprecated'>Deprecated</a>\n" +
+                        "@<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/SuppressWarnings.html' title='SuppressWarnings'>SuppressWarnings</a>(\"foo\")\n" +
+                        "public&nbsp;class Java"
+        )).matcher(javadoc).find());
+
+        assertTrue("The Groovy field details should have the annotation", Pattern.compile(Pattern.quote(
+                "<h4>@groovy.transform.Internal\n" +
+                        "public&nbsp;<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html' title='String'>String</a> " +
+                        "<strong>annotatedField</strong></h4>"
+        )).matcher(groovydoc).find());
+
+        assertTrue("The Java field details should have the annotation", Pattern.compile(Pattern.quote(
+                "<h4>@<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Deprecated.html' title='Deprecated'>Deprecated</a>\n" +
+                        "public&nbsp;<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html' title='String'>String</a> " +
+                        "<strong>annotatedField</strong></h4>"
+        )).matcher(javadoc).find());
+
+        // TODO: Annotations for properties are missing, for some reason.
+
+        assertTrue("The Groovy ctor details should have the annotation", Pattern.compile(Pattern.quote(
+                "<h4>@groovy.transform.NamedVariant\n" +
+                        "<strong>Groovy</strong>(" +
+                        "@groovy.transform.NamedParam " +
+                        "<a href='https://docs.oracle.com/javase/8/docs/api/java/util/List.html' title='List'>List</a> ctorParam" +
+                        ")</h4>"
+        )).matcher(groovydoc).find());
+
+        assertTrue("The Java ctor details should have the annotation", Pattern.compile(Pattern.quote(
+                "<h4>@<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Deprecated.html' title='Deprecated'>Deprecated</a>\n" +
+                        "public&nbsp;<strong>Java</strong>()</h4>"
+        )).matcher(javadoc).find());
+
+        // Note also the param annotation
+        assertTrue("The Groovy method details should have the annotations", Pattern.compile(Pattern.quote(
+                "<h4>@groovy.transform.NamedVariant\n" +
+                        "void <strong>annotatedMethod</strong>(" +
+                        "@groovy.transform.NamedParam(required: true) " +
+                        "<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html' title='String'>String</a> methodParam" +
+                        ")</h4>"
+        )).matcher(groovydoc).find());
+
+        assertTrue("The Java method details should have the annotations", Pattern.compile(Pattern.quote(
+                "<h4>@<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Deprecated.html' title='Deprecated'>Deprecated</a>\n" +
+                        "public&nbsp;void <strong>annotatedMethod</strong>(" +
+                        "@CommandLine.Parameters(hidden = true) " +
+                        "<a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html' title='String'>String</a> annotatedParam" +
+                        ")</h4>"
+        )).matcher(javadoc).find());
+    }
+
     public void testScript() throws Exception {
         List<String> srcList = new ArrayList<String>();
         srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/Script.groovy");
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Groovy.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Groovy.groovy
new file mode 100644
index 0000000..1362c88
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Groovy.groovy
@@ -0,0 +1,39 @@
+/*
+ *  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.anno
+
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.NamedParam
+import groovy.transform.NamedVariant
+
+// The annotations that are used here don't really matter,
+// since groovydoc shows all annotations, not just @Documented ones.
+@EqualsAndHashCode(cache = true)
+class Groovy implements Serializable {
+    @groovy.transform.Internal
+    public String annotatedField
+
+    @Deprecated List annotatedProperty
+
+    @NamedVariant
+    Groovy(@NamedParam List ctorParam) {}
+
+    @NamedVariant
+    void annotatedMethod(@NamedParam(required = true) String methodParam) {}
+}
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Java.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Java.java
new file mode 100644
index 0000000..d18db63
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/anno/Java.java
@@ -0,0 +1,40 @@
+/*
+ *  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.anno;
+
+
+import org.junit.runners.Parameterized;
+import picocli.CommandLine;
+
+import java.io.Serializable;
+
+// The annotations that are used here don't really matter,
+// since groovydoc shows all annotations, not just @Documented ones.
+@Deprecated
+@SuppressWarnings("foo")
+public class Java implements Serializable {
+    @Deprecated
+    public String annotatedField;
+
+    @Deprecated
+    public Java() {}
+
+    @Deprecated
+    public void annotatedMethod(@CommandLine.Parameters(hidden = true) String annotatedParam) {}
+}


[groovy] 03/04: improved error message when parsing Java source file fails

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e72c900bbf05c133bfe33ebf890bc2d2d56d3039
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon May 11 20:48:41 2020 +1000

    improved error message when parsing Java source file fails
---
 .../codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
index fb94a96..bbb66b3 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
@@ -65,7 +65,14 @@ public class GroovyDocParser implements GroovyDocParserI {
 
     private Map<String, GroovyClassDoc> parseJava(String packagePath, String file, String src) throws RuntimeException {
         GroovydocJavaVisitor visitor = new GroovydocJavaVisitor(packagePath, links);
-        visitor.visit(StaticJavaParser.parse(src), null);
+        try {
+            visitor.visit(StaticJavaParser.parse(src), null);
+        } catch(Throwable t) {
+            System.err.println("Attempting to ignore error parsing Java source file: " + packagePath + "/" + file);
+            System.err.println("Consider reporting the error to the Groovy project: https://issues.apache.org/jira/browse/GROOVY");
+            System.err.println("... or directly to the JavaParser project: https://github.com/javaparser/javaparser/issues");
+            System.err.println("Error: " + t.getMessage());
+        }
         return visitor.getGroovyClassDocs();
     }
 


[groovy] 04/04: GROOVY-9547: groovydoc: resolve tags later for Groovy source code (closes #1244)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 040cc2bf59af467230444df01020c87a1b6a696a
Author: Mikko Värri <vm...@linuxbox.fi>
AuthorDate: Mon May 11 11:51:37 2020 +0300

    GROOVY-9547: groovydoc: resolve tags later for Groovy source code (closes #1244)
    
    For Java source code, tags are resolved when the template asks for the
    comments.  For Groovy, they were resolved as soon as the source file
    was processes.  At that point, not all classes in the same package are
    processes, so links to those failed to link.
---
 .../tools/groovydoc/antlr4/GroovyDocParser.java    |  6 +--
 .../groovy/tools/groovydoc/GroovyDocToolTest.java  | 44 ++++++++++++++++++++++
 .../groovydoc/testfiles/GroovyInterface1.groovy    | 10 ++++-
 .../groovydoc/testfiles/JavaClassWithDiamond.java  |  9 +++++
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
index bbb66b3..ebb714c 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/antlr4/GroovyDocParser.java
@@ -86,11 +86,7 @@ public class GroovyDocParser implements GroovyDocParserI {
         ModuleNode root = unit.getAST();
         GroovydocVisitor visitor = new GroovydocVisitor(unit, packagePath, links);
         visitor.visitClass(root.getClasses().get(0));
-        Map<String, GroovyClassDoc> groovyClassDocs = visitor.getGroovyClassDocs();
-        for (GroovyClassDoc classDoc : groovyClassDocs.values()) {
-            replaceTags((SimpleGroovyClassDoc) classDoc);
-        }
-        return groovyClassDocs;
+        return visitor.getGroovyClassDocs();
     }
 
     private void replaceTags(SimpleGroovyClassDoc sgcd) {
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 0292fb7..2c6f078 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
@@ -940,6 +940,50 @@ public class GroovyDocToolTest extends GroovyTestCase {
         )).matcher(javadoc).find());
     }
 
+    public void testLinksToSamePackage() throws Exception {
+        final String base = "org/codehaus/groovy/tools/groovydoc/testfiles";
+        htmlTool.add(Arrays.asList(
+                base + "/GroovyInterface1.groovy",
+                base + "/JavaClassWithDiamond.java"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+
+        final String groovydoc = output.getText(MOCK_DIR + "/" + base + "/GroovyInterface1.html");
+        final String javadoc = output.getText(MOCK_DIR + "/" + base + "/JavaClassWithDiamond.html");
+
+        final Matcher groovyClassComment = Pattern.compile(Pattern.quote(
+                "<p> <a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.html#link()' title='Java'>Java</a> " +
+                        "<DL><DT><B>See Also:</B></DT>" +
+                        "<DD><a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.html' title='JavaClassWithDiamond'>JavaClassWithDiamond</a></DD>" +
+                        "</DL></p>"
+        )).matcher(groovydoc);
+        final Matcher groovyMethodComment = Pattern.compile(Pattern.quote(
+                "<p> <a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.html#link()' title='Java link'>Java link</a> " +
+                        "<DL><DT><B>See Also:</B></DT>" +
+                        "<DD><a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/JavaClassWithDiamond.html#link()' title='JavaClassWithDiamond.link'>JavaClassWithDiamond.link</a></DD>" +
+                        "</DL></p>"
+        )).matcher(groovydoc);
+        final Matcher javaClassComment = Pattern.compile(Pattern.quote(
+                "<p> <a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.html#link()' title='Groovy link'>Groovy link</a>\n" +
+                        "  <DL><DT><B>See Also:</B></DT>" +
+                        "<DD><a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.html' title='GroovyInterface1'>GroovyInterface1</a></DD>" +
+                        "</DL></p>"
+        )).matcher(javadoc);
+        final Matcher javaMethodComment = Pattern.compile(Pattern.quote(
+                "<p> <a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.html#link()' title='Groovy link'>Groovy link</a>\n" +
+                        "      <DL><DT><B>See Also:</B></DT>" +
+                        "<DD><a href='../../../../../../org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.html#link()' title='GroovyInterface1.link'>GroovyInterface1.link</a></DD>" +
+                        "</DL></p>"
+        )).matcher(javadoc);
+
+        assertTrue("The Groovy class comment should contain links", groovyClassComment.find());
+        assertTrue("The Groovy method comment should contain links", groovyMethodComment.find());
+        assertTrue("The Java class comment should contain links", javaClassComment.find());
+        assertTrue("The Java method comment should contain links", javaMethodComment.find());
+    }
+
     public void testScript() throws Exception {
         List<String> srcList = new ArrayList<String>();
         srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/Script.groovy");
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.groovy
index 20c2fda..a2a9138 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.groovy
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/GroovyInterface1.groovy
@@ -18,6 +18,14 @@
  */
 package org.codehaus.groovy.tools.groovydoc.testfiles
 
+/**
+ * {@link JavaClassWithDiamond#link() Java}
+ * @see JavaClassWithDiamond
+ */
 interface GroovyInterface1 {
-
+    /**
+     * {@link JavaClassWithDiamond#link() Java link}
+     * @see JavaClassWithDiamond#link()
+     */
+    void link()
 }
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
index 832543e..597db21 100644
--- 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
@@ -21,6 +21,15 @@ package org.codehaus.groovy.tools.groovydoc.testfiles;
 import java.util.ArrayList;
 import java.util.List;
 
+/**
+ * {@link GroovyInterface1#link() Groovy link}
+ * @see GroovyInterface1
+ */
 public abstract class JavaClassWithDiamond {
     public List<String> stringList = new ArrayList<>();
+    /**
+     * {@link GroovyInterface1#link() Groovy link}
+     * @see GroovyInterface1#link()
+     */
+    public abstract void link();
 }