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/04/20 08:48:56 UTC
[groovy] branch master updated: GROOVY-8774: Stub generator doesn't
handle package-info (closes #1228)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new b9c0168 GROOVY-8774: Stub generator doesn't handle package-info (closes #1228)
b9c0168 is described below
commit b9c01688f3e3f892b95a5d3554f9c1e2dd914805
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Apr 19 23:11:31 2020 +1000
GROOVY-8774: Stub generator doesn't handle package-info (closes #1228)
---
.../groovy/tools/javac/JavaStubGenerator.java | 23 ++++++++---
.../tools/stubgenerator/Groovy8774Bug.groovy | 44 ++++++++++++++++++++++
2 files changed, 61 insertions(+), 6 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 fcf3948..98ca072 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -152,23 +152,34 @@ public class JavaStubGenerator {
),
Charset.forName(encoding)
);
- generateStubContent(classNode, writer);
+ 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);
+ }
javaStubCompilationUnitSet.add(new RawJavaFileObject(createJavaStubFile(fileName).toPath().toUri()));
}
private void generateStubContent(ClassNode classNode, Writer writer) {
try (PrintWriter out = new PrintWriter(writer)) {
- String packageName = classNode.getPackageName();
- if (packageName != null) {
- out.println("package " + packageName + ";\n");
- }
-
+ printPackage(out, classNode);
printImports(out, classNode);
printClassContents(out, classNode);
}
}
+ private void printPackage(PrintWriter out, ClassNode classNode) {
+ String packageName = classNode.getPackageName();
+ if (packageName != null) {
+ printAnnotations(out, classNode.getPackage());
+ out.println("package " + packageName + ";\n");
+ }
+ }
+
private void printClassContents(PrintWriter out, ClassNode classNode) {
if (classNode instanceof InnerClassNode && ((InnerClassNode) classNode).isAnonymous()) {
// if it is an anonymous inner class, don't generate the stub code for it.
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8774Bug.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8774Bug.groovy
new file mode 100644
index 0000000..dcf5957
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy8774Bug.groovy
@@ -0,0 +1,44 @@
+/*
+ * 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.stubgenerator
+
+class Groovy8774Bug extends StringSourcesStubTestCase {
+
+ Map<String, String> provideSources() {
+ [
+ 'Dummy.java': '''
+ public interface Dummy { }
+ ''',
+ 'test/package-info.groovy': '''
+ @groovy.transform.Generated
+ package test
+ '''
+ ]
+ }
+
+// protected void init() {
+// debug = true
+// delete = false
+// }
+
+ void verifyStubs() {
+ assert stubJavaSourceFor('test/package-info').contains('@groovy.transform.Generated')
+ assert stubJavaSourceFor('test/package-info').contains('package test;')
+ }
+}