コード例 #1
0
ファイル: Java5.java プロジェクト: bodiam/discobot
 private void setAnnotationMetaData(Annotation[] annotations, AnnotatedNode an) {
   for (Annotation annotation : annotations) {
     AnnotationNode node = new AnnotationNode(ClassHelper.make(annotation.annotationType()));
     configureAnnotation(node, annotation);
     an.addAnnotation(node);
   }
 }
コード例 #2
0
    private boolean hasParamAnnotation(Method method) {
      Annotation[][] paramAnnotationArrays = method.getParameterAnnotations();
      for (Annotation[] paramAnnotations : paramAnnotationArrays)
        for (Annotation paramAnnotation : paramAnnotations)
          if (paramAnnotation.annotationType().isAssignableFrom(Param.class)) return true;

      return false;
    }
コード例 #3
0
ファイル: Distributor.java プロジェクト: superyfwy/db4o
 public static boolean hasAnnotation(Annotation[] anns, Class<? extends Annotation> clazz) {
   for (Annotation ann : anns) {
     if (clazz == ann.annotationType()) {
       return true;
     }
   }
   return false;
 }
コード例 #4
0
 // Ang's suggestion on getting annotation values
 public static String getClassAnnotationValue(
     Class classType, Class annotationType, String attributeName) {
   String value = null;
   Annotation annotation = classType.getAnnotation(annotationType);
   if (annotation != null) {
     try {
       value = (String) annotation.annotationType().getMethod(attributeName).invoke(annotation);
     } catch (Exception ex) {
       System.out.println("Failed loading class annotations");
     }
   }
   return value;
 }
コード例 #5
0
  private void addAsTestedFieldIfApplicable(@NotNull Field fieldFromTestClass) {
    for (Annotation fieldAnnotation : fieldFromTestClass.getDeclaredAnnotations()) {
      Tested testedMetadata;

      if (fieldAnnotation instanceof Tested) {
        testedMetadata = (Tested) fieldAnnotation;
      } else {
        testedMetadata = fieldAnnotation.annotationType().getAnnotation(Tested.class);
      }

      if (testedMetadata != null) {
        TestedField testedField =
            new TestedField(injectionState, fieldFromTestClass, testedMetadata);
        testedFields.add(testedField);
        break;
      }
    }
  }
コード例 #6
0
ファイル: Java5.java プロジェクト: bodiam/discobot
 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 = type.getDeclaredMethods();
     for (int i = 0; i < declaredMethods.length; i++) {
       Method declaredMethod = declaredMethods[i];
       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) {
       }
     }
   }
 }
コード例 #7
0
 /** Adds the annotations to the digest using a UTF8 encoding. */
 private static void addDigest(MessageDigest digest, Annotation ann) {
   addDigest(digest, ann.annotationType().getName());
 }