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 2020/07/09 06:16:22 UTC

[groovy] branch danielsun/tweak-java-stub updated (7944e11 -> 0db4b46)

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

sunlan pushed a change to branch danielsun/tweak-java-stub
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 7944e11  Minor refactoring: reuse the code of generating stub content
     new 0db4b46  Minor refactoring: reuse the code of generating stub content

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (7944e11)
            \
             N -- N -- N   refs/heads/danielsun/tweak-java-stub (0db4b46)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 .../java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)


[groovy] 01/01: Minor refactoring: reuse the code of generating stub content

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

sunlan pushed a commit to branch danielsun/tweak-java-stub
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 0db4b4616f97bdf6e2ceaa0f708f836e1b12f616
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Jul 9 14:14:17 2020 +0800

    Minor refactoring: reuse the code of generating stub content
---
 .../groovy/tools/javac/JavaStubGenerator.java      | 29 +++++++++++-----------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 15fcf97..59f061d 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -133,10 +133,7 @@ public class JavaStubGenerator {
     }
 
     private void generateMemStub(ClassNode classNode) {
-        Writer writer = new StringBuilderWriter(DEFAULT_BUFFER_SIZE);
-        generateStubContent(classNode, writer);
-
-        javaStubCompilationUnitSet.add(new MemJavaFileObject(classNode, writer.toString()));
+        javaStubCompilationUnitSet.add(new MemJavaFileObject(classNode, generateStubContent(classNode)));
     }
 
     private void generateFileStub(ClassNode classNode) throws FileNotFoundException {
@@ -152,24 +149,28 @@ public class JavaStubGenerator {
                 ),
                 Charset.forName(encoding)
         );
-        if (classNode.getNameWithoutPackage().equals("package-info")) {
-            // should just output the package statement
-            try (PrintWriter out = new PrintWriter(writer)) {
-                printPackage(out, classNode);
-            }
-        } else {
-            generateStubContent(classNode, writer);
+
+        try (PrintWriter out = new PrintWriter(writer)) {
+            out.print(generateStubContent(classNode));
         }
 
         javaStubCompilationUnitSet.add(new RawJavaFileObject(createJavaStubFile(fileName).toPath().toUri()));
     }
 
-    private void generateStubContent(ClassNode classNode, Writer writer) {
+    private String generateStubContent(ClassNode classNode) {
+        Writer writer = new StringBuilderWriter(DEFAULT_BUFFER_SIZE);
+
         try (PrintWriter out = new PrintWriter(writer)) {
             printPackage(out, classNode);
-            printImports(out, classNode);
-            printClassContents(out, classNode);
+
+            // should just output the package statement for `package-info` class node
+            if (!"package-info".equals(classNode.getNameWithoutPackage())) {
+                printImports(out, classNode);
+                printClassContents(out, classNode);
+            }
         }
+
+        return writer.toString();
     }
 
     private void printPackage(PrintWriter out, ClassNode classNode) {