This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 83532a0 Revert "GROOVY-9031: correct trait property generics before
writing stub methods" for now
83532a0 is described below
commit 83532a031abf9bd6117d17647c2748a69d01d3b6
Author: Daniel Sun <[email protected]>
AuthorDate: Tue Aug 13 17:09:00 2019 +0800
Revert "GROOVY-9031: correct trait property generics before writing stub
methods" for now
This reverts commit a6d36cd3
---
.../groovy/tools/javac/JavaStubGenerator.java | 33 +---------
src/test/groovy/bugs/Groovy9031.groovy | 72 ----------------------
2 files changed, 3 insertions(+), 102 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 06eefd4..64b3ee9 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -63,17 +63,10 @@ import java.io.Writer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-
-import static
org.codehaus.groovy.ast.tools.GenericsUtils.correctToGenericsSpec;
-import static org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;
public class JavaStubGenerator {
private final boolean java5;
@@ -154,37 +147,17 @@ public class JavaStubGenerator {
try {
Verifier verifier = new Verifier() {
@Override
- public void visitClass(ClassNode node) {
- List<Statement> savedStatements = new
ArrayList<>(node.getObjectInitializerStatements());
+ public void visitClass(final ClassNode node) {
+ List<Statement> savedStatements = new
ArrayList<Statement>(node.getObjectInitializerStatements());
super.visitClass(node);
node.getObjectInitializerStatements().addAll(savedStatements);
-
- for (ClassNode trait : findTraits(node)) {
- // GROOVY-9031: replace property type placeholder with
resolved type from trait generics
- Map<String, ClassNode> generics =
trait.isUsingGenerics() ? createGenericsSpec(trait) : null;
+ for (ClassNode trait : Traits.findTraits(node)) {
for (PropertyNode traitProperty :
trait.getProperties()) {
- ClassNode traitPropertyType =
traitProperty.getType();
-
traitProperty.setType(correctToGenericsSpec(generics, traitPropertyType));
super.visitProperty(traitProperty);
- traitProperty.setType(traitPropertyType);
}
}
}
- private Iterable<ClassNode> findTraits(ClassNode node) {
- Set<ClassNode> traits = new LinkedHashSet<>();
-
- LinkedList<ClassNode> todo = new LinkedList<>();
- Collections.addAll(todo, node.getInterfaces());
- while (!todo.isEmpty()) {
- ClassNode next = todo.removeLast();
- if (Traits.isTrait(next)) traits.add(next);
- Collections.addAll(todo, next.getInterfaces());
- }
-
- return traits;
- }
-
@Override
protected FinalVariableAnalyzer.VariableNotFinalCallback
getFinalVariablesCallback() {
return null;
diff --git a/src/test/groovy/bugs/Groovy9031.groovy
b/src/test/groovy/bugs/Groovy9031.groovy
deleted file mode 100644
index 6af7740..0000000
--- a/src/test/groovy/bugs/Groovy9031.groovy
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 groovy.bugs
-
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
-import org.junit.Test
-
-final class Groovy9031 {
-
- @Test
- void testGenerics() {
- def config = new CompilerConfiguration(
- targetDirectory: File.createTempDir(),
- jointCompilationOptions: [stubDir: File.createTempDir()]
- )
-
- def parentDir = File.createTempDir()
- try {
- def a = new File(parentDir, 'Trait.groovy')
- a.write '''
- trait Trait<V> {
- V value
- }
- '''
- def b = new File(parentDir, 'TraitImpl.groovy')
- b.write '''
- class TraitImpl implements Trait<String> {
- }
- '''
- def c = new File(parentDir, 'Whatever.java')
- c.write '''
- class Whatever {
- void meth() {
- new TraitImpl().getValue();
- }
- }
- '''
-
- def loader = new GroovyClassLoader(this.class.classLoader)
- def cu = new JavaAwareCompilationUnit(config, loader)
- cu.addSources(a, b, c)
- cu.compile()
-
- def stub = new File(config.jointCompilationOptions.stubDir,
'TraitImpl.java')
- def text = stub.text
-
- assert text.contains('java.lang.String getValue()')
- assert text.contains('void setValue(java.lang.String value)')
- } finally {
- parentDir.deleteDir()
- config.targetDirectory.deleteDir()
- config.jointCompilationOptions.stubDir.deleteDir()
- }
- }
-}