Skip to content

Commit 20b35f0

Browse files
committed
Add visibility and return type to SimpleMethodMetadata toString
Closes gh-34649
1 parent 7d0cc6c commit 20b35f0

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassAndBeanMethodTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ void verifyToString() throws Exception {
128128
.startsWith("ConfigurationClass: beanName 'Config1', class path resource");
129129

130130
List<BeanMethod> beanMethods = getBeanMethods(configurationClass);
131-
String prefix = "BeanMethod: " + Config1.class.getName();
131+
String prefix = "BeanMethod: java.lang.String " + Config1.class.getName();
132132
assertThat(beanMethods.get(0).toString()).isEqualTo(prefix + ".bean0()");
133133
assertThat(beanMethods.get(1).toString()).isEqualTo(prefix + ".bean1(java.lang.String)");
134134
assertThat(beanMethods.get(2).toString()).isEqualTo(prefix + ".bean2(java.lang.String,java.lang.Integer)");

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

+30-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.asm.AnnotationVisitor;
2626
import org.springframework.asm.MethodVisitor;
27+
import org.springframework.asm.Opcodes;
2728
import org.springframework.asm.SpringAsmInfo;
2829
import org.springframework.asm.Type;
2930
import org.springframework.core.annotation.MergedAnnotation;
@@ -87,7 +88,7 @@ public void visitEnd() {
8788
private Object getSource() {
8889
Source source = this.source;
8990
if (source == null) {
90-
source = new Source(this.declaringClassName, this.methodName, this.descriptor);
91+
source = new Source(this.declaringClassName, this.methodName, this.access, this.descriptor);
9192
this.source = source;
9293
}
9394
return source;
@@ -103,13 +104,16 @@ static final class Source {
103104

104105
private final String methodName;
105106

107+
private final int access;
108+
106109
private final String descriptor;
107110

108111
private @Nullable String toStringValue;
109112

110-
Source(String declaringClassName, String methodName, String descriptor) {
113+
Source(String declaringClassName, String methodName, int access, String descriptor) {
111114
this.declaringClassName = declaringClassName;
112115
this.methodName = methodName;
116+
this.access = access;
113117
this.descriptor = descriptor;
114118
}
115119

@@ -118,6 +122,7 @@ public int hashCode() {
118122
int result = 1;
119123
result = 31 * result + this.declaringClassName.hashCode();
120124
result = 31 * result + this.methodName.hashCode();
125+
result = 31 * result + this.access;
121126
result = 31 * result + this.descriptor.hashCode();
122127
return result;
123128
}
@@ -132,14 +137,36 @@ public boolean equals(@Nullable Object other) {
132137
}
133138
Source otherSource = (Source) other;
134139
return (this.declaringClassName.equals(otherSource.declaringClassName) &&
135-
this.methodName.equals(otherSource.methodName) && this.descriptor.equals(otherSource.descriptor));
140+
this.methodName.equals(otherSource.methodName) &&
141+
this.access == otherSource.access && this.descriptor.equals(otherSource.descriptor));
136142
}
137143

138144
@Override
139145
public String toString() {
140146
String value = this.toStringValue;
141147
if (value == null) {
142148
StringBuilder builder = new StringBuilder();
149+
if ((this.access & Opcodes.ACC_PUBLIC) != 0) {
150+
builder.append("public ");
151+
}
152+
if ((this.access & Opcodes.ACC_PROTECTED) != 0) {
153+
builder.append("protected ");
154+
}
155+
if ((this.access & Opcodes.ACC_PRIVATE) != 0) {
156+
builder.append("private ");
157+
}
158+
if ((this.access & Opcodes.ACC_ABSTRACT) != 0) {
159+
builder.append("abstract ");
160+
}
161+
if ((this.access & Opcodes.ACC_STATIC) != 0) {
162+
builder.append("static ");
163+
}
164+
if ((this.access & Opcodes.ACC_FINAL) != 0) {
165+
builder.append("final ");
166+
}
167+
Type returnType = Type.getReturnType(this.descriptor);
168+
builder.append(returnType.getClassName());
169+
builder.append(' ');
143170
builder.append(this.declaringClassName);
144171
builder.append('.');
145172
builder.append(this.methodName);

0 commit comments

Comments
 (0)