Search in sources :

Example 16 with Retention

use of java.lang.annotation.Retention in project guice by google.

the class Matchers method checkForRuntimeRetention.

private static void checkForRuntimeRetention(Class<? extends Annotation> annotationType) {
    Retention retention = annotationType.getAnnotation(Retention.class);
    checkArgument(retention != null && retention.value() == RetentionPolicy.RUNTIME, "Annotation %s is missing RUNTIME retention", annotationType.getSimpleName());
}
Also used : Retention(java.lang.annotation.Retention)

Example 17 with Retention

use of java.lang.annotation.Retention in project groovy-core by groovy.

the class ResolveVisitor method visitAnnotations.

public void visitAnnotations(AnnotatedNode node) {
    List<AnnotationNode> annotations = node.getAnnotations();
    if (annotations.isEmpty())
        return;
    Map<String, AnnotationNode> tmpAnnotations = new HashMap<String, AnnotationNode>();
    ClassNode annType;
    for (AnnotationNode an : annotations) {
        // skip built-in properties
        if (an.isBuiltIn())
            continue;
        annType = an.getClassNode();
        resolveOrFail(annType, ",  unable to find class for annotation", an);
        for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) {
            Expression newValue = transform(member.getValue());
            newValue = transformInlineConstants(newValue);
            member.setValue(newValue);
            checkAnnotationMemberValue(newValue);
        }
        if (annType.isResolved()) {
            Class annTypeClass = annType.getTypeClass();
            Retention retAnn = (Retention) annTypeClass.getAnnotation(Retention.class);
            if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME)) {
                AnnotationNode anyPrevAnnNode = tmpAnnotations.put(annTypeClass.getName(), an);
                if (anyPrevAnnNode != null) {
                    addError("Cannot specify duplicate annotation on the same member : " + annType.getName(), an);
                }
            }
        }
    }
}
Also used : Retention(java.lang.annotation.Retention)

Aggregations

Retention (java.lang.annotation.Retention)17 Target (java.lang.annotation.Target)5 Method (java.lang.reflect.Method)5 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)5 Expression (org.codehaus.groovy.ast.expr.Expression)5 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)5 ElementType (java.lang.annotation.ElementType)4 RetentionPolicy (java.lang.annotation.RetentionPolicy)4 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)4 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 AnnotationConstantExpression (org.codehaus.groovy.ast.expr.AnnotationConstantExpression)2 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)2 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)2 Test (org.junit.Test)2