use of java.lang.annotation.ElementType in project checker-framework by typetools.
the class AnnotatedTypeFactory method checkSupportedQuals.
/**
* @throws BugInCF If supportedQuals is empty or if any of the support qualifiers has a @Target
* meta-annotation that contain something besides TYPE_USE or TYPE_PARAMETER. (@Target({}) is
* allowed.)
*/
private void checkSupportedQuals() {
if (supportedQuals.isEmpty()) {
throw new TypeSystemError("Found no supported qualifiers.");
}
for (Class<? extends Annotation> annotationClass : supportedQuals) {
// Check @Target values
ElementType[] targetValues = annotationClass.getAnnotation(Target.class).value();
List<ElementType> badTargetValues = new ArrayList<>();
for (ElementType element : targetValues) {
if (!(element == ElementType.TYPE_USE || element == ElementType.TYPE_PARAMETER)) {
// if there's an ElementType with an enumerated value of something other
// than TYPE_USE or TYPE_PARAMETER then it isn't a valid qualifier
badTargetValues.add(element);
}
}
if (!badTargetValues.isEmpty()) {
String msg = "The @Target meta-annotation on type qualifier " + annotationClass.toString() + " must not contain " + StringsPlume.conjunction("or", badTargetValues) + ".";
throw new TypeSystemError(msg);
}
}
}
use of java.lang.annotation.ElementType in project geronimo-xbean by apache.
the class MetaAnnotatedElement method validTarget.
private static boolean validTarget(Class<? extends Annotation> type) {
final Target target = type.getAnnotation(Target.class);
if (target == null)
return false;
final ElementType[] targets = target.value();
return targets.length == 1 && targets[0] == ElementType.ANNOTATION_TYPE;
}
use of java.lang.annotation.ElementType in project groovy by apache.
the class Java8 method configureAnnotationNodeFromDefinition.
@Override
public void configureAnnotationNodeFromDefinition(final AnnotationNode definition, final AnnotationNode root) {
ClassNode type = definition.getClassNode();
final String typeName = type.getName();
if ("java.lang.annotation.Retention".equals(typeName)) {
Expression exp = definition.getMember("value");
if (!(exp instanceof PropertyExpression))
return;
PropertyExpression pe = (PropertyExpression) exp;
String name = pe.getPropertyAsString();
RetentionPolicy policy = RetentionPolicy.valueOf(name);
setRetentionPolicy(policy, root);
} else if ("java.lang.annotation.Target".equals(typeName)) {
Expression exp = definition.getMember("value");
if (!(exp instanceof ListExpression))
return;
ListExpression le = (ListExpression) exp;
int bitmap = 0;
for (Expression e : le.getExpressions()) {
if (!(e instanceof PropertyExpression))
return;
PropertyExpression element = (PropertyExpression) e;
String name = element.getPropertyAsString();
ElementType value = ElementType.valueOf(name);
bitmap |= getElementCode(value);
}
root.setAllowedTargets(bitmap);
}
}
use of java.lang.annotation.ElementType in project xtext-xtend by eclipse.
the class XtendValidator method checkAnnotationTarget.
@Check
public void checkAnnotationTarget(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return;
}
Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
if (targets.isEmpty())
return;
final EObject eContainer = getContainingAnnotationTarget(annotation);
Class<? extends EObject> clazz = eContainer.getClass();
if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
clazz = XtendFunction.class;
}
for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
if (mapping.getKey().isAssignableFrom(clazz)) {
targets.retainAll(mapping.getValue());
if (targets.isEmpty()) {
error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET);
}
}
}
}
use of java.lang.annotation.ElementType in project antlr4 by tunnelvisionlabs.
the class RuleDependencyChecker method getDependencies.
public static List<Tuple2<RuleDependency, AnnotatedElement>> getDependencies(Class<?> clazz) {
List<Tuple2<RuleDependency, AnnotatedElement>> result = new ArrayList<Tuple2<RuleDependency, AnnotatedElement>>();
List<ElementType> supportedTarget = Arrays.asList(RuleDependency.class.getAnnotation(Target.class).value());
for (ElementType target : supportedTarget) {
switch(target) {
case TYPE:
if (!clazz.isAnnotation()) {
getElementDependencies(clazz, result);
}
break;
case ANNOTATION_TYPE:
if (!clazz.isAnnotation()) {
getElementDependencies(clazz, result);
}
break;
case CONSTRUCTOR:
for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
getElementDependencies(ctor, result);
}
break;
case FIELD:
for (Field field : clazz.getDeclaredFields()) {
getElementDependencies(field, result);
}
break;
case LOCAL_VARIABLE:
System.err.println("Runtime rule dependency checking is not supported for local variables.");
break;
case METHOD:
for (Method method : clazz.getDeclaredMethods()) {
getElementDependencies(method, result);
}
break;
case PACKAGE:
// package is not a subset of class, so nothing to do here
break;
case PARAMETER:
System.err.println("Runtime rule dependency checking is not supported for parameters.");
break;
}
}
return result;
}
Aggregations