Skip to content

Commit 5f2a10c

Browse files
committed
Remove own class reading infrastructure in favor of extensions to AnnotationMetadata.
We now remove fully our own class-reading visitors as AnnotationMetadata exposes getDeclaredMethods. MethodsMetadataReaderFactory and MethodsMetadataReader remain deprecated bridging return types to retain backward compatibility. Closes #2520
1 parent 2adca7e commit 5f2a10c

13 files changed

+232
-1297
lines changed

src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
import org.springframework.beans.BeanUtils;
3333
import org.springframework.core.log.LogMessage;
34+
import org.springframework.core.type.AnnotationMetadata;
3435
import org.springframework.core.type.MethodMetadata;
35-
import org.springframework.data.type.MethodsMetadata;
36-
import org.springframework.data.type.classreading.MethodsMetadataReaderFactory;
36+
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
3737
import org.springframework.data.util.StreamUtils;
3838
import org.springframework.util.Assert;
3939
import org.springframework.util.ClassUtils;
@@ -133,7 +133,7 @@ private static class PropertyDescriptorSource {
133133
private static final Log logger = LogFactory.getLog(PropertyDescriptorSource.class);
134134

135135
private final Class<?> type;
136-
private final Optional<MethodsMetadata> metadata;
136+
private final Optional<AnnotationMetadata> metadata;
137137

138138
/**
139139
* Creates a new {@link PropertyDescriptorSource} for the given type.
@@ -179,15 +179,15 @@ private Stream<PropertyDescriptor> collectDescriptors() {
179179
}
180180

181181
/**
182-
* Returns a {@link Stream} of {@link PropertyDescriptor} ordered following the given {@link MethodsMetadata} only
183-
* returning methods seen by the given {@link MethodsMetadata}.
182+
* Returns a {@link Stream} of {@link PropertyDescriptor} ordered following the given {@link AnnotationMetadata}
183+
* only returning methods seen by the given {@link AnnotationMetadata}.
184184
*
185185
* @param source must not be {@literal null}.
186186
* @param metadata must not be {@literal null}.
187187
* @return
188188
*/
189189
private static Stream<PropertyDescriptor> filterAndOrder(Stream<PropertyDescriptor> source,
190-
MethodsMetadata metadata) {
190+
AnnotationMetadata metadata) {
191191

192192
var orderedMethods = getMethodOrder(metadata);
193193

@@ -201,12 +201,12 @@ private static Stream<PropertyDescriptor> filterAndOrder(Stream<PropertyDescript
201201
}
202202

203203
/**
204-
* Returns a {@link Stream} of interfaces using the given {@link MethodsMetadata} as primary source for ordering.
204+
* Returns a {@link Stream} of interfaces using the given {@link AnnotationMetadata} as primary source for ordering.
205205
*
206206
* @param metadata must not be {@literal null}.
207207
* @return
208208
*/
209-
private Stream<Class<?>> fromMetadata(MethodsMetadata metadata) {
209+
private Stream<Class<?>> fromMetadata(AnnotationMetadata metadata) {
210210
return Arrays.stream(metadata.getInterfaceNames()).map(it -> findType(it, type.getInterfaces()));
211211
}
212212

@@ -220,20 +220,20 @@ private Stream<Class<?>> fromType() {
220220
}
221221

222222
/**
223-
* Attempts to obtain {@link MethodsMetadata} from {@link Class}. Returns {@link Optional} containing
224-
* {@link MethodsMetadata} if metadata was read successfully, {@link Optional#empty()} otherwise.
223+
* Attempts to obtain {@link AnnotationMetadata} from {@link Class}. Returns {@link Optional} containing
224+
* {@link AnnotationMetadata} if metadata was read successfully, {@link Optional#empty()} otherwise.
225225
*
226226
* @param type must not be {@literal null}.
227-
* @return the optional {@link MethodsMetadata}.
227+
* @return the optional {@link AnnotationMetadata}.
228228
*/
229-
private static Optional<MethodsMetadata> getMetadata(Class<?> type) {
229+
private static Optional<AnnotationMetadata> getMetadata(Class<?> type) {
230230

231231
try {
232232

233-
var factory = new MethodsMetadataReaderFactory(type.getClassLoader());
233+
var factory = new SimpleMetadataReaderFactory(type.getClassLoader());
234234
var metadataReader = factory.getMetadataReader(ClassUtils.getQualifiedName(type));
235235

236-
return Optional.of(metadataReader.getMethodsMetadata());
236+
return Optional.of(metadataReader.getAnnotationMetadata());
237237

238238
} catch (IOException e) {
239239

@@ -259,18 +259,18 @@ private static Class<?> findType(String name, Class<?>[] types) {
259259
}
260260

261261
/**
262-
* Returns a {@link Map} containing method name to its positional index according to {@link MethodsMetadata}.
262+
* Returns a {@link Map} containing method name to its positional index according to {@link AnnotationMetadata}.
263263
*
264264
* @param metadata
265265
* @return
266266
*/
267-
private static Map<String, Integer> getMethodOrder(MethodsMetadata metadata) {
267+
private static Map<String, Integer> getMethodOrder(AnnotationMetadata metadata) {
268268

269-
var methods = metadata.getMethods() //
269+
var methods = metadata.getDeclaredMethods() //
270270
.stream() //
271271
.map(MethodMetadata::getMethodName) //
272272
.distinct() //
273-
.collect(Collectors.toList());
273+
.toList();
274274

275275
return IntStream.range(0, methods.size()) //
276276
.boxed() //

src/main/java/org/springframework/data/type/MethodsMetadata.java

+5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
import java.util.Set;
1919

20+
import org.springframework.core.type.AnnotationMetadata;
2021
import org.springframework.core.type.ClassMetadata;
2122
import org.springframework.core.type.MethodMetadata;
23+
import org.springframework.core.type.classreading.MetadataReader;
2224
import org.springframework.data.type.classreading.MethodsMetadataReader;
2325

2426
/**
@@ -30,7 +32,10 @@
3032
* @see MethodMetadata
3133
* @see ClassMetadata
3234
* @see MethodsMetadataReader#getMethodsMetadata()
35+
* @deprecated since 3.0, use {@link MetadataReader} directly to obtain {@link AnnotationMetadata#getDeclaredMethods()
36+
* declared methods} directly.
3337
*/
38+
@Deprecated
3439
public interface MethodsMetadata extends ClassMetadata {
3540

3641
/**

src/main/java/org/springframework/data/type/classreading/AbstractRecursiveAnnotationVisitor.java

-99
This file was deleted.

src/main/java/org/springframework/data/type/classreading/AnnotationAttributesReadingVisitor.java

-119
This file was deleted.

0 commit comments

Comments
 (0)