mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Polishing
This commit is contained in:
+1
@@ -37,4 +37,5 @@ abstract class MetadataReaderFactoryDelegate {
|
||||
static MetadataReaderFactory create(@Nullable ClassLoader classLoader) {
|
||||
return new SimpleMetadataReaderFactory(classLoader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-5
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
|
||||
import java.lang.classfile.Annotation;
|
||||
import java.lang.classfile.AnnotationElement;
|
||||
import java.lang.classfile.AnnotationValue;
|
||||
@@ -42,11 +41,15 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* Parse {@link RuntimeVisibleAnnotationsAttribute} into {@link MergedAnnotations}
|
||||
* instances.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
*/
|
||||
abstract class ClassFileAnnotationMetadata {
|
||||
|
||||
static MergedAnnotations createMergedAnnotations(String className, RuntimeVisibleAnnotationsAttribute annotationAttribute, @Nullable ClassLoader classLoader) {
|
||||
static MergedAnnotations createMergedAnnotations(
|
||||
String className, RuntimeVisibleAnnotationsAttribute annotationAttribute, @Nullable ClassLoader classLoader) {
|
||||
|
||||
Set<MergedAnnotation<?>> annotations = annotationAttribute.annotations()
|
||||
.stream()
|
||||
.map(ann -> createMergedAnnotation(className, ann, classLoader))
|
||||
@@ -56,7 +59,9 @@ abstract class ClassFileAnnotationMetadata {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <A extends java.lang.annotation.Annotation> @Nullable MergedAnnotation<A> createMergedAnnotation(String className, Annotation annotation, @Nullable ClassLoader classLoader) {
|
||||
private static <A extends java.lang.annotation.Annotation> @Nullable MergedAnnotation<A> createMergedAnnotation(
|
||||
String className, Annotation annotation, @Nullable ClassLoader classLoader) {
|
||||
|
||||
String typeName = fromTypeDescriptor(annotation.className().stringValue());
|
||||
if (AnnotationFilter.PLAIN.matches(typeName)) {
|
||||
return null;
|
||||
@@ -78,7 +83,9 @@ abstract class ClassFileAnnotationMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable Object readAnnotationValue(String className, AnnotationValue elementValue, @Nullable ClassLoader classLoader) {
|
||||
private static @Nullable Object readAnnotationValue(
|
||||
String className, AnnotationValue elementValue, @Nullable ClassLoader classLoader) {
|
||||
|
||||
switch (elementValue) {
|
||||
case AnnotationValue.OfConstant constantValue -> {
|
||||
return constantValue.resolvedValue();
|
||||
@@ -168,7 +175,6 @@ abstract class ClassFileAnnotationMetadata {
|
||||
|
||||
|
||||
record Source(Annotation entryName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-1
@@ -42,7 +42,9 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* {@link AnnotationMetadata} implementation that leverages
|
||||
* the {@link java.lang.classfile.ClassFile} API.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
*/
|
||||
class ClassFileClassMetadata implements AnnotationMetadata {
|
||||
|
||||
@@ -66,9 +68,11 @@ class ClassFileClassMetadata implements AnnotationMetadata {
|
||||
|
||||
private @Nullable Set<String> annotationTypes;
|
||||
|
||||
|
||||
ClassFileClassMetadata(String className, AccessFlags accessFlags, @Nullable String enclosingClassName,
|
||||
@Nullable String superClassName, boolean independentInnerClass, Set<String> interfaceNames,
|
||||
Set<String> memberClassNames, Set<MethodMetadata> declaredMethods, MergedAnnotations mergedAnnotations) {
|
||||
|
||||
this.className = className;
|
||||
this.accessFlags = accessFlags;
|
||||
this.enclosingClassName = enclosingClassName;
|
||||
@@ -80,6 +84,7 @@ class ClassFileClassMetadata implements AnnotationMetadata {
|
||||
this.mergedAnnotations = mergedAnnotations;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.className;
|
||||
@@ -215,6 +220,7 @@ class ClassFileClassMetadata implements AnnotationMetadata {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
static class Builder {
|
||||
|
||||
private final ClassLoader clasLoader;
|
||||
@@ -297,7 +303,6 @@ class ClassFileClassMetadata implements AnnotationMetadata {
|
||||
return new ClassFileClassMetadata(this.className, this.accessFlags, this.enclosingClassName, this.superClassName,
|
||||
independentInnerClass, this.interfaceNames, this.memberClassNames, this.declaredMethods, this.mergedAnnotations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -31,6 +31,7 @@ import org.springframework.core.type.ClassMetadata;
|
||||
* {@link MetadataReader} implementation based on the {@link ClassFile} API.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
*/
|
||||
final class ClassFileMetadataReader implements MetadataReader {
|
||||
|
||||
@@ -51,6 +52,7 @@ final class ClassFileMetadataReader implements MetadataReader {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Resource getResource() {
|
||||
return this.resource;
|
||||
|
||||
+2
-1
@@ -32,7 +32,6 @@ import org.springframework.core.io.ResourceLoader;
|
||||
*/
|
||||
public class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactory {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ClassFileMetadataReaderFactory for the default class loader.
|
||||
*/
|
||||
@@ -57,8 +56,10 @@ public class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactor
|
||||
super(classLoader);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MetadataReader getMetadataReader(Resource resource) throws IOException {
|
||||
return new ClassFileMetadataReader(resource, getResourceLoader().getClassLoader());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-5
@@ -37,7 +37,9 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* {@link MethodMetadata} extracted from class bytecode using the
|
||||
* {@link java.lang.classfile.ClassFile} API.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
*/
|
||||
class ClassFileMethodMetadata implements MethodMetadata {
|
||||
|
||||
@@ -54,7 +56,10 @@ class ClassFileMethodMetadata implements MethodMetadata {
|
||||
|
||||
private final MergedAnnotations annotations;
|
||||
|
||||
ClassFileMethodMetadata(String methodName, AccessFlags accessFlags, @Nullable String declaringClassName, String returnTypeName, Object source, MergedAnnotations annotations) {
|
||||
|
||||
ClassFileMethodMetadata(String methodName, AccessFlags accessFlags, @Nullable String declaringClassName,
|
||||
String returnTypeName, Object source, MergedAnnotations annotations) {
|
||||
|
||||
this.methodName = methodName;
|
||||
this.accessFlags = accessFlags;
|
||||
this.declaringClassName = declaringClassName;
|
||||
@@ -63,6 +68,7 @@ class ClassFileMethodMetadata implements MethodMetadata {
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return this.methodName;
|
||||
@@ -131,6 +137,7 @@ class ClassFileMethodMetadata implements MethodMetadata {
|
||||
return this.source.toString();
|
||||
}
|
||||
|
||||
|
||||
static ClassFileMethodMetadata of(MethodModel methodModel, ClassLoader classLoader) {
|
||||
String methodName = methodModel.methodName().stringValue();
|
||||
AccessFlags flags = methodModel.flags();
|
||||
@@ -146,13 +153,13 @@ class ClassFileMethodMetadata implements MethodMetadata {
|
||||
return new ClassFileMethodMetadata(methodName, flags, declaringClassName, returnTypeName, source, annotations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link MergedAnnotation} source.
|
||||
*
|
||||
* @param declaringClassName the name of the declaring class
|
||||
* @param flags the access flags
|
||||
* @param methodName the name of the method
|
||||
* @param descriptor the bytecode descriptor for this method
|
||||
* @param flags the access flags
|
||||
* @param methodName the name of the method
|
||||
* @param descriptor the bytecode descriptor for this method
|
||||
*/
|
||||
record Source(@Nullable String declaringClassName, AccessFlags flags, String methodName, MethodTypeDesc descriptor) {
|
||||
|
||||
|
||||
+2
@@ -25,6 +25,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||
* For JDK >= 24, the {@link ClassFileMetadataReaderFactory} is being used.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
* @see MetadataReaderFactory
|
||||
*/
|
||||
abstract class MetadataReaderFactoryDelegate {
|
||||
@@ -36,4 +37,5 @@ abstract class MetadataReaderFactoryDelegate {
|
||||
static MetadataReaderFactory create(@Nullable ClassLoader classLoader) {
|
||||
return new ClassFileMetadataReaderFactory(classLoader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user