001/* 002 * Copyright 2002-2016 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.core.annotation; 018 019import java.lang.annotation.Annotation; 020import java.lang.reflect.Constructor; 021import java.lang.reflect.Method; 022 023import org.springframework.core.MethodParameter; 024 025/** 026 * A {@link MethodParameter} variant which synthesizes annotations that 027 * declare attribute aliases via {@link AliasFor @AliasFor}. 028 * 029 * @author Juergen Hoeller 030 * @author Sam Brannen 031 * @since 4.2 032 * @see AnnotationUtils#synthesizeAnnotation 033 * @see AnnotationUtils#synthesizeAnnotationArray 034 */ 035public class SynthesizingMethodParameter extends MethodParameter { 036 037 /** 038 * Create a new {@code SynthesizingMethodParameter} for the given method, 039 * with nesting level 1. 040 * @param method the Method to specify a parameter for 041 * @param parameterIndex the index of the parameter: -1 for the method 042 * return type; 0 for the first method parameter; 1 for the second method 043 * parameter, etc. 044 */ 045 public SynthesizingMethodParameter(Method method, int parameterIndex) { 046 super(method, parameterIndex); 047 } 048 049 /** 050 * Create a new {@code SynthesizingMethodParameter} for the given method. 051 * @param method the Method to specify a parameter for 052 * @param parameterIndex the index of the parameter: -1 for the method 053 * return type; 0 for the first method parameter; 1 for the second method 054 * parameter, etc. 055 * @param nestingLevel the nesting level of the target type 056 * (typically 1; e.g. in case of a List of Lists, 1 would indicate the 057 * nested List, whereas 2 would indicate the element of the nested List) 058 */ 059 public SynthesizingMethodParameter(Method method, int parameterIndex, int nestingLevel) { 060 super(method, parameterIndex, nestingLevel); 061 } 062 063 /** 064 * Create a new {@code SynthesizingMethodParameter} for the given constructor, 065 * with nesting level 1. 066 * @param constructor the Constructor to specify a parameter for 067 * @param parameterIndex the index of the parameter 068 */ 069 public SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex) { 070 super(constructor, parameterIndex); 071 } 072 073 /** 074 * Create a new {@code SynthesizingMethodParameter} for the given constructor. 075 * @param constructor the Constructor to specify a parameter for 076 * @param parameterIndex the index of the parameter 077 * @param nestingLevel the nesting level of the target type 078 * (typically 1; e.g. in case of a List of Lists, 1 would indicate the 079 * nested List, whereas 2 would indicate the element of the nested List) 080 */ 081 public SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel) { 082 super(constructor, parameterIndex, nestingLevel); 083 } 084 085 /** 086 * Copy constructor, resulting in an independent {@code SynthesizingMethodParameter} 087 * based on the same metadata and cache state that the original object was in. 088 * @param original the original SynthesizingMethodParameter object to copy from 089 */ 090 protected SynthesizingMethodParameter(SynthesizingMethodParameter original) { 091 super(original); 092 } 093 094 095 @Override 096 protected <A extends Annotation> A adaptAnnotation(A annotation) { 097 return AnnotationUtils.synthesizeAnnotation(annotation, getAnnotatedElement()); 098 } 099 100 @Override 101 protected Annotation[] adaptAnnotationArray(Annotation[] annotations) { 102 return AnnotationUtils.synthesizeAnnotationArray(annotations, getAnnotatedElement()); 103 } 104 105 106 @Override 107 public SynthesizingMethodParameter clone() { 108 return new SynthesizingMethodParameter(this); 109 } 110 111}