Skip to content

Commit 1e7d954

Browse files
committed
MethodMetadata exposes method return type
Issue: SPR-13024
1 parent 441ed80 commit 1e7d954

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

spring-core/src/main/java/org/springframework/core/type/MethodMetadata.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public interface MethodMetadata extends AnnotatedTypeMetadata {
3939
/**
4040
* Return the fully-qualified name of the class that declares this method.
4141
*/
42-
public String getDeclaringClassName();
42+
String getDeclaringClassName();
43+
44+
/**
45+
* Return the fully-qualified name of this method's declared return type.
46+
* @since 4.2
47+
*/
48+
String getReturnTypeName();
4349

4450
/**
4551
* Return whether the underlying method is effectively abstract:

spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public String getDeclaringClassName() {
8484
return this.introspectedMethod.getDeclaringClass().getName();
8585
}
8686

87+
@Override
88+
public String getReturnTypeName() {
89+
return this.introspectedMethod.getReturnType().getName();
90+
}
91+
8792
@Override
8893
public boolean isAbstract() {
8994
return Modifier.isAbstract(this.introspectedMethod.getModifiers());

spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
7676
if ((access & Opcodes.ACC_BRIDGE) != 0) {
7777
return super.visitMethod(access, name, desc, signature, exceptions);
7878
}
79-
return new MethodMetadataReadingVisitor(name, access, getClassName(), this.classLoader, this.methodMetadataSet);
79+
return new MethodMetadataReadingVisitor(name, access, getClassName(),
80+
Type.getReturnType(desc).getClassName(), this.classLoader, this.methodMetadataSet);
8081
}
8182

8283
@Override

spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@
4444
*/
4545
public class MethodMetadataReadingVisitor extends MethodVisitor implements MethodMetadata {
4646

47-
protected final String name;
47+
protected final String methodName;
4848

4949
protected final int access;
5050

5151
protected final String declaringClassName;
5252

53+
protected final String returnTypeName;
54+
5355
protected final ClassLoader classLoader;
5456

5557
protected final Set<MethodMetadata> methodMetadataSet;
@@ -58,13 +60,14 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho
5860
new LinkedMultiValueMap<String, AnnotationAttributes>(4);
5961

6062

61-
public MethodMetadataReadingVisitor(String name, int access, String declaringClassName,
62-
ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) {
63+
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName,
64+
String returnTypeName, ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) {
6365

6466
super(SpringAsmInfo.ASM_VERSION);
65-
this.name = name;
67+
this.methodName = methodName;
6668
this.access = access;
6769
this.declaringClassName = declaringClassName;
70+
this.returnTypeName = returnTypeName;
6871
this.classLoader = classLoader;
6972
this.methodMetadataSet = methodMetadataSet;
7073
}
@@ -79,7 +82,7 @@ public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
7982

8083
@Override
8184
public String getMethodName() {
82-
return this.name;
85+
return this.methodName;
8386
}
8487

8588
@Override
@@ -144,4 +147,9 @@ public String getDeclaringClassName() {
144147
return this.declaringClassName;
145148
}
146149

150+
@Override
151+
public String getReturnTypeName() {
152+
return this.returnTypeName;
153+
}
154+
147155
}

0 commit comments

Comments
 (0)