Skip to content

Commit

Permalink
Fix for #1563: declaring type when inferred type is type variable
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 30, 2024
1 parent ab13344 commit 29e6a48
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,55 @@ public void testArrayDGM() {
assertEquals("First parameter type should be resolved from object expression", "java.lang.String[]", printTypeName(dgm.getParameters()[0].getType()));
}

@Test
public void testTypeVariable1() {
String contents =
"class C<T> {\n" +
" void test(T t) {\n" +
" t.notify()\n" +
" }\n" +
"}\n";

assertType(contents, "notify", "java.lang.Void");
assertDeclaringType(contents, "notify", "java.lang.Object");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1563
public void testTypeVariable2() {
String contents =
"class C<T extends Thread> {\n" +
" void test(T thread) {\n" +
" thread.getName()\n" +
" thread.name\n" +
" }\n" +
"}\n";

assertType(contents, "name", "java.lang.String");
assertDeclaringType(contents, "name", "java.lang.Thread");

assertType(contents, "getName", "java.lang.String");
assertDeclaringType(contents, "getName", "java.lang.Thread");
}

@Test
public void testTypeVariable3() {
String contents =
"class C<T extends Thread> {\n" +
" void test(T thread) {\n" +
" thread.with {" +
" getName()\n" +
" name\n" +
" }\n" +
" }\n" +
"}\n";

assertType(contents, "name", "java.lang.String");
assertDeclaringType(contents, "name", "java.lang.Thread");

assertType(contents, "getName", "java.lang.String");
assertDeclaringType(contents, "getName", "java.lang.Thread");
}

@Test // GRECLIPSE-997
public void testNestedGenerics1() {
String contents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,11 @@ protected static ClassNode getDeclaringTypeFromDeclaration(final ASTNode declara
declaringType = VariableScope.OBJECT_CLASS_NODE;
}
// retain inferredDeclaringType's generics if possible
if (inferredDeclaringType.equals(declaringType)) {
if (inferredDeclaringType.equals(declaringType) &&
!inferredDeclaringType.isGenericsPlaceHolder()) {
return inferredDeclaringType;
} else {
return declaringType;
return declaringType.getPlainNodeReference();
}
}

Expand Down

0 comments on commit 29e6a48

Please sign in to comment.