Skip to content

Commit

Permalink
Fix for #733: use top redirect when making generics type for placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 28, 2018
1 parent 57164be commit 3f0e2f1
Show file tree
Hide file tree
Showing 11 changed files with 2,443 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ public void testTraitBinary() throws Exception {

env.addGroovyClass(paths[1], "q", "DefaultNamed",
"package q;\n" +
"public class DefaultNamed {\n" +
"class DefaultNamed {\n" +
" public String name() { 'name' }\n" +
"}\n");

Expand Down Expand Up @@ -2844,6 +2844,55 @@ public void testTraitBinary() throws Exception {
executeClass(paths[0], "Runner", "new name", "");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/733
public void testTraitGenerics() throws Exception {
IPath[] paths = createSimpleProject("Project", true);

env.addGroovyClass(paths[1], "p", "Event",
"package p\n" +
"class Event<T> {\n" +
" Event(String id, T payload) {\n" +
" }\n" +
" Event<T> setReplyTo(Object replyTo) {\n" +
" }\n" +
"}\n");

env.addGroovyClass(paths[1], "p", "Events",
"package p\n" +
"@groovy.transform.CompileStatic\n" +
"trait Events {\n" +
" def <E extends Event<?>> Registration<Object, Closure<E>> on(Class key, Closure consumer) {\n" +
" }\n" +
"}\n" +
"interface Registration<K, V> {}\n");

env.addGroovyClass(paths[1], "q", "Service",
"package q\n" +
"class Service implements p.Events {\n" +
"}\n");

env.addGroovyClass(paths[1], "q", "ServiceWrapper",
"package q\n" +
"class ServiceWrapper {\n" +
" Service service\n" +
"}\n");

fullBuild(paths[0]);
expectingNoProblems();

// modify the body of the wrapper
env.addGroovyClass(paths[1], "q", "ServiceWrapper",
"package q\n" +
"class ServiceWrapper {\n" +
" Service service\n" +
" def logger\n" +
"}\n");

incrementalBuild(paths[0]);
expectingCompiledClasses("q.ServiceWrapper");
expectingNoProblems(); // not "Inconsistent classfile encountered: The undefined type parameter T is referenced from within Service"
}

@Test // see GroovyCompilationUnitDeclaration#processToPhase(int)
public void testTraitGRE1776() throws Exception {
IPath[] paths = createSimpleProject("Project", true);
Expand All @@ -2856,7 +2905,7 @@ public void testTraitGRE1776() throws Exception {
env.addGroovyClass(paths[1], "q", "MyClass",
"package q\n" +
"import p.MyTrait\n" +
"public class MyClass implements MyTrait {}\n");
"class MyClass implements MyTrait {}\n");

incrementalBuild(paths[0]);
expectingCompiledClasses("p.MyTrait", "p.MyTrait$Trait$Helper", "q.MyClass");
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy24/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<file-match-pattern match-pattern="groovy/ast/expr/LambdaExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/expr/MethodCallExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/expr/StaticMethodCallExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/tools/GenericsUtils.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/AnnotationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/AsmClassGenerator.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/ClassCompletionVerifier.java" include-pattern="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void setHasInconsistentHierarchy(boolean b) {
private Map<CompilePhase, Map<Class<? extends ASTTransformation>, Set<ASTNode>>> transformInstances;

// use this to synchronize access for the lazy init
protected Object lazyInitLock = new Object();
protected final Object lazyInitLock = new Object();

// clazz!=null when resolved
protected Class clazz;
Expand All @@ -199,8 +199,7 @@ public void setHasInconsistentHierarchy(boolean b) {
protected ClassNode componentType;
// if not null this instance is handled as proxy
// for the redirect
// GRECLIPSE private->protected
protected ClassNode redirect;
private ClassNode redirect;
// flag if the classes or its members are annotated
private boolean annotated;

Expand Down Expand Up @@ -1311,7 +1310,7 @@ public String toString(boolean showRedirect) {
ret.append(">");
}
if (redirect != null && showRedirect) {
ret.append(" -> ").append(redirect().toString());
ret.append(" -> ").append(redirect.toString());
}
return ret.toString();
}
Expand Down Expand Up @@ -1541,6 +1540,17 @@ public boolean isAnnotated() {
return this.annotated;
}

// GRECLIPSE add
public GenericsType asGenericsType() {
if (!isGenericsPlaceHolder()) {
return new GenericsType(this);
} else {
ClassNode upper = (redirect != null ? redirect : this);
return new GenericsType(this, new ClassNode[]{upper}, null);
}
}
// GRECLIPSE end

public GenericsType[] getGenericsTypes() {
return genericsTypes;
}
Expand Down
Loading

0 comments on commit 3f0e2f1

Please sign in to comment.