@Override public SynthesizingMethodParameter clone() { return new SynthesizingMethodParameter(this); }
/** * Create a new SynthesizingMethodParameter for the given parameter descriptor. * <p>This is a convenience factory method for scenarios where a * Java 8 {@link Parameter} descriptor is already available. * @param parameter the parameter descriptor * @return the corresponding SynthesizingMethodParameter instance * @since 5.0 */ public static SynthesizingMethodParameter forParameter(Parameter parameter) { return forExecutable(parameter.getDeclaringExecutable(), findParameterIndex(parameter)); }
@Override protected <A extends Annotation> A adaptAnnotation(A annotation) { return AnnotationUtils.synthesizeAnnotation(annotation, getAnnotatedElement()); }
@Test public void testHashCode() throws NoSuchMethodException { assertEquals(stringParameter.hashCode(), stringParameter.hashCode()); assertEquals(longParameter.hashCode(), longParameter.hashCode()); assertEquals(intReturnType.hashCode(), intReturnType.hashCode()); Method method = getClass().getMethod("method", String.class, Long.TYPE); SynthesizingMethodParameter methodParameter = new SynthesizingMethodParameter(method, 0); assertEquals(stringParameter.hashCode(), methodParameter.hashCode()); assertNotEquals(longParameter.hashCode(), methodParameter.hashCode()); }
@Test public void testFactoryMethods() { assertEquals(stringParameter, SynthesizingMethodParameter.forExecutable(method, 0)); assertEquals(longParameter, SynthesizingMethodParameter.forExecutable(method, 1)); assertEquals(stringParameter, SynthesizingMethodParameter.forParameter(method.getParameters()[0])); assertEquals(longParameter, SynthesizingMethodParameter.forParameter(method.getParameters()[1])); }
@Test public void testEquals() throws NoSuchMethodException { assertEquals(stringParameter, stringParameter); assertEquals(longParameter, longParameter); assertEquals(intReturnType, intReturnType); assertFalse(stringParameter.equals(longParameter)); assertFalse(stringParameter.equals(intReturnType)); assertFalse(longParameter.equals(stringParameter)); assertFalse(longParameter.equals(intReturnType)); assertFalse(intReturnType.equals(stringParameter)); assertFalse(intReturnType.equals(longParameter)); Method method = getClass().getMethod("method", String.class, Long.TYPE); MethodParameter methodParameter = new SynthesizingMethodParameter(method, 0); assertEquals(stringParameter, methodParameter); assertEquals(methodParameter, stringParameter); assertNotEquals(longParameter, methodParameter); assertNotEquals(methodParameter, longParameter); methodParameter = new MethodParameter(method, 0); assertEquals(stringParameter, methodParameter); assertEquals(methodParameter, stringParameter); assertNotEquals(longParameter, methodParameter); assertNotEquals(methodParameter, longParameter); }
boolean required = (autowired == null || autowired.required()); MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable( parameter.getDeclaringExecutable(), parameterIndex); DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
Annotation[] anns = this.combinedAnnotations; if (anns == null) { anns = super.getParameterAnnotations(); int index = getParameterIndex(); if (index >= 0) {
boolean required = (autowired == null || autowired.required()); MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable( parameter.getDeclaringExecutable(), parameterIndex); DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
Annotation[] anns = this.combinedAnnotations; if (anns == null) { anns = super.getParameterAnnotations(); for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) { int index = getParameterIndex();
/** * Create a new SynthesizingMethodParameter for the given method or constructor. * <p>This is a convenience factory method for scenarios where a * Method or Constructor reference is treated in a generic fashion. * @param executable the Method or Constructor to specify a parameter for * @param parameterIndex the index of the parameter * @return the corresponding SynthesizingMethodParameter instance * @since 5.0 */ public static SynthesizingMethodParameter forExecutable(Executable executable, int parameterIndex) { if (executable instanceof Method) { return new SynthesizingMethodParameter((Method) executable, parameterIndex); } else if (executable instanceof Constructor) { return new SynthesizingMethodParameter((Constructor<?>) executable, parameterIndex); } else { throw new IllegalArgumentException("Not a Method/Constructor: " + executable); } }
/** * Create a new SynthesizingMethodParameter for the given parameter descriptor. * <p>This is a convenience factory method for scenarios where a * Java 8 {@link Parameter} descriptor is already available. * @param parameter the parameter descriptor * @return the corresponding SynthesizingMethodParameter instance * @since 5.0 */ public static SynthesizingMethodParameter forParameter(Parameter parameter) { return forExecutable(parameter.getDeclaringExecutable(), findParameterIndex(parameter)); }
@Override protected Annotation[] adaptAnnotationArray(Annotation[] annotations) { return AnnotationUtils.synthesizeAnnotationArray(annotations, getAnnotatedElement()); }
boolean required = (autowired == null || autowired.required()); MethodParameter methodParameter = SynthesizingMethodParameter.forExecutable( parameter.getDeclaringExecutable(), parameterIndex); DependencyDescriptor descriptor = new DependencyDescriptor(methodParameter, required);
@Override public Annotation[] getParameterAnnotations() { Annotation[] anns = this.combinedAnnotations; if (anns == null) { anns = super.getParameterAnnotations(); for (Annotation[][] ifcAnns : getInterfaceParameterAnnotations()) { Annotation[] paramAnns = ifcAnns[getParameterIndex()]; if (paramAnns.length > 0) { List<Annotation> merged = new ArrayList<>(anns.length + paramAnns.length); merged.addAll(Arrays.asList(anns)); for (Annotation paramAnn : paramAnns) { boolean existingType = false; for (Annotation ann : anns) { if (ann.annotationType() == paramAnn.annotationType()) { existingType = true; break; } } if (!existingType) { merged.add(adaptAnnotation(paramAnn)); } } anns = merged.toArray(new Annotation[0]); } } this.combinedAnnotations = anns; } return anns; }
@Override public SynthesizingMethodParameter clone() { return new SynthesizingMethodParameter(this); }
/** * Create a new SynthesizingMethodParameter for the given parameter descriptor. * <p>This is a convenience factory method for scenarios where a * Java 8 {@link Parameter} descriptor is already available. * @param parameter the parameter descriptor * @return the corresponding SynthesizingMethodParameter instance * @since 5.0 */ public static SynthesizingMethodParameter forParameter(Parameter parameter) { return forExecutable(parameter.getDeclaringExecutable(), findParameterIndex(parameter)); }
@Override protected <A extends Annotation> A adaptAnnotation(A annotation) { return AnnotationUtils.synthesizeAnnotation(annotation, getAnnotatedElement()); }
/** * Return the declared return type of the resolved method. */ public MethodParameter returnType() { return new SynthesizingMethodParameter(this.method, -1); }
/** * Create a new SynthesizingMethodParameter for the given parameter descriptor. * <p>This is a convenience factory method for scenarios where a * Java 8 {@link Parameter} descriptor is already available. * @param parameter the parameter descriptor * @return the corresponding SynthesizingMethodParameter instance * @since 5.0 */ public static SynthesizingMethodParameter forParameter(Parameter parameter) { return forExecutable(parameter.getDeclaringExecutable(), findParameterIndex(parameter)); }