Java Class.getDeclaredAnnotations Examples

Java Class.getDeclaredAnnotations - 17 examples found. These are the top rated real world Java examples of Class.getDeclaredAnnotations extracted from open source projects. You can rate examples to help us improve the quality of examples.
 protected void _addClassMixIns(AnnotationMap annotations, Class<?> toMask, Class<?> mixin) {
   if (mixin == null) {
     return;
   }
   // Ok, first: annotations from mix-in class itself:
   for (Annotation a : mixin.getDeclaredAnnotations()) {
     if (_annotationIntrospector.isHandled(a)) {
       annotations.addIfNotPresent(a);
     }
   }
   /* And then from its supertypes, if any. But note that we will
    *  only consider super-types up until reaching the masked
    * class (if found); this because often mix-in class
    * is a sub-class (for convenience reasons). And if so, we
    * absolutely must NOT include super types of masked class,
    * as that would inverse precedence of annotations.
    */
   for (Class<?> parent : ClassUtil.findSuperTypes(mixin, toMask)) {
     for (Annotation a : parent.getDeclaredAnnotations()) {
       if (_annotationIntrospector.isHandled(a)) {
         annotations.addIfNotPresent(a);
       }
     }
   }
 }
  /**
   * Initialization method that will recursively collect Jackson annotations for this class and all
   * super classes and interfaces.
   *
   * <p>Starting with 1.2, it will also apply mix-in annotations, as per [JACKSON-76]
   */
  protected void resolveClassAnnotations() {
    _classAnnotations = new AnnotationMap();
    // add mix-in annotations first (overrides)
    if (_primaryMixIn != null) {
      _addClassMixIns(_classAnnotations, _class, _primaryMixIn);
    }
    // first, annotations from the class itself:
    for (Annotation a : _class.getDeclaredAnnotations()) {
      if (_annotationIntrospector.isHandled(a)) {
        _classAnnotations.addIfNotPresent(a);
      }
    }

    // and then from super types
    for (Class<?> cls : _superTypes) {
      // and mix mix-in annotations in-between
      _addClassMixIns(_classAnnotations, cls);
      for (Annotation a : cls.getDeclaredAnnotations()) {
        if (_annotationIntrospector.isHandled(a)) {
          _classAnnotations.addIfNotPresent(a);
        }
      }
    }

    /* and finally... any annotations there might be for plain
     * old Object.class: separate because for all other purposes
     * it is just ignored (not included in super types)
     */
    /* 12-Jul-2009, tatu: Should this be done for interfaces too?
     *   For now, yes, seems useful for some cases, and not harmful
     *   for any?
     */
    _addClassMixIns(_classAnnotations, Object.class);
  }
 private void assertAnnotations(Class<?> type) {
   assertThat(
       describe(type).getDeclaredAnnotations(),
       hasItems(
           new AnnotationList.ForLoadedAnnotation(type.getDeclaredAnnotations())
               .toArray(new AnnotationDescription[type.getDeclaredAnnotations().length])));
   assertThat(
       describe(type).getDeclaredAnnotations().size(), is(type.getDeclaredAnnotations().length));
   assertThat(
       describe(type).getInheritedAnnotations(),
       hasItems(
           new AnnotationList.ForLoadedAnnotation(type.getAnnotations())
               .toArray(new AnnotationDescription[type.getAnnotations().length])));
   assertThat(describe(type).getInheritedAnnotations().size(), is(type.getAnnotations().length));
 }
 private void verifyExternalClass(final Class clazz) {
   // don't recommended to instantiate the class doing clazz.newInstance().
   clazz.getDeclaredConstructors();
   clazz.getDeclaredFields();
   clazz.getDeclaredMethods();
   clazz.getDeclaredClasses();
   clazz.getDeclaredAnnotations();
 }
Example #5
0
 private GenerateForm getFormAnnotation(Class formClass) {
   GenerateForm formAnnotation = null;
   for (Annotation annotation : formClass.getDeclaredAnnotations()) {
     Log.i(TAG, "class annotation: " + annotation);
     if (annotation instanceof GenerateForm) {
       formAnnotation = (GenerateForm) annotation;
       break;
     }
   }
   return formAnnotation;
 }
  private String getName() {
    Class<T> type = getType();
    for (Annotation annotation : type.getDeclaredAnnotations()) {
      if (annotation.annotationType().isAssignableFrom(PreferenceFile.class)) {
        PreferenceFile preferenceFileAnnotation = (PreferenceFile) annotation;
        return preferenceFileAnnotation.name();
      }
    }

    return type.getSimpleName();
  }