Skip to content

Commit f3ec07f

Browse files
jameskleehDanny02
andauthored
Fix introspections on overridden methods in interfaces with generic return type (micronaut-projects#3965)
* collect most specific type * Don't include return type in the method signature. Restore changes to abstract element spec Co-authored-by: Daniel Heinrich <dannynullzwo@gmail.com>
1 parent be78011 commit f3ec07f

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

inject-java-test/src/main/groovy/io/micronaut/annotation/processing/test/AbstractTypeElementSpec.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.micronaut.annotation.processing.test
1717

18+
import com.google.testing.compile.JavaFileObjects
1819
import com.sun.tools.javac.model.JavacElements
1920
import com.sun.tools.javac.processing.JavacProcessingEnvironment
2021
import com.sun.tools.javac.util.Context

inject-java-test/src/test/groovy/io/micronaut/inject/visitor/beans/BeanIntrospectionSpec.groovy

+59
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,65 @@ import java.lang.reflect.Field
3535

3636
class BeanIntrospectionSpec extends AbstractTypeElementSpec {
3737

38+
39+
void "test bean introspection with property of generic interface"() {
40+
given:
41+
BeanIntrospection introspection = buildBeanIntrospection('test.Foo', '''
42+
package test;
43+
44+
@io.micronaut.core.annotation.Introspected
45+
class Foo implements GenBase<String> {
46+
public String getName() {
47+
return "test";
48+
}
49+
}
50+
51+
interface GenBase<T> {
52+
T getName();
53+
}
54+
''')
55+
when:
56+
def test = introspection.instantiate()
57+
58+
then:
59+
introspection.getRequiredProperty("name", String)
60+
.get(test) == 'test'
61+
}
62+
63+
void "test bean introspection with argument of generic interface"() {
64+
given:
65+
BeanIntrospection introspection = buildBeanIntrospection('test.Foo', '''
66+
package test;
67+
68+
@io.micronaut.core.annotation.Introspected
69+
class Foo implements GenBase<Long> {
70+
71+
private Long value;
72+
73+
public Long getValue() {
74+
return value;
75+
}
76+
77+
public void setValue(Long value) {
78+
this.value = value;
79+
}
80+
}
81+
82+
interface GenBase<T> {
83+
T getValue();
84+
85+
void setValue(T t);
86+
}
87+
''')
88+
when:
89+
def test = introspection.instantiate()
90+
BeanProperty bp = introspection.getRequiredProperty("value", Long)
91+
bp.set(test, 5L)
92+
93+
then:
94+
bp.get(test) == 5L
95+
}
96+
3897
void "test bean introspection with property with static creator method on interface"() {
3998
given:
4099
BeanIntrospection introspection = buildBeanIntrospection('test.Foo', '''

inject-java/src/main/java/io/micronaut/annotation/processing/SuperclassAwareTypeVisitor.java

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public R visitDeclared(DeclaredType type, P p) {
6464
ExecutableElement ee = (ExecutableElement) enclosedElement;
6565
String qualifiedName = ee.getSimpleName().toString();
6666
qualifiedName += "(" + ee.getParameters().stream().map(variableElement -> types.erasure(variableElement.asType()).toString()).collect(Collectors.joining(",")) + ")";
67-
qualifiedName = types.erasure(ee.getReturnType()).toString() + "." + qualifiedName;
6867
// if the method has already been processed then it is overridden so ignore
6968
if (!processed.contains(qualifiedName)) {
7069
processed.add(qualifiedName);

0 commit comments

Comments
 (0)