Early removal of 5.x-deprecated code
Closes gh-27686
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -207,17 +207,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code StringDecoder} for {@code "text/plain"}.
|
||||
* @param stripDelimiter this flag is ignored
|
||||
* @deprecated as of Spring 5.0.4, in favor of {@link #textPlainOnly()} or
|
||||
* {@link #textPlainOnly(List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static StringDecoder textPlainOnly(boolean stripDelimiter) {
|
||||
return textPlainOnly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code StringDecoder} for {@code "text/plain"}.
|
||||
*/
|
||||
@@ -235,17 +224,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||
return new StringDecoder(delimiters, stripDelimiter, new MimeType("text", "plain", DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code StringDecoder} that supports all MIME types.
|
||||
* @param stripDelimiter this flag is ignored
|
||||
* @deprecated as of Spring 5.0.4, in favor of {@link #allMimeTypes()} or
|
||||
* {@link #allMimeTypes(List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static StringDecoder allMimeTypes(boolean stripDelimiter) {
|
||||
return allMimeTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code StringDecoder} that supports all MIME types.
|
||||
*/
|
||||
|
||||
@@ -99,22 +99,6 @@ public class ClassPathResource extends AbstractFileResolvingResource {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code ClassPathResource} with optional {@code ClassLoader}
|
||||
* and {@code Class}. Only for internal usage.
|
||||
* @param path relative or absolute path within the classpath
|
||||
* @param classLoader the class loader to load the resource with, if any
|
||||
* @param clazz the class to load resources with, if any
|
||||
* @deprecated as of 4.3.13, in favor of selective use of
|
||||
* {@link #ClassPathResource(String, ClassLoader)} vs {@link #ClassPathResource(String, Class)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected ClassPathResource(String path, @Nullable ClassLoader classLoader, @Nullable Class<?> clazz) {
|
||||
this.path = StringUtils.cleanPath(path);
|
||||
this.classLoader = classLoader;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the path for this resource (as resource path within the class path).
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.asm.SpringAsmInfo;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* {@link AnnotationVisitor} to recursively visit annotations.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.1.1
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected final AnnotationAttributes attributes;
|
||||
|
||||
@Nullable
|
||||
protected final ClassLoader classLoader;
|
||||
|
||||
|
||||
public AbstractRecursiveAnnotationVisitor(@Nullable ClassLoader classLoader, AnnotationAttributes attributes) {
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
this.classLoader = classLoader;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(String attributeName, Object attributeValue) {
|
||||
this.attributes.put(attributeName, attributeValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
|
||||
String annotationType = Type.getType(asmTypeDescriptor).getClassName();
|
||||
AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
|
||||
this.attributes.put(attributeName, nestedAttributes);
|
||||
return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitArray(String attributeName) {
|
||||
return new RecursiveAnnotationArrayVisitor(attributeName, this.attributes, this.classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnum(String attributeName, String asmTypeDescriptor, String attributeValue) {
|
||||
Object newValue = getEnumValue(asmTypeDescriptor, attributeValue);
|
||||
visit(attributeName, newValue);
|
||||
}
|
||||
|
||||
protected Object getEnumValue(String asmTypeDescriptor, String attributeValue) {
|
||||
Object valueToUse = attributeValue;
|
||||
try {
|
||||
Class<?> enumType = ClassUtils.forName(Type.getType(asmTypeDescriptor).getClassName(), this.classLoader);
|
||||
Field enumConstant = ReflectionUtils.findField(enumType, attributeValue);
|
||||
if (enumConstant != null) {
|
||||
ReflectionUtils.makeAccessible(enumConstant);
|
||||
valueToUse = enumConstant.get(null);
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
logger.debug("Failed to classload enum type while reading annotation metadata", ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
logger.debug("Could not access enum value while reading annotation metadata", ex);
|
||||
}
|
||||
return valueToUse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* ASM visitor which looks for annotations defined on a class or method,
|
||||
* including meta-annotations.
|
||||
*
|
||||
* <p>This visitor is fully recursive, taking into account any nested
|
||||
* annotations or nested annotation arrays.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttributesVisitor {
|
||||
|
||||
private final MultiValueMap<String, AnnotationAttributes> attributesMap;
|
||||
|
||||
private final Map<String, Set<String>> metaAnnotationMap;
|
||||
|
||||
|
||||
public AnnotationAttributesReadingVisitor(String annotationType,
|
||||
MultiValueMap<String, AnnotationAttributes> attributesMap, Map<String, Set<String>> metaAnnotationMap,
|
||||
@Nullable ClassLoader classLoader) {
|
||||
|
||||
super(annotationType, new AnnotationAttributes(annotationType, classLoader), classLoader);
|
||||
this.attributesMap = attributesMap;
|
||||
this.metaAnnotationMap = metaAnnotationMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
super.visitEnd();
|
||||
|
||||
Class<? extends Annotation> annotationClass = this.attributes.annotationType();
|
||||
if (annotationClass != null) {
|
||||
List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
|
||||
if (attributeList == null) {
|
||||
this.attributesMap.add(this.annotationType, this.attributes);
|
||||
}
|
||||
else {
|
||||
attributeList.add(0, this.attributes);
|
||||
}
|
||||
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) {
|
||||
try {
|
||||
Annotation[] metaAnnotations = annotationClass.getAnnotations();
|
||||
if (!ObjectUtils.isEmpty(metaAnnotations)) {
|
||||
Set<Annotation> visited = new LinkedHashSet<>();
|
||||
for (Annotation metaAnnotation : metaAnnotations) {
|
||||
recursivelyCollectMetaAnnotations(visited, metaAnnotation);
|
||||
}
|
||||
if (!visited.isEmpty()) {
|
||||
Set<String> metaAnnotationTypeNames = new LinkedHashSet<>(visited.size());
|
||||
for (Annotation ann : visited) {
|
||||
metaAnnotationTypeNames.add(ann.annotationType().getName());
|
||||
}
|
||||
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to introspect meta-annotations on " + annotationClass + ": " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) {
|
||||
Class<? extends Annotation> annotationType = annotation.annotationType();
|
||||
String annotationName = annotationType.getName();
|
||||
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) {
|
||||
try {
|
||||
// Only do attribute scanning for public annotations.
|
||||
if (Modifier.isPublic(annotationType.getModifiers())) {
|
||||
this.attributesMap.add(annotationName,
|
||||
AnnotationUtils.getAnnotationAttributes(annotation, false, true));
|
||||
}
|
||||
for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) {
|
||||
recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Opcodes;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* ASM class visitor which looks for the class name and implemented types as
|
||||
* well as for the annotations defined on the class, exposing them through
|
||||
* the {@link org.springframework.core.type.AnnotationMetadata} interface.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Costin Leau
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @deprecated As of Spring Framework 5.2, this class has been replaced by
|
||||
* {@link SimpleAnnotationMetadataReadingVisitor} for internal use within the
|
||||
* framework, but there is no public replacement for
|
||||
* {@code AnnotationMetadataReadingVisitor}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor implements AnnotationMetadata {
|
||||
|
||||
@Nullable
|
||||
protected final ClassLoader classLoader;
|
||||
|
||||
protected final Set<String> annotationSet = new LinkedHashSet<>(4);
|
||||
|
||||
protected final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<>(4);
|
||||
|
||||
/**
|
||||
* Declared as a {@link LinkedMultiValueMap} instead of a {@link MultiValueMap}
|
||||
* to ensure that the hierarchical ordering of the entries is preserved.
|
||||
* @see AnnotationReadingVisitorUtils#getMergedAnnotationAttributes
|
||||
*/
|
||||
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(3);
|
||||
|
||||
protected final Set<MethodMetadata> methodMetadataSet = new LinkedHashSet<>(4);
|
||||
|
||||
|
||||
public AnnotationMetadataReadingVisitor(@Nullable ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MergedAnnotations getAnnotations() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
// Skip bridge methods - we're only interested in original annotation-defining user methods.
|
||||
// On JDK 8, we'd otherwise run into double detection of the same annotated method...
|
||||
if ((access & Opcodes.ACC_BRIDGE) != 0) {
|
||||
return super.visitMethod(access, name, desc, signature, exceptions);
|
||||
}
|
||||
return new MethodMetadataReadingVisitor(name, access, getClassName(),
|
||||
Type.getReturnType(desc).getClassName(), this.classLoader, this.methodMetadataSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
String className = Type.getType(desc).getClassName();
|
||||
if (AnnotationUtils.isInJavaLangAnnotationPackage(className)) {
|
||||
return null;
|
||||
}
|
||||
this.annotationSet.add(className);
|
||||
return new AnnotationAttributesReadingVisitor(
|
||||
className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getAnnotationTypes() {
|
||||
return this.annotationSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getMetaAnnotationTypes(String annotationName) {
|
||||
Set<String> metaAnnotationTypes = this.metaAnnotationMap.get(annotationName);
|
||||
return (metaAnnotationTypes != null ? metaAnnotationTypes : Collections.emptySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetaAnnotation(String metaAnnotationType) {
|
||||
if (AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotationType)) {
|
||||
return false;
|
||||
}
|
||||
Collection<Set<String>> allMetaTypes = this.metaAnnotationMap.values();
|
||||
for (Set<String> metaTypes : allMetaTypes) {
|
||||
if (metaTypes.contains(metaAnnotationType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotated(String annotationName) {
|
||||
return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
|
||||
this.attributesMap.containsKey(annotationName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnnotation(String annotationName) {
|
||||
return getAnnotationTypes().contains(annotationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationAttributes getAnnotationAttributes(String annotationName, boolean classValuesAsString) {
|
||||
AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(
|
||||
this.attributesMap, this.metaAnnotationMap, annotationName);
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
return AnnotationReadingVisitorUtils.convertClassValues(
|
||||
"class '" + getClassName() + "'", this.classLoader, raw, classValuesAsString);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) {
|
||||
MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>();
|
||||
List<AnnotationAttributes> attributes = this.attributesMap.get(annotationName);
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
}
|
||||
String annotatedElement = "class '" + getClassName() + "'";
|
||||
for (AnnotationAttributes raw : attributes) {
|
||||
for (Map.Entry<String, Object> entry : AnnotationReadingVisitorUtils.convertClassValues(
|
||||
annotatedElement, this.classLoader, raw, classValuesAsString).entrySet()) {
|
||||
allAttributes.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return allAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnnotatedMethods(String annotationName) {
|
||||
for (MethodMetadata methodMetadata : this.methodMetadataSet) {
|
||||
if (methodMetadata.isAnnotated(annotationName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
|
||||
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4);
|
||||
for (MethodMetadata methodMetadata : this.methodMetadataSet) {
|
||||
if (methodMetadata.isAnnotated(annotationName)) {
|
||||
annotatedMethods.add(methodMetadata);
|
||||
}
|
||||
}
|
||||
return annotatedMethods;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Internal utility class used when reading annotations via ASM.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Costin Leau
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 4.0
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
abstract class AnnotationReadingVisitorUtils {
|
||||
|
||||
public static AnnotationAttributes convertClassValues(Object annotatedElement,
|
||||
@Nullable ClassLoader classLoader, AnnotationAttributes original, boolean classValuesAsString) {
|
||||
|
||||
AnnotationAttributes result = new AnnotationAttributes(original);
|
||||
AnnotationUtils.postProcessAnnotationAttributes(annotatedElement, result, classValuesAsString);
|
||||
|
||||
for (Map.Entry<String, Object> entry : result.entrySet()) {
|
||||
try {
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof AnnotationAttributes) {
|
||||
value = convertClassValues(
|
||||
annotatedElement, classLoader, (AnnotationAttributes) value, classValuesAsString);
|
||||
}
|
||||
else if (value instanceof AnnotationAttributes[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = convertClassValues(annotatedElement, classLoader, values[i], classValuesAsString);
|
||||
}
|
||||
value = values;
|
||||
}
|
||||
else if (value instanceof Type) {
|
||||
value = (classValuesAsString ? ((Type) value).getClassName() :
|
||||
ClassUtils.forName(((Type) value).getClassName(), classLoader));
|
||||
}
|
||||
else if (value instanceof Type[] array) {
|
||||
Object[] convArray =
|
||||
(classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
convArray[i] = (classValuesAsString ? array[i].getClassName() :
|
||||
ClassUtils.forName(array[i].getClassName(), classLoader));
|
||||
}
|
||||
value = convArray;
|
||||
}
|
||||
else if (classValuesAsString) {
|
||||
if (value instanceof Class) {
|
||||
value = ((Class<?>) value).getName();
|
||||
}
|
||||
else if (value instanceof Class[]) {
|
||||
Class<?>[] clazzArray = (Class<?>[]) value;
|
||||
String[] newValue = new String[clazzArray.length];
|
||||
for (int i = 0; i < clazzArray.length; i++) {
|
||||
newValue[i] = clazzArray[i].getName();
|
||||
}
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
entry.setValue(value);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// Class not found - can't resolve class reference in annotation attribute.
|
||||
result.put(entry.getKey(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the merged attributes of the annotation of the given type,
|
||||
* if any, from the supplied {@code attributesMap}.
|
||||
* <p>Annotation attribute values appearing <em>lower</em> in the annotation
|
||||
* hierarchy (i.e., closer to the declaring class) will override those
|
||||
* defined <em>higher</em> in the annotation hierarchy.
|
||||
* @param attributesMap the map of annotation attribute lists, keyed by
|
||||
* annotation type name
|
||||
* @param metaAnnotationMap the map of meta annotation relationships,
|
||||
* keyed by annotation type name
|
||||
* @param annotationName the fully qualified class name of the annotation
|
||||
* type to look for
|
||||
* @return the merged annotation attributes, or {@code null} if no
|
||||
* matching annotation is present in the {@code attributesMap}
|
||||
* @since 4.0.3
|
||||
*/
|
||||
@Nullable
|
||||
public static AnnotationAttributes getMergedAnnotationAttributes(
|
||||
LinkedMultiValueMap<String, AnnotationAttributes> attributesMap,
|
||||
Map<String, Set<String>> metaAnnotationMap, String annotationName) {
|
||||
|
||||
// Get the unmerged list of attributes for the target annotation.
|
||||
List<AnnotationAttributes> attributesList = attributesMap.get(annotationName);
|
||||
if (CollectionUtils.isEmpty(attributesList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// To start with, we populate the result with a copy of all attribute values
|
||||
// from the target annotation. A copy is necessary so that we do not
|
||||
// inadvertently mutate the state of the metadata passed to this method.
|
||||
AnnotationAttributes result = new AnnotationAttributes(attributesList.get(0));
|
||||
|
||||
Set<String> overridableAttributeNames = new HashSet<>(result.keySet());
|
||||
overridableAttributeNames.remove(AnnotationUtils.VALUE);
|
||||
|
||||
// Since the map is a LinkedMultiValueMap, we depend on the ordering of
|
||||
// elements in the map and reverse the order of the keys in order to traverse
|
||||
// "down" the annotation hierarchy.
|
||||
List<String> annotationTypes = new ArrayList<>(attributesMap.keySet());
|
||||
Collections.reverse(annotationTypes);
|
||||
|
||||
// No need to revisit the target annotation type:
|
||||
annotationTypes.remove(annotationName);
|
||||
|
||||
for (String currentAnnotationType : annotationTypes) {
|
||||
List<AnnotationAttributes> currentAttributesList = attributesMap.get(currentAnnotationType);
|
||||
if (!ObjectUtils.isEmpty(currentAttributesList)) {
|
||||
Set<String> metaAnns = metaAnnotationMap.get(currentAnnotationType);
|
||||
if (metaAnns != null && metaAnns.contains(annotationName)) {
|
||||
AnnotationAttributes currentAttributes = currentAttributesList.get(0);
|
||||
for (String overridableAttributeName : overridableAttributeNames) {
|
||||
Object value = currentAttributes.get(overridableAttributeName);
|
||||
if (value != null) {
|
||||
// Store the value, potentially overriding a value from an attribute
|
||||
// of the same name found higher in the annotation hierarchy.
|
||||
result.put(overridableAttributeName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.asm.Attribute;
|
||||
import org.springframework.asm.ClassVisitor;
|
||||
import org.springframework.asm.FieldVisitor;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Opcodes;
|
||||
import org.springframework.asm.SpringAsmInfo;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* ASM class visitor which looks only for the class name and implemented types,
|
||||
* exposing them through the {@link org.springframework.core.type.ClassMetadata}
|
||||
* interface.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Costin Leau
|
||||
* @author Mark Fisher
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @since 2.5
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata {
|
||||
|
||||
private String className = "";
|
||||
|
||||
private boolean isInterface;
|
||||
|
||||
private boolean isAnnotation;
|
||||
|
||||
private boolean isAbstract;
|
||||
|
||||
private boolean isFinal;
|
||||
|
||||
@Nullable
|
||||
private String enclosingClassName;
|
||||
|
||||
private boolean independentInnerClass;
|
||||
|
||||
@Nullable
|
||||
private String superClassName;
|
||||
|
||||
private String[] interfaces = new String[0];
|
||||
|
||||
private final Set<String> memberClassNames = new LinkedHashSet<>(4);
|
||||
|
||||
|
||||
public ClassMetadataReadingVisitor() {
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(
|
||||
int version, int access, String name, String signature, @Nullable String supername, String[] interfaces) {
|
||||
|
||||
this.className = ClassUtils.convertResourcePathToClassName(name);
|
||||
this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
|
||||
this.isAnnotation = ((access & Opcodes.ACC_ANNOTATION) != 0);
|
||||
this.isAbstract = ((access & Opcodes.ACC_ABSTRACT) != 0);
|
||||
this.isFinal = ((access & Opcodes.ACC_FINAL) != 0);
|
||||
if (supername != null && !this.isInterface) {
|
||||
this.superClassName = ClassUtils.convertResourcePathToClassName(supername);
|
||||
}
|
||||
this.interfaces = new String[interfaces.length];
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
this.interfaces[i] = ClassUtils.convertResourcePathToClassName(interfaces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOuterClass(String owner, String name, String desc) {
|
||||
this.enclosingClassName = ClassUtils.convertResourcePathToClassName(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) {
|
||||
if (outerName != null) {
|
||||
String fqName = ClassUtils.convertResourcePathToClassName(name);
|
||||
String fqOuterName = ClassUtils.convertResourcePathToClassName(outerName);
|
||||
if (this.className.equals(fqName)) {
|
||||
this.enclosingClassName = fqOuterName;
|
||||
this.independentInnerClass = ((access & Opcodes.ACC_STATIC) != 0);
|
||||
}
|
||||
else if (this.className.equals(fqOuterName)) {
|
||||
this.memberClassNames.add(fqName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSource(String source, String debug) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
|
||||
// no-op
|
||||
return new EmptyAnnotationVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAttribute(Attribute attr) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
|
||||
// no-op
|
||||
return new EmptyFieldVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
// no-op
|
||||
return new EmptyMethodVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterface() {
|
||||
return this.isInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotation() {
|
||||
return this.isAnnotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return this.isAbstract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return this.isFinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIndependent() {
|
||||
return (this.enclosingClassName == null || this.independentInnerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEnclosingClass() {
|
||||
return (this.enclosingClassName != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getEnclosingClassName() {
|
||||
return this.enclosingClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getSuperClassName() {
|
||||
return this.superClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getInterfaceNames() {
|
||||
return this.interfaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMemberClassNames() {
|
||||
return StringUtils.toStringArray(this.memberClassNames);
|
||||
}
|
||||
|
||||
|
||||
private static class EmptyAnnotationVisitor extends AnnotationVisitor {
|
||||
|
||||
public EmptyAnnotationVisitor() {
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String name, String desc) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitArray(String name) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class EmptyMethodVisitor extends MethodVisitor {
|
||||
|
||||
public EmptyMethodVisitor() {
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class EmptyFieldVisitor extends FieldVisitor {
|
||||
|
||||
public EmptyFieldVisitor() {
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.asm.Opcodes;
|
||||
import org.springframework.asm.SpringAsmInfo;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* ASM method visitor which looks for the annotations defined on a method,
|
||||
* exposing them through the {@link org.springframework.core.type.MethodMetadata}
|
||||
* interface.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Pollack
|
||||
* @author Costin Leau
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
* @since 3.0
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MethodMetadataReadingVisitor extends MethodVisitor implements MethodMetadata {
|
||||
|
||||
protected final String methodName;
|
||||
|
||||
protected final int access;
|
||||
|
||||
protected final String declaringClassName;
|
||||
|
||||
protected final String returnTypeName;
|
||||
|
||||
@Nullable
|
||||
protected final ClassLoader classLoader;
|
||||
|
||||
protected final Set<MethodMetadata> methodMetadataSet;
|
||||
|
||||
protected final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<>(4);
|
||||
|
||||
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(3);
|
||||
|
||||
|
||||
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName,
|
||||
String returnTypeName, @Nullable ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) {
|
||||
|
||||
super(SpringAsmInfo.ASM_VERSION);
|
||||
this.methodName = methodName;
|
||||
this.access = access;
|
||||
this.declaringClassName = declaringClassName;
|
||||
this.returnTypeName = returnTypeName;
|
||||
this.classLoader = classLoader;
|
||||
this.methodMetadataSet = methodMetadataSet;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MergedAnnotations getAnnotations() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
this.methodMetadataSet.add(this);
|
||||
String className = Type.getType(desc).getClassName();
|
||||
return new AnnotationAttributesReadingVisitor(
|
||||
className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMethodName() {
|
||||
return this.methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return ((this.access & Opcodes.ACC_ABSTRACT) != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
return ((this.access & Opcodes.ACC_STATIC) != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return ((this.access & Opcodes.ACC_FINAL) != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverridable() {
|
||||
return (!isStatic() && !isFinal() && ((this.access & Opcodes.ACC_PRIVATE) == 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotated(String annotationName) {
|
||||
return this.attributesMap.containsKey(annotationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationAttributes getAnnotationAttributes(String annotationName, boolean classValuesAsString) {
|
||||
AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(
|
||||
this.attributesMap, this.metaAnnotationMap, annotationName);
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
return AnnotationReadingVisitorUtils.convertClassValues(
|
||||
"method '" + getMethodName() + "'", this.classLoader, raw, classValuesAsString);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) {
|
||||
if (!this.attributesMap.containsKey(annotationName)) {
|
||||
return null;
|
||||
}
|
||||
MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>();
|
||||
List<AnnotationAttributes> attributesList = this.attributesMap.get(annotationName);
|
||||
if (attributesList != null) {
|
||||
String annotatedElement = "method '" + getMethodName() + '\'';
|
||||
for (AnnotationAttributes annotationAttributes : attributesList) {
|
||||
AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues(
|
||||
annotatedElement, this.classLoader, annotationAttributes, classValuesAsString);
|
||||
convertedAttributes.forEach(allAttributes::add);
|
||||
}
|
||||
}
|
||||
return allAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeclaringClassName() {
|
||||
return this.declaringClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReturnTypeName() {
|
||||
return this.returnTypeName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* {@link AnnotationVisitor} to recursively visit annotation arrays.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1.1
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor {
|
||||
|
||||
private final String attributeName;
|
||||
|
||||
private final List<AnnotationAttributes> allNestedAttributes = new ArrayList<>();
|
||||
|
||||
|
||||
public RecursiveAnnotationArrayVisitor(
|
||||
String attributeName, AnnotationAttributes attributes, @Nullable ClassLoader classLoader) {
|
||||
|
||||
super(classLoader, attributes);
|
||||
this.attributeName = attributeName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(String attributeName, Object attributeValue) {
|
||||
Object newValue = attributeValue;
|
||||
Object existingValue = this.attributes.get(this.attributeName);
|
||||
if (existingValue != null) {
|
||||
newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
|
||||
}
|
||||
else {
|
||||
Class<?> arrayClass = newValue.getClass();
|
||||
if (Enum.class.isAssignableFrom(arrayClass)) {
|
||||
while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
|
||||
arrayClass = arrayClass.getSuperclass();
|
||||
}
|
||||
}
|
||||
Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
|
||||
newArray[0] = newValue;
|
||||
newValue = newArray;
|
||||
}
|
||||
this.attributes.put(this.attributeName, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String attributeName, String asmTypeDescriptor) {
|
||||
String annotationType = Type.getType(asmTypeDescriptor).getClassName();
|
||||
AnnotationAttributes nestedAttributes = new AnnotationAttributes(annotationType, this.classLoader);
|
||||
this.allNestedAttributes.add(nestedAttributes);
|
||||
return new RecursiveAnnotationAttributesVisitor(annotationType, nestedAttributes, this.classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
if (!this.allNestedAttributes.isEmpty()) {
|
||||
this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0]));
|
||||
}
|
||||
else if (!this.attributes.containsKey(this.attributeName)) {
|
||||
Class<? extends Annotation> annotationType = this.attributes.annotationType();
|
||||
if (annotationType != null) {
|
||||
try {
|
||||
Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType();
|
||||
if (attributeType.isArray()) {
|
||||
Class<?> elementType = attributeType.getComponentType();
|
||||
if (elementType.isAnnotation()) {
|
||||
elementType = AnnotationAttributes.class;
|
||||
}
|
||||
this.attributes.put(this.attributeName, Array.newInstance(elementType, 0));
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// Corresponding attribute method not found: cannot expose empty array.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import org.springframework.asm.AnnotationVisitor;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link AnnotationVisitor} to recursively visit annotation attributes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1.1
|
||||
* @deprecated As of Spring Framework 5.2, this class and related classes in this
|
||||
* package have been replaced by {@link SimpleAnnotationMetadataReadingVisitor}
|
||||
* and related classes for internal use within the framework.
|
||||
*/
|
||||
@Deprecated
|
||||
class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVisitor {
|
||||
|
||||
protected final String annotationType;
|
||||
|
||||
|
||||
public RecursiveAnnotationAttributesVisitor(
|
||||
String annotationType, AnnotationAttributes attributes, @Nullable ClassLoader classLoader) {
|
||||
|
||||
super(classLoader, attributes);
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
AnnotationUtils.registerDefaultValues(this.attributes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.lang;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated element uses Java 7 specific API constructs,
|
||||
* without implying that it strictly requires Java 7.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
* @deprecated as of 5.0 since the framework is based on Java 8+ now
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface UsesJava7 {
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.lang;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated element uses Java 8 specific API constructs,
|
||||
* without implying that it strictly requires Java 8.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
* @deprecated as of 5.0 since the framework is based on Java 8+ now
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
@Deprecated
|
||||
public @interface UsesJava8 {
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.lang;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated element uses the Http Server available in
|
||||
* {@code com.sun.*} classes, which is only available on a Sun/Oracle JVM.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
* @deprecated as of 5.1, along with Spring's Sun HTTP Server support classes
|
||||
*/
|
||||
@Deprecated
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
public @interface UsesSunHttpServer {
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.lang;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated element uses an API from the {@code sun.misc}
|
||||
* package.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.3
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Documented
|
||||
public @interface UsesSunMisc {
|
||||
}
|
||||
@@ -558,42 +558,6 @@ public abstract class ObjectUtils {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the same value as {@link Boolean#hashCode(boolean)}}.
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
|
||||
*/
|
||||
@Deprecated
|
||||
public static int hashCode(boolean bool) {
|
||||
return Boolean.hashCode(bool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the same value as {@link Double#hashCode(double)}}.
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
|
||||
*/
|
||||
@Deprecated
|
||||
public static int hashCode(double dbl) {
|
||||
return Double.hashCode(dbl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the same value as {@link Float#hashCode(float)}}.
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
|
||||
*/
|
||||
@Deprecated
|
||||
public static int hashCode(float flt) {
|
||||
return Float.hashCode(flt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the same value as {@link Long#hashCode(long)}}.
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
|
||||
*/
|
||||
@Deprecated
|
||||
public static int hashCode(long lng) {
|
||||
return Long.hashCode(lng);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Convenience methods for toString output
|
||||
|
||||
@@ -886,18 +886,6 @@ public abstract class StringUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the RFC 3066 compliant language tag,
|
||||
* as used for the HTTP "Accept-Language" header.
|
||||
* @param locale the Locale to transform to a language tag
|
||||
* @return the RFC 3066 compliant language tag as {@code String}
|
||||
* @deprecated as of 5.0.4, in favor of {@link Locale#toLanguageTag()}
|
||||
*/
|
||||
@Deprecated
|
||||
public static String toLanguageTag(Locale locale) {
|
||||
return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given {@code timeZoneString} value into a {@link TimeZone}.
|
||||
* @param timeZoneString the time zone {@code String}, following {@link TimeZone#getTimeZone(String)}
|
||||
@@ -983,37 +971,6 @@ public abstract class StringUtils {
|
||||
return newArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the given {@code String} arrays into one, with overlapping
|
||||
* array elements only included once.
|
||||
* <p>The order of elements in the original arrays is preserved
|
||||
* (with the exception of overlapping elements, which are only
|
||||
* included on their first occurrence).
|
||||
* @param array1 the first array (can be {@code null})
|
||||
* @param array2 the second array (can be {@code null})
|
||||
* @return the new array ({@code null} if both given arrays were {@code null})
|
||||
* @deprecated as of 4.3.15, in favor of manual merging via {@link LinkedHashSet}
|
||||
* (with every entry included at most once, even entries within the first array)
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static String[] mergeStringArrays(@Nullable String[] array1, @Nullable String[] array2) {
|
||||
if (ObjectUtils.isEmpty(array1)) {
|
||||
return array2;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(array2)) {
|
||||
return array1;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<>(Arrays.asList(array1));
|
||||
for (String str : array2) {
|
||||
if (!result.contains(str)) {
|
||||
result.add(str);
|
||||
}
|
||||
}
|
||||
return toStringArray(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the given {@code String} array if necessary.
|
||||
* @param array the original array (potentially empty)
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util.comparator;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A comparator that chains a sequence of one or more Comparators.
|
||||
*
|
||||
* <p>A compound comparator calls each Comparator in sequence until a single
|
||||
* Comparator returns a non-zero result, or the comparators are exhausted and
|
||||
* zero is returned.
|
||||
*
|
||||
* <p>This facilitates in-memory sorting similar to multi-column sorting in SQL.
|
||||
* The order of any single Comparator in the list can also be reversed.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2.2
|
||||
* @param <T> the type of objects that may be compared by this comparator
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the standard JDK 8
|
||||
* {@link Comparator#thenComparing(Comparator)}
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({"serial", "rawtypes"})
|
||||
public class CompoundComparator<T> implements Comparator<T>, Serializable {
|
||||
|
||||
private final List<InvertibleComparator> comparators;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a CompoundComparator with initially no Comparators. Clients
|
||||
* must add at least one Comparator before calling the compare method or an
|
||||
* IllegalStateException is thrown.
|
||||
*/
|
||||
public CompoundComparator() {
|
||||
this.comparators = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a CompoundComparator from the Comparators in the provided array.
|
||||
* <p>All Comparators will default to ascending sort order,
|
||||
* unless they are InvertibleComparators.
|
||||
* @param comparators the comparators to build into a compound comparator
|
||||
* @see InvertibleComparator
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public CompoundComparator(Comparator... comparators) {
|
||||
Assert.notNull(comparators, "Comparators must not be null");
|
||||
this.comparators = new ArrayList<>(comparators.length);
|
||||
for (Comparator comparator : comparators) {
|
||||
addComparator(comparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Comparator to the end of the chain.
|
||||
* <p>The Comparator will default to ascending sort order,
|
||||
* unless it is a InvertibleComparator.
|
||||
* @param comparator the Comparator to add to the end of the chain
|
||||
* @see InvertibleComparator
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addComparator(Comparator<? extends T> comparator) {
|
||||
if (comparator instanceof InvertibleComparator) {
|
||||
this.comparators.add((InvertibleComparator) comparator);
|
||||
}
|
||||
else {
|
||||
this.comparators.add(new InvertibleComparator(comparator));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Comparator to the end of the chain using the provided sort order.
|
||||
* @param comparator the Comparator to add to the end of the chain
|
||||
* @param ascending the sort order: ascending (true) or descending (false)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addComparator(Comparator<? extends T> comparator, boolean ascending) {
|
||||
this.comparators.add(new InvertibleComparator(comparator, ascending));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the Comparator at the given index.
|
||||
* <p>The Comparator will default to ascending sort order,
|
||||
* unless it is a InvertibleComparator.
|
||||
* @param index the index of the Comparator to replace
|
||||
* @param comparator the Comparator to place at the given index
|
||||
* @see InvertibleComparator
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setComparator(int index, Comparator<? extends T> comparator) {
|
||||
if (comparator instanceof InvertibleComparator) {
|
||||
this.comparators.set(index, (InvertibleComparator) comparator);
|
||||
}
|
||||
else {
|
||||
this.comparators.set(index, new InvertibleComparator(comparator));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the Comparator at the given index using the given sort order.
|
||||
* @param index the index of the Comparator to replace
|
||||
* @param comparator the Comparator to place at the given index
|
||||
* @param ascending the sort order: ascending (true) or descending (false)
|
||||
*/
|
||||
public void setComparator(int index, Comparator<T> comparator, boolean ascending) {
|
||||
this.comparators.set(index, new InvertibleComparator<>(comparator, ascending));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the sort order of each sort definition contained by this compound
|
||||
* comparator.
|
||||
*/
|
||||
public void invertOrder() {
|
||||
for (InvertibleComparator comparator : this.comparators) {
|
||||
comparator.invertOrder();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the sort order of the sort definition at the specified index.
|
||||
* @param index the index of the comparator to invert
|
||||
*/
|
||||
public void invertOrder(int index) {
|
||||
this.comparators.get(index).invertOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the sort order at the given index to ascending.
|
||||
* @param index the index of the comparator to change
|
||||
*/
|
||||
public void setAscendingOrder(int index) {
|
||||
this.comparators.get(index).setAscending(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the sort order at the given index to descending sort.
|
||||
* @param index the index of the comparator to change
|
||||
*/
|
||||
public void setDescendingOrder(int index) {
|
||||
this.comparators.get(index).setAscending(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of aggregated comparators.
|
||||
*/
|
||||
public int getComparatorCount() {
|
||||
return this.comparators.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(T o1, T o2) {
|
||||
Assert.state(!this.comparators.isEmpty(),
|
||||
"No sort definitions have been added to this CompoundComparator to compare");
|
||||
for (InvertibleComparator comparator : this.comparators) {
|
||||
int result = comparator.compare(o1, o2);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof CompoundComparator &&
|
||||
this.comparators.equals(((CompoundComparator<T>) other).comparators)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.comparators.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CompoundComparator: " + this.comparators;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util.comparator;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A decorator for a comparator, with an "ascending" flag denoting
|
||||
* whether comparison results should be treated in forward (standard
|
||||
* ascending) order or flipped for reverse (descending) order.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2.2
|
||||
* @param <T> the type of objects that may be compared by this comparator
|
||||
* @deprecated as of Spring Framework 5.0, in favor of the standard JDK 8
|
||||
* {@link Comparator#reversed()}
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class InvertibleComparator<T> implements Comparator<T>, Serializable {
|
||||
|
||||
private final Comparator<T> comparator;
|
||||
|
||||
private boolean ascending = true;
|
||||
|
||||
|
||||
/**
|
||||
* Create an InvertibleComparator that sorts ascending by default.
|
||||
* For the actual comparison, the specified Comparator will be used.
|
||||
* @param comparator the comparator to decorate
|
||||
*/
|
||||
public InvertibleComparator(Comparator<T> comparator) {
|
||||
Assert.notNull(comparator, "Comparator must not be null");
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an InvertibleComparator that sorts based on the provided order.
|
||||
* For the actual comparison, the specified Comparator will be used.
|
||||
* @param comparator the comparator to decorate
|
||||
* @param ascending the sort order: ascending (true) or descending (false)
|
||||
*/
|
||||
public InvertibleComparator(Comparator<T> comparator, boolean ascending) {
|
||||
Assert.notNull(comparator, "Comparator must not be null");
|
||||
this.comparator = comparator;
|
||||
setAscending(ascending);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify the sort order: ascending (true) or descending (false).
|
||||
*/
|
||||
public void setAscending(boolean ascending) {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sort order: ascending (true) or descending (false).
|
||||
*/
|
||||
public boolean isAscending() {
|
||||
return this.ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the sort order: ascending → descending or
|
||||
* descending → ascending.
|
||||
*/
|
||||
public void invertOrder() {
|
||||
this.ascending = !this.ascending;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
int result = this.comparator.compare(o1, o2);
|
||||
if (result != 0) {
|
||||
// Invert the order if it is a reverse sort.
|
||||
if (!this.ascending) {
|
||||
if (Integer.MIN_VALUE == result) {
|
||||
result = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
result *= -1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof InvertibleComparator)) {
|
||||
return false;
|
||||
}
|
||||
InvertibleComparator<T> otherComp = (InvertibleComparator<T>) other;
|
||||
return (this.comparator.equals(otherComp.comparator) && this.ascending == otherComp.ascending);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.comparator.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InvertibleComparator: [" + this.comparator + "]; ascending=" + this.ascending;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.core.annotation;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -36,7 +35,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets;
|
||||
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet;
|
||||
import org.springframework.lang.UsesSunMisc;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
@@ -60,12 +58,6 @@ class AnnotationTypeMappingsTests {
|
||||
AnnotationTypeMapping::getAnnotationType).containsExactly(SimpleAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forAnnotationWhenHasSpringAnnotationReturnsFilteredMappings() {
|
||||
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithSpringLangAnnotation.class);
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forAnnotationTypeWhenMetaAnnotationsReturnsMappings() {
|
||||
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(MetaAnnotated.class);
|
||||
@@ -526,12 +518,6 @@ class AnnotationTypeMappingsTests {
|
||||
@interface SimpleAnnotation {
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@UsesSunMisc
|
||||
@interface WithSpringLangAnnotation {
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface AA {
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.asm.ClassReader;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AbstractAnnotationMetadataTests;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link AnnotationMetadataReadingVisitor}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class AnnotationMetadataReadingVisitorTests extends AbstractAnnotationMetadataTests {
|
||||
|
||||
@Override
|
||||
protected AnnotationMetadata get(Class<?> source) {
|
||||
try {
|
||||
ClassLoader classLoader = source.getClassLoader();
|
||||
String className = source.getName();
|
||||
String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX
|
||||
+ ClassUtils.convertClassNameToResourcePath(className)
|
||||
+ ClassUtils.CLASS_FILE_SUFFIX;
|
||||
Resource resource = new DefaultResourceLoader().getResource(resourcePath);
|
||||
try (InputStream inputStream = new BufferedInputStream(
|
||||
resource.getInputStream())) {
|
||||
ClassReader classReader = new ClassReader(inputStream);
|
||||
AnnotationMetadataReadingVisitor metadata = new AnnotationMetadataReadingVisitor(
|
||||
classLoader);
|
||||
classReader.accept(metadata, ClassReader.SKIP_DEBUG);
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("equals() not implemented in deprecated AnnotationMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyEquals() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("hashCode() not implemented in deprecated AnnotationMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyHashCode() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("toString() not implemented in deprecated AnnotationMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyToString() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void getAnnotationsReturnsDirectAnnotations() {
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(super::getAnnotationsReturnsDirectAnnotations);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.asm.ClassReader;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AbstractMethodMetadataTests;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link MethodMetadataReadingVisitor}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class MethodMetadataReadingVisitorTests extends AbstractMethodMetadataTests {
|
||||
|
||||
@Override
|
||||
protected AnnotationMetadata get(Class<?> source) {
|
||||
try {
|
||||
ClassLoader classLoader = source.getClassLoader();
|
||||
String className = source.getName();
|
||||
String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX
|
||||
+ ClassUtils.convertClassNameToResourcePath(className)
|
||||
+ ClassUtils.CLASS_FILE_SUFFIX;
|
||||
Resource resource = new DefaultResourceLoader().getResource(resourcePath);
|
||||
try (InputStream inputStream = new BufferedInputStream(
|
||||
resource.getInputStream())) {
|
||||
ClassReader classReader = new ClassReader(inputStream);
|
||||
AnnotationMetadataReadingVisitor metadata = new AnnotationMetadataReadingVisitor(
|
||||
classLoader);
|
||||
classReader.accept(metadata, ClassReader.SKIP_DEBUG);
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("equals() not implemented in deprecated MethodMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyEquals() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("hashCode() not implemented in deprecated MethodMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyHashCode() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("toString() not implemented in deprecated MethodMetadataReadingVisitor")
|
||||
@Override
|
||||
public void verifyToString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void getAnnotationsReturnsDirectAnnotations() {
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
|
||||
super::getAnnotationsReturnsDirectAnnotations);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -233,44 +233,6 @@ class ObjectUtilsTests {
|
||||
assertThat(ObjectUtils.nullSafeEquals(new int[] {1, 2, 3}, new int[] {1, 2, 3})).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void hashCodeWithBooleanFalse() {
|
||||
int expected = Boolean.FALSE.hashCode();
|
||||
assertThat(ObjectUtils.hashCode(false)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void hashCodeWithBooleanTrue() {
|
||||
int expected = Boolean.TRUE.hashCode();
|
||||
assertThat(ObjectUtils.hashCode(true)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void hashCodeWithDouble() {
|
||||
double dbl = 9830.43;
|
||||
int expected = Double.valueOf(dbl).hashCode();
|
||||
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void hashCodeWithFloat() {
|
||||
float flt = 34.8f;
|
||||
int expected = (Float.valueOf(flt)).hashCode();
|
||||
assertThat(ObjectUtils.hashCode(flt)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void hashCodeWithLong() {
|
||||
long lng = 883L;
|
||||
int expected = (Long.valueOf(lng)).hashCode();
|
||||
assertThat(ObjectUtils.hashCode(lng)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void identityToString() {
|
||||
Object obj = new Object();
|
||||
|
||||
@@ -440,21 +440,6 @@ class StringUtilsTests {
|
||||
assertThat(StringUtils.concatenateStringArrays(null, null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void mergeStringArrays() {
|
||||
String[] input1 = new String[] {"myString2"};
|
||||
String[] input2 = new String[] {"myString1", "myString2"};
|
||||
String[] result = StringUtils.mergeStringArrays(input1, input2);
|
||||
assertThat(result.length).isEqualTo(2);
|
||||
assertThat(result[0]).isEqualTo("myString2");
|
||||
assertThat(result[1]).isEqualTo("myString1");
|
||||
|
||||
assertThat(StringUtils.mergeStringArrays(input1, null)).isEqualTo(input1);
|
||||
assertThat(StringUtils.mergeStringArrays(null, input2)).isEqualTo(input2);
|
||||
assertThat(StringUtils.mergeStringArrays(null, null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sortStringArray() {
|
||||
String[] input = new String[] {"myString2"};
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Test for {@link CompoundComparator}.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Deprecated
|
||||
class CompoundComparatorTests {
|
||||
|
||||
@Test
|
||||
void shouldNeedAtLeastOneComparator() {
|
||||
Comparator<String> c = new CompoundComparator<>();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
c.compare("foo", "bar"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link InvertibleComparator}.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Deprecated
|
||||
class InvertibleComparatorTests {
|
||||
|
||||
private final Comparator<Integer> comparator = new ComparableComparator<>();
|
||||
|
||||
|
||||
@Test
|
||||
void shouldNeedComparator() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new InvertibleComparator<>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNeedComparatorWithAscending() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new InvertibleComparator<>(null, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDefaultToAscending() throws Exception {
|
||||
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator);
|
||||
assertThat(invertibleComparator.isAscending()).isTrue();
|
||||
assertThat(invertibleComparator.compare(1, 2)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInvert() throws Exception {
|
||||
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator);
|
||||
assertThat(invertibleComparator.isAscending()).isTrue();
|
||||
assertThat(invertibleComparator.compare(1, 2)).isEqualTo(-1);
|
||||
invertibleComparator.invertOrder();
|
||||
assertThat(invertibleComparator.isAscending()).isFalse();
|
||||
assertThat(invertibleComparator.compare(1, 2)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCompareAscending() throws Exception {
|
||||
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, true);
|
||||
assertThat(invertibleComparator.compare(1, 2)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCompareDescending() throws Exception {
|
||||
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, false);
|
||||
assertThat(invertibleComparator.compare(1, 2)).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user