use of java.lang.annotation.ElementType in project felix by apache.
the class Predicates method onlySupportedElements.
/**
* Restrict to the supported {@link ElementType}(s) of the annotation (use the @Target, if provided).
* @param annotationType annotation to explore
*/
public static Predicate onlySupportedElements(final Class<? extends Annotation> annotationType) {
Target target = annotationType.getAnnotation(Target.class);
if (target == null) {
return alwaysTrue();
}
Collection<Predicate> supportedTypes = new HashSet<Predicate>();
for (ElementType type : target.value()) {
supportedTypes.add(on(type));
}
return or(supportedTypes);
}
use of java.lang.annotation.ElementType in project checker-framework by typetools.
the class AnnotatedTypes method hasTypeQualifierElementTypes.
/**
* Sees if the passed in array of {@link ElementType} values have the correct set of values
* which defines a type qualifier
*
* @param elements an array of {@link ElementType} values
* @param cls the annotation class being tested; used for diagnostic messages only
* @throws RuntimeException if the array contains both {@link ElementType#TYPE_USE} and
* something besides {@link ElementType#TYPE_PARAMETER}
*/
public static boolean hasTypeQualifierElementTypes(ElementType[] elements, Class<?> cls) {
boolean hasTypeUse = false;
ElementType otherElementType = null;
for (ElementType element : elements) {
if (element.equals(ElementType.TYPE_USE)) {
// valid annotations have to have TYPE_USE
hasTypeUse = true;
} else if (!element.equals(ElementType.TYPE_PARAMETER)) {
// if there's an ElementType with a enumerated value of something other than
// TYPE_USE or TYPE_PARAMETER then it isn't a valid annotation
otherElementType = element;
}
if (hasTypeUse && otherElementType != null) {
ErrorReporter.errorAbort("@Target meta-annotation should not contain both TYPE_USE and " + otherElementType + ", for annotation " + cls.getName());
}
}
return hasTypeUse;
}
use of java.lang.annotation.ElementType in project dolphin-platform by canoo.
the class ActionTestControllerTest method callPrivateMethodWithElementTypeParam.
@Test
public void callPrivateMethodWithElementTypeParam() {
Assert.assertNull(controller.getModel().getEnumValue());
final ElementType value = ElementType.METHOD;
controller.invoke(PUBLIC_WITH_ELEMENT_TYPE_PARAM_ACTION, new Param(PARAM_NAME, value));
Assert.assertEquals(controller.getModel().getEnumValue().compareTo(value), 0);
}
use of java.lang.annotation.ElementType in project groovy-core by groovy.
the class Java5 method configureAnnotation.
private void configureAnnotation(AnnotationNode node, Annotation annotation) {
Class type = annotation.annotationType();
if (type == Retention.class) {
Retention r = (Retention) annotation;
RetentionPolicy value = r.value();
setRetentionPolicy(value, node);
node.setMember("value", new PropertyExpression(new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)), value.toString()));
} else if (type == Target.class) {
Target t = (Target) annotation;
ElementType[] elements = t.value();
ListExpression elementExprs = new ListExpression();
for (ElementType element : elements) {
elementExprs.addExpression(new PropertyExpression(new ClassExpression(ClassHelper.ELEMENT_TYPE_TYPE), element.name()));
}
node.setMember("value", elementExprs);
} else {
Method[] declaredMethods;
try {
declaredMethods = type.getDeclaredMethods();
} catch (SecurityException se) {
declaredMethods = new Method[0];
}
for (Method declaredMethod : declaredMethods) {
try {
Object value = declaredMethod.invoke(annotation);
Expression valueExpression = annotationValueToExpression(value);
if (valueExpression == null)
continue;
node.setMember(declaredMethod.getName(), valueExpression);
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
}
}
use of java.lang.annotation.ElementType in project groovy by apache.
the class Java8 method configureAnnotation.
protected void configureAnnotation(final AnnotationNode node, final Annotation annotation) {
Class<?> type = annotation.annotationType();
if (type == Retention.class) {
Retention r = (Retention) annotation;
RetentionPolicy value = r.value();
setRetentionPolicy(value, node);
node.setMember("value", new PropertyExpression(new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)), value.toString()));
} else if (type == Target.class) {
Target t = (Target) annotation;
ElementType[] elements = t.value();
ListExpression elementExprs = new ListExpression();
for (ElementType element : elements) {
elementExprs.addExpression(new PropertyExpression(new ClassExpression(ClassHelper.ELEMENT_TYPE_TYPE), element.name()));
}
node.setMember("value", elementExprs);
} else {
Method[] declaredMethods;
try {
declaredMethods = type.getDeclaredMethods();
} catch (SecurityException se) {
declaredMethods = EMPTY_METHOD_ARRAY;
}
for (Method declaredMethod : declaredMethods) {
try {
Object value = declaredMethod.invoke(annotation);
Expression valueExpression = annotationValueToExpression(value);
if (valueExpression == null)
continue;
node.setMember(declaredMethod.getName(), valueExpression);
} catch (IllegalAccessException | InvocationTargetException ignore) {
}
}
}
}
Aggregations