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

sunlan pushed a commit to branch refine-groovydoc
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/refine-groovydoc by this push:
     new d8164b3  Prepare to compare the result generated by old and new 
SimpleJavaClassDocAssembler
d8164b3 is described below

commit d8164b35398152470f1a8c963144778dee7ec717
Author: Daniel Sun <sun...@apache.org>
AuthorDate: Sun Dec 30 00:51:02 2018 +0800

    Prepare to compare the result generated by old and new 
SimpleJavaClassDocAssembler
---
 .../groovydoc/SimpleJavaClassDocAssembler.java     | 45 +++++-----
 .../groovydoc/SimpleJavaClassDocAssembler.java     | 95 ++++++++++++++++++++++
 .../tools/groovydoc/util/DocComparator.groovy      | 25 ++++++
 3 files changed, 142 insertions(+), 23 deletions(-)

diff --git 
a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
 
b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
index 49579b9..511bed9 100644
--- 
a/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
+++ 
b/subprojects/groovy-groovydoc/src/main/java/org/apache/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
@@ -28,7 +28,7 @@ import com.github.javaparser.ast.body.EnumDeclaration;
 import com.github.javaparser.ast.body.FieldDeclaration;
 import com.github.javaparser.ast.body.MethodDeclaration;
 import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
-import com.github.javaparser.ast.visitor.GenericVisitorAdapter;
+import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
 import com.github.javaparser.javadoc.Javadoc;
 import org.codehaus.groovy.groovydoc.GroovyClassDoc;
 import org.codehaus.groovy.tools.groovydoc.LinkArgument;
@@ -39,8 +39,9 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
 
-public class SimpleJavaClassDocAssembler extends GenericVisitorAdapter<Object, 
Object> {
+public class SimpleJavaClassDocAssembler extends VoidVisitorAdapter<Object> {
     private final String packagePath;
+    private final String file;
     private final String javaSourceContent;
     private final String className;
     private final List<LinkArgument> links;
@@ -49,6 +50,7 @@ public class SimpleJavaClassDocAssembler extends 
GenericVisitorAdapter<Object, O
 
     public SimpleJavaClassDocAssembler(String packagePath, String file, String 
javaSourceContent, List<LinkArgument> links, Properties properties) {
         this.packagePath = packagePath;
+        this.file = file;
         this.javaSourceContent = javaSourceContent;
         this.links = links;
         this.properties = properties;
@@ -62,60 +64,57 @@ public class SimpleJavaClassDocAssembler extends 
GenericVisitorAdapter<Object, O
         }
     }
 
-    public Map<String, GroovyClassDoc> getGroovyClassDocs() {
-        return classDocs;
-    }
-
-    public void assemble() {
+    public Map<String, GroovyClassDoc> assemble() {
         this.visit(JavaParser.parse(javaSourceContent), null);
+        return classDocs;
     }
 
     @Override
-    public Object visit(final ClassOrInterfaceDeclaration n, final Object arg) 
{
+    public void visit(final ClassOrInterfaceDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final MethodDeclaration n, final Object arg) {
+    public void visit(final MethodDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final ConstructorDeclaration n, final Object arg) {
+    public void visit(final ConstructorDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final FieldDeclaration n, final Object arg) {
+    public void visit(final FieldDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final EnumDeclaration n, final Object arg) {
+    public void visit(final EnumDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final EnumConstantDeclaration n, final Object arg) {
+    public void visit(final EnumConstantDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final AnnotationDeclaration n, final Object arg) {
+    public void visit(final AnnotationDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     @Override
-    public Object visit(final AnnotationMemberDeclaration n, final Object arg) 
{
+    public void visit(final AnnotationMemberDeclaration n, final Object arg) {
         processJavadoc(n);
-        return super.visit(n, arg);
+        super.visit(n, arg);
     }
 
     private void processJavadoc(NodeWithJavadoc n) {
diff --git 
a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
 
b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
new file mode 100644
index 0000000..d791a4a
--- /dev/null
+++ 
b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleJavaClassDocAssembler.java
@@ -0,0 +1,95 @@
+/*
+ *  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;
+
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+import antlr.collections.AST;
+import org.codehaus.groovy.antlr.AntlrASTProcessor;
+import org.codehaus.groovy.antlr.SourceBuffer;
+import org.codehaus.groovy.antlr.UnicodeEscapingReader;
+import org.codehaus.groovy.antlr.java.Groovifier;
+import org.codehaus.groovy.antlr.java.Java2GroovyConverter;
+import org.codehaus.groovy.antlr.java.JavaLexer;
+import org.codehaus.groovy.antlr.java.JavaRecognizer;
+import org.codehaus.groovy.antlr.treewalker.PreOrderTraversal;
+import org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal;
+import org.codehaus.groovy.antlr.treewalker.Visitor;
+import org.codehaus.groovy.groovydoc.GroovyClassDoc;
+
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class SimpleJavaClassDocAssembler {
+    private final String packagePath;
+    private final String file;
+    private final String javaSourceContent;
+//    private final String className;
+    private final List<LinkArgument> links;
+    private final Properties properties;
+
+    public SimpleJavaClassDocAssembler(String packagePath, String file, String 
javaSourceContent, List<LinkArgument> links, Properties properties) {
+        this.packagePath = packagePath;
+        this.file = file;
+        this.javaSourceContent = javaSourceContent;
+        this.links = links;
+        this.properties = properties;
+    }
+
+    public Map<String, GroovyClassDoc> assemble() throws TokenStreamException, 
RecognitionException {
+        SourceBuffer sourceBuffer = new SourceBuffer();
+        JavaRecognizer parser = getJavaParser(javaSourceContent, sourceBuffer);
+        String[] tokenNames = parser.getTokenNames();
+        try {
+            parser.compilationUnit();
+        } catch (OutOfMemoryError e) {
+            throw e;
+        }
+        AST ast = parser.getAST();
+
+        // modify the Java AST into a Groovy AST (just token types)
+        Visitor java2groovyConverter = new Java2GroovyConverter(tokenNames);
+        AntlrASTProcessor java2groovyTraverser = new 
PreOrderTraversal(java2groovyConverter);
+        java2groovyTraverser.process(ast);
+
+        // now mutate (groovify) the ast into groovy
+        Visitor groovifier = new Groovifier(tokenNames, false);
+        AntlrASTProcessor groovifierTraverser = new 
PreOrderTraversal(groovifier);
+        groovifierTraverser.process(ast);
+
+        // now do the business
+        Visitor visitor = new SimpleGroovyClassDocAssembler(packagePath, file, 
sourceBuffer, links, properties, false);
+        AntlrASTProcessor traverser = new SourceCodeTraversal(visitor);
+
+        traverser.process(ast);
+
+        return ((SimpleGroovyClassDocAssembler) visitor).getGroovyClassDocs();
+    }
+
+    private static JavaRecognizer getJavaParser(String input, SourceBuffer 
sourceBuffer) {
+        UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new 
StringReader(input), sourceBuffer);
+        JavaLexer lexer = new JavaLexer(unicodeReader);
+        unicodeReader.setLexer(lexer);
+        JavaRecognizer parser = JavaRecognizer.make(lexer);
+        parser.setSourceBuffer(sourceBuffer);
+        return parser;
+    }
+}
diff --git 
a/subprojects/groovy-groovydoc/src/test/groovy/org/apache/groovy/tools/groovydoc/util/DocComparator.groovy
 
b/subprojects/groovy-groovydoc/src/test/groovy/org/apache/groovy/tools/groovydoc/util/DocComparator.groovy
new file mode 100644
index 0000000..782ed8a
--- /dev/null
+++ 
b/subprojects/groovy-groovydoc/src/test/groovy/org/apache/groovy/tools/groovydoc/util/DocComparator.groovy
@@ -0,0 +1,25 @@
+/*
+ *  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.apache.groovy.tools.groovydoc.util
+
+/**
+ * TODO compare the result generated by old and new SimpleJavaClassDocAssembler
+ */
+class DocComparator {
+}

Reply via email to