コード例 #1
0
  public String resolveAnnotationType(Annotation annotation) {
    StringBuffer type = new StringBuffer();
    AnnotationDefinition annotationDefinition = annotation.getAnnotationDefinition();

    if (annotationDefinition == null) {
      logger.warn("Annotation definition for annotation: " + annotation + " is not defined.");
      return type.toString();
    }

    if (annotationDefinition.isMarker()) {
      return type.toString();
    }

    // finally we can process annotation members.
    Object memberValue;
    int memberCount = 0;
    for (AnnotationMemberDefinition memberDefinition :
        annotationDefinition.getAnnotationMembers()) {
      if ((memberValue = annotation.getValue(memberDefinition.getName())) != null) {
        // a value has been set for this member.
        if (memberCount == 0) type.append("(");
        if (memberCount > 0) type.append(", ");
        type.append(resolveMemberType(memberDefinition, memberValue));
        memberCount++;
      }
    }
    if (memberCount > 0) type.append(")");

    return type.toString();
  }
コード例 #2
0
 public static AnnotationDefinition build(
     Class annotationClass, Map<String, String> valueMap, TypeResolver resolver)
     throws NoSuchMethodException {
   AnnotationDefinition annotationDefinition = new AnnotationDefinition(annotationClass.getName());
   HashMap<String, AnnotationPropertyVal> values = new HashMap<String, AnnotationPropertyVal>();
   for (String key : valueMap.keySet()) {
     AnnotationPropertyVal value = rebuild(key, annotationClass, valueMap.get(key), resolver);
     if (value != null) {
       values.put(key, value);
     }
   }
   annotationDefinition.values = Collections.unmodifiableMap(values);
   return annotationDefinition;
 }