|
10 | 10 |
|
11 | 11 | package org.junit.jupiter.engine.execution;
|
12 | 12 |
|
13 |
| -import static org.junit.platform.commons.util.ReflectionUtils.isInnerClass; |
14 |
| - |
15 | 13 | import java.lang.annotation.Annotation;
|
16 |
| -import java.lang.reflect.AnnotatedElement; |
17 |
| -import java.lang.reflect.Constructor; |
18 |
| -import java.lang.reflect.Executable; |
19 | 14 | import java.lang.reflect.Parameter;
|
20 | 15 | import java.util.List;
|
21 | 16 | import java.util.Optional;
|
@@ -58,62 +53,17 @@ public Optional<Object> getTarget() {
|
58 | 53 |
|
59 | 54 | @Override
|
60 | 55 | public boolean isAnnotated(Class<? extends Annotation> annotationType) {
|
61 |
| - return AnnotationUtils.isAnnotated(getEffectiveAnnotatedParameter(), annotationType); |
| 56 | + return AnnotationUtils.isAnnotated(this.parameter, this.index, annotationType); |
62 | 57 | }
|
63 | 58 |
|
64 | 59 | @Override
|
65 | 60 | public <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType) {
|
66 |
| - return AnnotationUtils.findAnnotation(getEffectiveAnnotatedParameter(), annotationType); |
| 61 | + return AnnotationUtils.findAnnotation(this.parameter, this.index, annotationType); |
67 | 62 | }
|
68 | 63 |
|
69 | 64 | @Override
|
70 | 65 | public <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType) {
|
71 |
| - return AnnotationUtils.findRepeatableAnnotations(getEffectiveAnnotatedParameter(), annotationType); |
72 |
| - } |
73 |
| - |
74 |
| - /** |
75 |
| - * Due to a bug in {@code javac} on JDK versions prior to JDK 9, looking up |
76 |
| - * annotations directly on a {@link Parameter} will fail for inner class |
77 |
| - * constructors. |
78 |
| - * |
79 |
| - * <h4>Bug in {@code javac} on JDK versions prior to JDK 9</h4> |
80 |
| - * |
81 |
| - * <p>The parameter annotations array in the compiled byte code for the user's |
82 |
| - * test class excludes an entry for the implicit <em>enclosing instance</em> |
83 |
| - * parameter for an inner class constructor. |
84 |
| - * |
85 |
| - * <h4>Workaround</h4> |
86 |
| - * |
87 |
| - * <p>JUnit provides a workaround for this off-by-one error by helping extension |
88 |
| - * authors to access annotations on the preceding {@link Parameter} object (i.e., |
89 |
| - * {@code index - 1}). The {@linkplain #getIndex() current index} must never be |
90 |
| - * zero in such situations since JUnit Jupiter should never ask a |
91 |
| - * {@code ParameterResolver} to resolve a parameter for the implicit <em>enclosing |
92 |
| - * instance</em> parameter. |
93 |
| - * |
94 |
| - * <h4>WARNING</h4> |
95 |
| - * |
96 |
| - * <p>The {@code AnnotatedElement} returned by this method should never be cast and |
97 |
| - * treated as a {@code Parameter} since the metadata (e.g., {@link Parameter#getName()}, |
98 |
| - * {@link Parameter#getType()}, etc.) will not match those for the declared parameter |
99 |
| - * at the given index in an inner class constructor. |
100 |
| - * |
101 |
| - * @return the actual {@code Parameter} for this context, or the <em>effective</em> |
102 |
| - * {@code Parameter} if the aforementioned bug is detected |
103 |
| - */ |
104 |
| - private AnnotatedElement getEffectiveAnnotatedParameter() { |
105 |
| - Executable executable = getDeclaringExecutable(); |
106 |
| - |
107 |
| - if (executable instanceof Constructor && isInnerClass(executable.getDeclaringClass()) |
108 |
| - && executable.getParameterAnnotations().length == executable.getParameterCount() - 1) { |
109 |
| - |
110 |
| - Preconditions.condition(this.index != 0, |
111 |
| - "A ParameterContext should never be created for parameter index 0 in an inner class constructor"); |
112 |
| - |
113 |
| - return executable.getParameters()[this.index - 1]; |
114 |
| - } |
115 |
| - |
116 |
| - return this.parameter; |
| 66 | + return AnnotationUtils.findRepeatableAnnotations(this.parameter, this.index, annotationType); |
117 | 67 | }
|
118 | 68 |
|
119 | 69 | @Override
|
|
0 commit comments