1 package com.fasterxml.jackson.databind.introspect; 2 3 import java.lang.annotation.Annotation; 4 import java.lang.reflect.Type; 5 6 import com.fasterxml.jackson.databind.JavaType; 7 8 /** 9 * Intermediate base class that encapsulates features that 10 * constructors and methods share. 11 */ 12 public abstract class AnnotatedWithParams 13 extends AnnotatedMember 14 { 15 private static final long serialVersionUID = 1L; 16 17 /** 18 * Annotations associated with parameters of the annotated 19 * entity (method or constructor parameters) 20 */ 21 protected final AnnotationMap[] _paramAnnotations; 22 23 /* 24 /********************************************************** 25 /* Life-cycle 26 /********************************************************** 27 */ 28 AnnotatedWithParams(TypeResolutionContext ctxt, AnnotationMap annotations, AnnotationMap[] paramAnnotations)29 protected AnnotatedWithParams(TypeResolutionContext ctxt, AnnotationMap annotations, AnnotationMap[] paramAnnotations) 30 { 31 super(ctxt, annotations); 32 _paramAnnotations = paramAnnotations; 33 } 34 35 /** 36 * @since 2.8.1 37 */ AnnotatedWithParams(AnnotatedWithParams base, AnnotationMap[] paramAnnotations)38 protected AnnotatedWithParams(AnnotatedWithParams base, AnnotationMap[] paramAnnotations) { 39 super(base); 40 _paramAnnotations = paramAnnotations; 41 } 42 43 /** 44 * Method called to override a method parameter annotation, 45 * usually due to a mix-in 46 * annotation masking or overriding an annotation 'real' method 47 * has. 48 */ addOrOverrideParam(int paramIndex, Annotation a)49 public final void addOrOverrideParam(int paramIndex, Annotation a) 50 { 51 AnnotationMap old = _paramAnnotations[paramIndex]; 52 if (old == null) { 53 old = new AnnotationMap(); 54 _paramAnnotations[paramIndex] = old; 55 } 56 old.add(a); 57 } 58 59 /** 60 * Method called by parameter object when an augmented instance is created; 61 * needs to replace parameter with new instance 62 */ replaceParameterAnnotations(int index, AnnotationMap ann)63 protected AnnotatedParameter replaceParameterAnnotations(int index, AnnotationMap ann) 64 { 65 _paramAnnotations[index] = ann; 66 return getParameter(index); 67 } 68 69 /* 70 /********************************************************** 71 /* Extended API 72 /********************************************************** 73 */ 74 getParameterAnnotations(int index)75 public final AnnotationMap getParameterAnnotations(int index) 76 { 77 if (_paramAnnotations != null) { 78 if (index >= 0 && index < _paramAnnotations.length) { 79 return _paramAnnotations[index]; 80 } 81 } 82 return null; 83 } 84 getParameter(int index)85 public final AnnotatedParameter getParameter(int index) { 86 return new AnnotatedParameter(this, getParameterType(index), 87 _typeContext, getParameterAnnotations(index), index); 88 } 89 getParameterCount()90 public abstract int getParameterCount(); 91 getRawParameterType(int index)92 public abstract Class<?> getRawParameterType(int index); 93 94 /** 95 * @since 2.7 96 */ getParameterType(int index)97 public abstract JavaType getParameterType(int index); 98 99 /** 100 * @deprecated Since 2.7, remove in 2.9 101 */ 102 @Deprecated getGenericParameterType(int index)103 public abstract Type getGenericParameterType(int index); 104 getAnnotationCount()105 public final int getAnnotationCount() { return _annotations.size(); } 106 107 /** 108 * Method that can be used to (try to) call this object without arguments. 109 * This may succeed or fail, depending on expected number 110 * of arguments: caller needs to take care to pass correct number. 111 * Exceptions are thrown directly from actual low-level call. 112 *<p> 113 * Note: only works for constructors and static methods. 114 */ call()115 public abstract Object call() throws Exception; 116 117 /** 118 * Method that can be used to (try to) call this object with specified arguments. 119 * This may succeed or fail, depending on expected number 120 * of arguments: caller needs to take care to pass correct number. 121 * Exceptions are thrown directly from actual low-level call. 122 *<p> 123 * Note: only works for constructors and static methods. 124 */ call(Object[] args)125 public abstract Object call(Object[] args) throws Exception; 126 127 /** 128 * Method that can be used to (try to) call this object with single arguments. 129 * This may succeed or fail, depending on expected number 130 * of arguments: caller needs to take care to pass correct number. 131 * Exceptions are thrown directly from actual low-level call. 132 *<p> 133 * Note: only works for constructors and static methods. 134 */ call1(Object arg)135 public abstract Object call1(Object arg) throws Exception; 136 } 137