本文整理汇总了Java中java.lang.annotation.Annotation.annotationType方法的典型用法代码示例。如果您正苦于以下问题:Java Annotation.annotationType方法的具体用法?Java Annotation.annotationType怎么用?Java Annotation.annotationType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.annotation.Annotation
的用法示例。
在下文中一共展示了Annotation.annotationType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBindingAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
/**
* Returns the binding annotation on {@code member}, or null if there isn't one.
*/
public static Annotation findBindingAnnotation(
Errors errors, Member member, Annotation[] annotations) {
Annotation found = null;
for (Annotation annotation : annotations) {
Class<? extends Annotation> annotationType = annotation.annotationType();
if (isBindingAnnotation(annotationType)) {
if (found != null) {
errors.duplicateBindingAnnotations(member, found.annotationType(), annotationType);
} else {
found = annotation;
}
}
}
return found;
}
示例2: isInjectedField
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private static boolean isInjectedField(final Field field) {
for (final Annotation a : field.getDeclaredAnnotations()) {
final Class<?> t = a.annotationType();
if (t == javax.inject.Inject.class ||
t == javax.ws.rs.core.Context.class ||
t == javax.ws.rs.CookieParam.class ||
t == javax.ws.rs.FormParam.class ||
t == javax.ws.rs.HeaderParam.class ||
t == javax.ws.rs.QueryParam.class ||
t == javax.ws.rs.PathParam.class ||
t == javax.ws.rs.BeanParam.class ||
t == OptionalClasses.PERSISTENCE_CONTEXT) {
return true;
}
}
return false;
}
示例3: processAnnotations
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private void processAnnotations(Object device) {
if (device==null) return;
final Method[] methods = device.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
final Annotation[] as = methods[i].getAnnotations();
if (as!=null) for (Annotation annotation : as) {
Class<? extends Annotation> clazz = annotation.annotationType();
if (this.annotations.contains(clazz)) {
Collection<MethodWrapper> ms = annotationMap.get(clazz);
if (ms == null) {
ms = new ArrayList<>(31);
annotationMap.put(clazz, ms);
}
ms.add(new MethodWrapper(clazz, device, methods[i]));
}
}
}
}
示例4: getEntityAnnos
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private static List<Map<String, Object>> getEntityAnnos(Object targetClass, String annotationName) {
Annotation[] anno = null;
if (targetClass instanceof Field)
anno = ((Field) targetClass).getAnnotations();
else
anno = ((Class<?>) targetClass).getAnnotations();
List<Map<String, Object>> l = new ArrayList<Map<String, Object>>();
for (Annotation annotation : anno) {
Class<? extends Annotation> type = annotation.annotationType();
String cName = type.getName();
if (matchNameCheck(annotationName, cName)) {
l.add(changeAnnotationValuesToMap(annotation, type));
}
}
return l;
}
示例5: invokeAnnotationByField
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
/**
* Invokes the annotation of the given field
*
* @param field field
* @param annotationClazz annotation
* @param <T> returnType
* @return returnValue
*/
public static <T extends Annotation> T invokeAnnotationByField(Field field, Class<T> annotationClazz) {
if (field == null)
throw new IllegalArgumentException("Field cannot be null!");
if (annotationClazz == null)
throw new IllegalArgumentException("AnnotationClass cannot be null!");
for (final Annotation annotation : field.getDeclaredAnnotations()) {
if (annotation.annotationType() == annotationClazz)
return (T) annotation;
}
return null;
}
示例6: getAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
protected Class<?> getAnnotation(Class<?> c) {
// we should get only declared annotations, not inherited ones
Annotation[] anns = c.getDeclaredAnnotations();
for (Annotation ann : anns) {
// Hadoop clearly got it wrong for not making the annotation values (private, public, ..)
// an enum instead we have three independent annotations!
Class<?> type = ann.annotationType();
if (isInterfaceAudienceClass(type)) {
return type;
}
}
return null;
}
示例7: getAlwaysRunFromAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private boolean getAlwaysRunFromAnnotation(final Annotation methodAnnotation) {
if (methodAnnotation.annotationType() == OurBeforeSuite.class) {
return ((OurBeforeSuite) methodAnnotation).alwaysRun();
}
if (methodAnnotation.annotationType() == OurBeforeGroups.class) {
return ((OurBeforeGroups) methodAnnotation).alwaysRun();
}
if (methodAnnotation.annotationType() == OurAfterGroups.class) {
return ((OurAfterGroups) methodAnnotation).alwaysRun();
}
return methodAnnotation.annotationType() != OurAfterSuite.class || ((OurAfterSuite) methodAnnotation).alwaysRun();
}
示例8: getValueAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
/**
* Gets the class of the value annotation belonging
* to a field, null if there is none.
*
* @param field Field being checked
* @return The value annotation of the field
*/
private static Class<? extends Annotation> getValueAnnotation(Field field) {
// Values must have a label annotation
if (!field.isAnnotationPresent(Label.class))
return null;
// Find a valid value type annotation, if any
Annotation a = Arrays.stream(field.getDeclaredAnnotations())
.filter(annotation -> annotation.annotationType().isAnnotationPresent(ValueDefinition.class))
.findFirst().orElse(null);
return a != null ? a.annotationType() : null;
}
示例9: findAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
@Nullable public static Annotation findAnnotation(Set<? extends Annotation> annotations,
Class<? extends Annotation> annotationClass) {
if (annotations.isEmpty()) return null; // Save an iterator in the common case.
for (Annotation annotation : annotations) {
if (annotation.annotationType() == annotationClass) return annotation;
}
return null;
}
示例10: get
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
/**
* Finds the specified annotation from the array and returns it.
* Null if not found.
*/
public <A extends Annotation> A get( Class<A> annotationType ) {
for (Annotation a : annotations) {
if(a.annotationType()==annotationType)
return annotationType.cast(a);
}
return null;
}
示例11: printArrContents
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private static void printArrContents(Annotation[] actualAnnos) {
System.out.print("Actual Arr Values: ");
for (Annotation a : actualAnnos) {
if (a != null && a.annotationType() != null) {
System.out.print("[" + a.toString() + "]");
} else {
System.out.println("[null]");
}
}
System.out.println();
}
示例12: invokeAnnotationByMethod
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
/**
* Invokes the annotation of the given method
*
* @param method method
* @param annotationClazz annotation
* @param <T> returnType
* @return returnValue
*/
public static <T extends Annotation> T invokeAnnotationByMethod(Method method, Class<T> annotationClazz) {
if (method == null)
throw new IllegalArgumentException("Method cannot be null!");
if (annotationClazz == null)
throw new IllegalArgumentException("AnnotationClass cannot be null!");
for (final Annotation annotation : method.getDeclaredAnnotations()) {
if (annotation.annotationType() == annotationClazz)
return (T) annotation;
}
return null;
}
示例13: hasRequestBodyAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private static boolean hasRequestBodyAnnotation(Annotation[][] annotations) {
if (annotations.length == 1) {
Annotation[] containerAnnotations = annotations[0];
for (Annotation annotation : containerAnnotations) {
Type annotationType = annotation.annotationType();
if (annotationType == RequestBody.class) {
return true;
}
}
}
return false;
}
示例14: processAnnotation
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private void processAnnotation(final Annotation annotation) {
final Class<? extends Annotation> annType = annotation.annotationType();
if (annType == Context.class) {
setStrategy(Strategy.CONTEXT);
} else if (annType == CookieParam.class) {
processCookieParamAnnotation((CookieParam) annotation);
} else if (annType == FormParam.class) {
processFormParamAnnotation((FormParam) annotation);
} else if (annType == HeaderParam.class) {
processHeaderParamAnnotation((HeaderParam) annotation);
} else if (annType == Named.class) {
processNamedAnnotation((Named) annotation);
} else if (annType == PathParam.class) {
processPathParamAnnotation((PathParam) annotation);
} else if (annType == OptionalClasses.PERSISTENCE_CONTEXT) {
processPersistenceContextAnnotation((PersistenceContext) annotation);
} else if (annType == QueryParam.class) {
processQueryParamAnnotation((QueryParam) annotation);
} else if (annType == DefaultValue.class) {
defaultValue = (DefaultValue) annotation;
} else if (annType.isAnnotationPresent(Qualifier.class)) {
processQualifierAnnotation(annType);
}
}
示例15: search
import java.lang.annotation.Annotation; //导入方法依赖的package包/类
private Class<? extends Annotation> search(
final Field field
) {
final Annotation[] annotations = field.getDeclaredAnnotations();
final Set<Class<? extends Annotation>>
annotationCls = Plugins.INFIX_MAP.keySet();
Class<? extends Annotation> hitted = null;
for (final Annotation annotation : annotations) {
if (annotationCls.contains(annotation.annotationType())) {
hitted = annotation.annotationType();
break;
}
}
return hitted;
}