![JAR search and dependency download from the Maven repository](/logo.png)
org.codehaus.jackson.map.introspect.AnnotatedMethod Maven / Gradle / Ivy
Go to download
Data Mapper package is a high-performance data binding package
built on Jackson JSON processor
package org.codehaus.jackson.map.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.codehaus.jackson.map.util.ClassUtil;
public final class AnnotatedMethod
extends Annotated
{
final Method _method;
final AnnotationMap _annotations;
final AnnotationMap[] _paramAnnotations;
// // Simple lazy-caching:
public Class>[] _paramTypes;
/*
//////////////////////////////////////////////////////
// Life-cycle
//////////////////////////////////////////////////////
*/
public AnnotatedMethod(Method method, AnnotationMap annMap,
AnnotationMap[] paramAnnotations)
{
_method = method;
_annotations = annMap;
_paramAnnotations = paramAnnotations;
}
/**
* Method called to augment annotations, by adding specified
* annotation if and only if it is not yet present in the
* annotation map we have.
*/
public void addIfNotPresent(Annotation a)
{
_annotations.addIfNotPresent(a);
}
/**
* Method called to override a method annotation, usually due to a mix-in
* annotation masking or overriding an annotation 'real' method
* has.
*/
public void addOrOverride(Annotation a)
{
_annotations.add(a);
}
/**
* Method called to override a method parameter annotation,
* usually due to a mix-in
* annotation masking or overriding an annotation 'real' method
* has.
*/
public void addOrOverrideParam(int paramIndex, Annotation a)
{
AnnotationMap old = _paramAnnotations[paramIndex];
if (old == null) {
old = new AnnotationMap();
_paramAnnotations[paramIndex] = old;
}
old.add(a);
}
/*
//////////////////////////////////////////////////////
// Annotated impl
//////////////////////////////////////////////////////
*/
public Method getAnnotated() { return _method; }
public int getModifiers() { return _method.getModifiers(); }
public String getName() { return _method.getName(); }
public A getAnnotation(Class acls)
{
return _annotations.get(acls);
}
/**
* For methods, this returns declared return type, which is only
* useful with getters (setters do not return anything; hence "void"
* type is returned here)
*/
public Class> getType() {
return getReturnType();
}
/*
//////////////////////////////////////////////////////
// Extended API, generic
//////////////////////////////////////////////////////
*/
public AnnotatedParameter getParameter(int index) {
return new AnnotatedParameter(getParameterType(index), _paramAnnotations[index]);
}
public Type[] getParameterTypes() {
return _method.getGenericParameterTypes();
}
public Class>[] getParameterClasses()
{
if (_paramTypes == null) {
_paramTypes = _method.getParameterTypes();
}
return _paramTypes;
}
public int getParameterCount() {
return getParameterTypes().length;
}
public Class> getParameterClass(int index)
{
Class>[] types = _method.getParameterTypes();
return (index >= types.length) ? null : types[index];
}
public Type getParameterType(int index)
{
Type[] types = _method.getGenericParameterTypes();
return (index >= types.length) ? null : types[index];
}
public AnnotationMap getParameterAnnotations(int index)
{
if (_paramAnnotations != null) {
if (index >= 0 && index <= _paramAnnotations.length) {
return _paramAnnotations[index];
}
}
return null;
}
public Type getGenericReturnType() { return _method.getGenericReturnType(); }
public Class> getReturnType() { return _method.getReturnType(); }
public Class> getDeclaringClass() { return _method.getDeclaringClass(); }
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName() + "("
+getParameterCount()+" params)";
}
public int getAnnotationCount() { return _annotations.size(); }
/**
* Method that can be called to modify access rights, by calling
* {@link java.lang.reflect.AccessibleObject#setAccessible} on
* the underlying annotated element.
*/
public void fixAccess()
{
ClassUtil.checkAndFixAccess(_method);
}
/*
//////////////////////////////////////////////////////
// Extended API, specific annotations
//////////////////////////////////////////////////////
*/
public String toString()
{
return "[method "+getName()+", annotations: "+_annotations+"]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy