Skip to content

Commit 420f823

Browse files
committed
Rollback accidental commit :/.
1 parent 897aab9 commit 420f823

File tree

2 files changed

+1
-259
lines changed

2 files changed

+1
-259
lines changed

org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 0 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818

1919
import java.lang.annotation.Annotation;
2020
import java.lang.reflect.Method;
21-
import java.util.ArrayList;
2221
import java.util.Arrays;
2322
import java.util.HashMap;
24-
import java.util.List;
2523
import java.util.Map;
2624

2725
import org.springframework.core.BridgeMethodResolver;
@@ -43,7 +41,6 @@
4341
* @author Juergen Hoeller
4442
* @author Sam Brannen
4543
* @author Mark Fisher
46-
* @author Oliver Gierke
4744
* @since 2.0
4845
* @see java.lang.reflect.Method#getAnnotations()
4946
* @see java.lang.reflect.Method#getAnnotation(Class)
@@ -376,201 +373,4 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType,
376373
}
377374
}
378375

379-
/**
380-
* Returns a {@link ParameterAnnotation} instance for the first parameter with the given annotation.
381-
* @param <T>
382-
* @param method the {@link Method} whose parameters shall be inspected
383-
* @param annotationType the annotation typed the parameter shall carry
384-
* @return
385-
*/
386-
public static <T extends Annotation> ParameterAnnotation<T> getParameterAnnotation(Method method,
387-
Class<T> annotationType) {
388-
389-
List<ParameterAnnotation<T>> annotations = getParameterAnnotations(method, annotationType);
390-
return annotations.isEmpty() ? null : annotations.get(0);
391-
}
392-
393-
/**
394-
* Returns all {@link ParameterAnnotation}s for parameters with the given annotation.
395-
* @param <T>
396-
* @param method the {@link Method} whose parameters shall be scanned for annotations
397-
* @param annotationType the annotation type the paramter shall carry
398-
* @return
399-
*/
400-
public static <T extends Annotation> List<ParameterAnnotation<T>> getParameterAnnotations(Method method,
401-
Class<T> annotationType) {
402-
403-
return getParameterAnnotations(method, new AnnotationTypeFilter<T>(annotationType));
404-
}
405-
406-
/**
407-
* Returns the {@link ParameterAnnotation} for a parameter of the given type that carries an annotation of the given
408-
* type.
409-
* @param <T>
410-
* @param method the {@link Method} that shall be scanned for parameters carrying the annotation
411-
* @param annotationType the annotation type that shall be discovered
412-
* @param parameterType the parameter type that shall be considered
413-
* @return
414-
*/
415-
public static <T extends Annotation> ParameterAnnotation<T> getParameterAnnotation(Method method,
416-
Class<T> annotationType, final Class<?> parameterType) {
417-
418-
List<ParameterAnnotation<T>> annotations = getParameterAnnotations(method, annotationType, parameterType);
419-
return annotations.isEmpty() ? null : annotations.get(0);
420-
}
421-
422-
/**
423-
* Returns all {@link ParameterAnnotation}s for parameters of the given type that carry an annotation of the given
424-
* type.
425-
* @param <T>
426-
* @param method the {@link Method} that shall be scanned for parameters carrying the annotation
427-
* @param annotationType the annotation type that shall be discovered
428-
* @param parameterType the parameter type that shall be considered
429-
* @return
430-
*/
431-
public static <T extends Annotation> List<ParameterAnnotation<T>> getParameterAnnotations(Method method,
432-
Class<T> annotationType, final Class<?> parameterType) {
433-
434-
return getParameterAnnotations(method, new AnnotationTypeFilter<T>(annotationType) {
435-
436-
@Override
437-
public boolean matches(ParameterAnnotation<?> parameterAnnotation) {
438-
return super.matches(parameterAnnotation)
439-
&& parameterType.equals(parameterAnnotation.getParameterType());
440-
}
441-
});
442-
}
443-
444-
/**
445-
* Returns all {@link ParameterAnnotation}s for parameters of the given method that match the given
446-
* {@link ParameterAnnotationFilter}.
447-
* @see ParameterAnnotationFilter
448-
* @param <T>
449-
* @param method the {@link Method} that shall be scanned for annotated parameters
450-
* @param filter a {@link ParameterAnnotationFilter} to apply criterias on the {@link ParameterAnnotation}s to be
451-
* returned
452-
* @return
453-
*/
454-
@SuppressWarnings("unchecked")
455-
public static <T extends Annotation> List<ParameterAnnotation<T>> getParameterAnnotations(Method method,
456-
ParameterAnnotationFilter filter) {
457-
458-
List<ParameterAnnotation<T>> result = new ArrayList<ParameterAnnotation<T>>();
459-
460-
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
461-
Class<?>[] parameterTypes = method.getParameterTypes();
462-
463-
for (int i = 0; i < parameterAnnotations.length; i++) {
464-
for (Annotation annotation : parameterAnnotations[i]) {
465-
466-
ParameterAnnotation<T> parameterAnnotation = new ParameterAnnotation<T>((T) annotation, i,
467-
parameterTypes[i]);
468-
469-
if (filter.matches(parameterAnnotation)) {
470-
result.add(parameterAnnotation);
471-
}
472-
}
473-
}
474-
475-
return result;
476-
}
477-
478-
/**
479-
* Allows filtering {@link ParameterAnnotation} instances.
480-
* @see AnnotationUtils#getParameterAnnotations(Method, ParameterAnnotationFilter)
481-
*/
482-
public interface ParameterAnnotationFilter {
483-
boolean matches(ParameterAnnotation<?> annotation);
484-
}
485-
486-
/**
487-
* {@link ParameterAnnotationFilter} that matches all {@link ParameterAnnotation}s that have the given annotation
488-
* type.
489-
*/
490-
public static class AnnotationTypeFilter<T extends Annotation> implements ParameterAnnotationFilter {
491-
492-
private final Class<T> annotationType;
493-
494-
public AnnotationTypeFilter(Class<T> annotationType) {
495-
this.annotationType = annotationType;
496-
}
497-
498-
public boolean matches(ParameterAnnotation<?> parameterAnnotation) {
499-
return annotationType.equals(parameterAnnotation.getAnnotation().annotationType());
500-
}
501-
}
502-
503-
/**
504-
* Captures an annotation for a method parameter as well as some meta information about the parameter.
505-
*/
506-
public static class ParameterAnnotation<T extends Annotation> {
507-
508-
private final T annotation;
509-
private final int parameterIndex;
510-
private final Class<?> parameterType;
511-
512-
ParameterAnnotation(T annotation, int parameterIndex, Class<?> parameterType) {
513-
Assert.notNull(annotation);
514-
Assert.notNull(parameterType);
515-
this.annotation = annotation;
516-
this.parameterIndex = parameterIndex;
517-
this.parameterType = parameterType;
518-
}
519-
520-
/**
521-
* Returns the annotation bound to the parameter.
522-
* @return the annotation
523-
*/
524-
public T getAnnotation() {
525-
return annotation;
526-
}
527-
528-
/**
529-
* Returns the method parameter index in the list of parameters.
530-
* @return the parameterIndex
531-
*/
532-
public int getParameterIndex() {
533-
return parameterIndex;
534-
}
535-
536-
/**
537-
* Returns the type of the method parameter the annotation is bound to.
538-
* @return the parameterType
539-
*/
540-
public Class<?> getParameterType() {
541-
return parameterType;
542-
}
543-
544-
/*
545-
* (non-Javadoc)
546-
*
547-
* @see java.lang.Object#equals(java.lang.Object)
548-
*/
549-
@Override
550-
public boolean equals(Object obj) {
551-
if (obj == this) {
552-
return true;
553-
}
554-
if (!(obj instanceof ParameterAnnotation<?>)) {
555-
return false;
556-
}
557-
558-
ParameterAnnotation<?> that = (ParameterAnnotation<?>) obj;
559-
return this.annotation.equals(that.annotation) && this.parameterType.equals(that.parameterType)
560-
&& this.parameterIndex == that.parameterIndex;
561-
}
562-
563-
/*
564-
* (non-Javadoc)
565-
*
566-
* @see java.lang.Object#hashCode()
567-
*/
568-
@Override
569-
public int hashCode() {
570-
int result = 17;
571-
result = 31 * result + annotation.hashCode();
572-
result = 31 * result + parameterType.hashCode();
573-
return 31 * result + (parameterIndex ^ parameterIndex >>> 32);
574-
}
575-
}
576376
}

org.springframework.core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@
1919
import static org.junit.Assert.*;
2020
import static org.springframework.core.annotation.AnnotationUtils.*;
2121

22-
import java.io.Serializable;
23-
import java.lang.annotation.ElementType;
2422
import java.lang.annotation.Inherited;
2523
import java.lang.annotation.Retention;
2624
import java.lang.annotation.RetentionPolicy;
27-
import java.lang.annotation.Target;
2825
import java.lang.reflect.Method;
29-
import java.util.List;
3026

3127
import org.junit.Test;
3228
import org.springframework.core.Ordered;
33-
import org.springframework.core.annotation.AnnotationUtils.ParameterAnnotation;
3429

3530
/**
3631
* @author Rod Johnson
@@ -209,45 +204,6 @@ public void testFindAnnotationFromInterfaceOnSuper() throws Exception {
209204
assertNotNull(order);
210205
}
211206

212-
@Test
213-
public void testDetectsParameterAnnotation() throws Exception {
214-
215-
Method method = InterfaceWithAnnotatedMethodParameters.class.getMethod("foo", String.class, Long.class);
216-
ParameterAnnotation<MyAnnotation> parameterAnnotation = getParameterAnnotation(method, MyAnnotation.class);
217-
assertParameterAnnotationWith(parameterAnnotation, "foo", 1, Long.class);
218-
219-
List<ParameterAnnotation<MyAnnotation>> parameterAnnotations = getParameterAnnotations(method,
220-
MyAnnotation.class);
221-
assertNotNull(parameterAnnotations);
222-
assertEquals(1, parameterAnnotations.size());
223-
assertEquals(parameterAnnotation, parameterAnnotations.get(0));
224-
}
225-
226-
@Test
227-
public void testDetectsFirstParameterAnnotationForMultipleOnes() throws Exception {
228-
229-
Method method = InterfaceWithAnnotatedMethodParameters.class.getMethod("bar", String.class, String.class,
230-
Serializable.class);
231-
ParameterAnnotation<MyAnnotation> parameterAnnotation = getParameterAnnotation(method, MyAnnotation.class);
232-
assertParameterAnnotationWith(parameterAnnotation, "first", 0, String.class);
233-
234-
List<ParameterAnnotation<MyAnnotation>> parameterAnnotations = getParameterAnnotations(method,
235-
MyAnnotation.class);
236-
assertNotNull(parameterAnnotations);
237-
assertEquals(2, parameterAnnotations.size());
238-
assertEquals(parameterAnnotation, parameterAnnotations.get(0));
239-
assertParameterAnnotationWith(parameterAnnotations.get(1), "third", 2, Serializable.class);
240-
}
241-
242-
private void assertParameterAnnotationWith(ParameterAnnotation<MyAnnotation> parameterAnnotation, String value,
243-
int index, Class<?> parameterType) {
244-
assertNotNull(parameterAnnotation);
245-
assertEquals(index, parameterAnnotation.getParameterIndex());
246-
assertNotNull(parameterAnnotation.getAnnotation());
247-
assertEquals(value, parameterAnnotation.getAnnotation().value());
248-
assertEquals(parameterType, parameterAnnotation.getParameterType());
249-
}
250-
251207
public static interface AnnotatedInterface {
252208

253209
@Order(0)
@@ -365,24 +321,10 @@ public void foo() {
365321
}
366322
}
367323

368-
public static interface InterfaceWithAnnotatedMethodParameters {
369-
370-
void foo(String foo, @MyAnnotation("foo") Long bar);
371-
372-
void bar(@MyAnnotation("first") String first, String second,
373-
@Transactional @MyAnnotation("third") Serializable third);
374-
}
375324
}
376325

377326
@Retention(RetentionPolicy.RUNTIME)
378327
@Inherited
379328
@interface Transactional {
380-
381-
}
382-
383-
@Retention(RetentionPolicy.RUNTIME)
384-
@Target(ElementType.PARAMETER)
385-
@interface MyAnnotation {
386-
387-
String value() default "";
329+
388330
}

0 commit comments

Comments
 (0)