Java Code Examples for java.lang.reflect.Executable#getParameterAnnotations()

The following examples show how to use java.lang.reflect.Executable#getParameterAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassScanning.java    From weld-junit with Apache License 2.0 6 votes vote down vote up
private static List<Class<?>> getExecutableParameterTypes(Executable executable, boolean explicitInjection) {

        List<Class<?>> types = new ArrayList<>();

        if (explicitInjection) {
            Annotation[][] paramAnns = executable.getParameterAnnotations();
            Class<?>[] paramTypes = executable.getParameterTypes();
            for (int c = 0; c < paramTypes.length; ++c) {
                if (stream(paramAnns[c]).anyMatch(ClassScanning::isBeanParameterAnnotation)) {
                    types.add(paramTypes[c]);
                }
            }
        } else {
            types.addAll(asList(executable.getParameterTypes()));
        }

        return types;
    }
 
Example 2
Source File: DefaultInjectorResources.java    From panda with Apache License 2.0 5 votes vote down vote up
@Override
public Annotation[][] fetchAnnotations(Executable executable) {
    Annotation[][] parameterAnnotations = cachedAnnotations.get(executable);

    if (parameterAnnotations == null) {
        parameterAnnotations = executable.getParameterAnnotations();
        cachedAnnotations.put(executable, parameterAnnotations);
    }

    return parameterAnnotations;
}
 
Example 3
Source File: HotSpotResolvedJavaMethodImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Annotation[][] getParameterAnnotations() {
    Executable javaMethod = toJava();
    return javaMethod == null ? new Annotation[signature.getParameterCount(false)][0] : javaMethod.getParameterAnnotations();
}
 
Example 4
Source File: ExecutableParameterTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private static Annotation[][] getParameterAnnotations(
        Executable executable, int expectedParameterAnnotationsSize) {
    Annotation[][] allAnnotations = executable.getParameterAnnotations();
    assertEquals(expectedParameterAnnotationsSize, allAnnotations.length);
    return allAnnotations;
}
 
Example 5
Source File: ParameterResolutionDelegate.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Due to a bug in {@code javac} on JDK versions prior to JDK 9, looking up
 * annotations directly on a {@link Parameter} will fail for inner class
 * constructors.
 * <h4>Bug in javac in JDK &lt; 9</h4>
 * <p>The parameter annotations array in the compiled byte code excludes an entry
 * for the implicit <em>enclosing instance</em> parameter for an inner class
 * constructor.
 * <h4>Workaround</h4>
 * <p>This method provides a workaround for this off-by-one error by allowing the
 * caller to access annotations on the preceding {@link Parameter} object (i.e.,
 * {@code index - 1}). If the supplied {@code index} is zero, this method returns
 * an empty {@code AnnotatedElement}.
 * <h4>WARNING</h4>
 * <p>The {@code AnnotatedElement} returned by this method should never be cast and
 * treated as a {@code Parameter} since the metadata (e.g., {@link Parameter#getName()},
 * {@link Parameter#getType()}, etc.) will not match those for the declared parameter
 * at the given index in an inner class constructor.
 * @return the supplied {@code parameter} or the <em>effective</em> {@code Parameter}
 * if the aforementioned bug is in effect
 */
private static AnnotatedElement getEffectiveAnnotatedParameter(Parameter parameter, int index) {
	Executable executable = parameter.getDeclaringExecutable();
	if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
			executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {
		// Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
		// for inner classes, so access it with the actual parameter index lowered by 1
		return (index == 0 ? EMPTY_ANNOTATED_ELEMENT : executable.getParameters()[index - 1]);
	}
	return parameter;
}
 
Example 6
Source File: ParameterAutowireUtils.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Due to a bug in {@code javac} on JDK versions prior to JDK 9, looking up
 * annotations directly on a {@link Parameter} will fail for inner class
 * constructors.
 * <h4>Bug in javac in JDK &lt; 9</h4>
 * <p>The parameter annotations array in the compiled byte code excludes an entry
 * for the implicit <em>enclosing instance</em> parameter for an inner class
 * constructor.
 * <h4>Workaround</h4>
 * <p>This method provides a workaround for this off-by-one error by allowing the
 * caller to access annotations on the preceding {@link Parameter} object (i.e.,
 * {@code index - 1}). If the supplied {@code index} is zero, this method returns
 * an empty {@code AnnotatedElement}.
 * <h4>WARNING</h4>
 * <p>The {@code AnnotatedElement} returned by this method should never be cast and
 * treated as a {@code Parameter} since the metadata (e.g., {@link Parameter#getName()},
 * {@link Parameter#getType()}, etc.) will not match those for the declared parameter
 * at the given index in an inner class constructor.
 * @return the supplied {@code parameter} or the <em>effective</em> {@code Parameter}
 * if the aforementioned bug is in effect
 */
private static AnnotatedElement getEffectiveAnnotatedParameter(Parameter parameter, int index) {
	Executable executable = parameter.getDeclaringExecutable();
	if (executable instanceof Constructor && ClassUtils.isInnerClass(executable.getDeclaringClass()) &&
			executable.getParameterAnnotations().length == executable.getParameterCount() - 1) {
		// Bug in javac in JDK <9: annotation array excludes enclosing instance parameter
		// for inner classes, so access it with the actual parameter index lowered by 1
		return (index == 0 ? EMPTY_ANNOTATED_ELEMENT : executable.getParameters()[index - 1]);
	}
	return parameter;
}