All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.crnk.rs.internal.legacy.provider.Parameter Maven / Gradle / Ivy

There is a newer version: 2.6.20180430102904
Show newest version
package io.crnk.rs.internal.legacy.provider;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Parameter {

	private final Method method;
	private final int parameterIndex;

	public Parameter(Method method, int parameterIndex) {
		this.method = method;
		this.parameterIndex = parameterIndex;
	}

	public Class getType() {
		return method.getParameterTypes()[parameterIndex];
	}

	public  T getAnnotation(Class clazz) {
		Annotation[] annotations = method.getParameterAnnotations()[parameterIndex];
		for (Annotation annotation : annotations) {
			if (clazz.isAssignableFrom(annotation.getClass())) {
				return (T) annotation;
			}
		}

		return null;
	}

	public boolean isAnnotationPresent(Class clazz) {
		Annotation[] annotations = method.getParameterAnnotations()[parameterIndex];
		for (Annotation annotation : annotations) {
			if (clazz.isAssignableFrom(annotation.getClass())) {
				return true;
			}
		}

		return false;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy