Java Code Examples for java.lang.annotation.Retention

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/event/.

Source file: EventUtil.java

  33 
vote

public static void checkEventBindings(WebBeansContext webBeansContext,Annotation... annotations){
  for (  Annotation ann : annotations) {
    Retention retention=ann.annotationType().getAnnotation(Retention.class);
    RetentionPolicy policy=retention.value();
    if (!policy.equals(RetentionPolicy.RUNTIME)) {
      throw new IllegalArgumentException("Event qualifiere RetentionPolicy must be RUNTIME for qualifier : " + ann);
    }
  }
  webBeansContext.getAnnotationManager().checkQualifierConditions(annotations);
}
 

Example 2

From project hibernate-validator, under directory /annotation-processor/src/main/java/org/hibernate/validator/ap/checks/.

Source file: RetentionPolicyCheck.java

  32 
vote

@Override public Set<ConstraintCheckError> checkAnnotationType(TypeElement element,AnnotationMirror annotation){
  Retention retention=element.getAnnotation(Retention.class);
  if (retention == null) {
    return CollectionHelper.asSet(new ConstraintCheckError(element,null,"CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION"));
  }
  if (!retention.value().equals(RetentionPolicy.RUNTIME)) {
    return CollectionHelper.asSet(new ConstraintCheckError(element,annotationApiHelper.getMirror(element.getAnnotationMirrors(),Retention.class),"CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION"));
  }
  return Collections.emptySet();
}
 

Example 3

From project griffon, under directory /subprojects/griffon-cli/src/main/groovy/org/codehaus/griffon/compiler/.

Source file: ResolveVisitor.java

  31 
vote

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) {
    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);
        }
      }
    }
  }
}
 

Example 4

From project rewrite, under directory /integration-cdi/src/main/java/org/ocpsoft/rewrite/cdi/util/.

Source file: Reflections.java

  29 
vote

/** 
 * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.
 * @param binding The binding type to check
 * @return true only if the annotation is really a binding type
 */
@Deprecated public static boolean isBindings(Annotation binding){
  boolean isBindingAnnotation=false;
  if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {
    isBindingAnnotation=true;
  }
  return isBindingAnnotation;
}
 

Example 5

From project solder, under directory /api/src/main/java/org/jboss/solder/reflection/.

Source file: Reflections.java

  29 
vote

/** 
 * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.
 * @param binding The binding type to check
 * @return true only if the annotation is really a binding type
 */
@Deprecated public static boolean isBindings(Annotation binding){
  boolean isBindingAnnotation=false;
  if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {
    isBindingAnnotation=true;
  }
  return isBindingAnnotation;
}