Java Class.isAnnotation Examples

Java Class.isAnnotation - 30 examples found. These are the top rated real world Java examples of Class.isAnnotation extracted from open source projects. You can rate examples to help us improve the quality of examples.
 private static boolean arrayMemberEquals(
     Class<?> paramClass, Object paramObject1, Object paramObject2) {
   if (paramClass.isAnnotation()) {
     return annotationArrayMemberEquals((Annotation[]) paramObject1, (Annotation[]) paramObject2);
   }
   if (paramClass.equals(Byte.TYPE)) {
     return Arrays.equals((byte[]) paramObject1, (byte[]) paramObject2);
   }
   if (paramClass.equals(Short.TYPE)) {
     return Arrays.equals((short[]) paramObject1, (short[]) paramObject2);
   }
   if (paramClass.equals(Integer.TYPE)) {
     return Arrays.equals((int[]) paramObject1, (int[]) paramObject2);
   }
   if (paramClass.equals(Character.TYPE)) {
     return Arrays.equals((char[]) paramObject1, (char[]) paramObject2);
   }
   if (paramClass.equals(Long.TYPE)) {
     return Arrays.equals((long[]) paramObject1, (long[]) paramObject2);
   }
   if (paramClass.equals(Float.TYPE)) {
     return Arrays.equals((float[]) paramObject1, (float[]) paramObject2);
   }
   if (paramClass.equals(Double.TYPE)) {
     return Arrays.equals((double[]) paramObject1, (double[]) paramObject2);
   }
   if (paramClass.equals(Boolean.TYPE)) {
     return Arrays.equals((boolean[]) paramObject1, (boolean[]) paramObject2);
   }
   return Arrays.equals((Object[]) paramObject1, (Object[]) paramObject2);
 }
Example #2
0
  /**
   * Create a new AnnotationImpl.
   *
   * @param className className
   * @param cl classloader
   * @param parameterTypes parameterTypes
   * @param memberName memberName
   * @param onMethod onMethod
   * @param onField onField
   * @param annotationClass annotationClass
   */
  @SuppressWarnings("unchecked")
  public AnnotationImpl(
      String className,
      ClassLoader cl,
      List<String> parameterTypes,
      String memberName,
      boolean onMethod,
      boolean onField,
      Class<?> annotationClass) {
    super();
    this.className = className;
    this.cl = cl;
    if (parameterTypes != null) {
      this.parameterTypes = new ArrayList<String>(parameterTypes.size());
      this.parameterTypes.addAll(parameterTypes);
    } else {
      this.parameterTypes = new ArrayList<String>(0);
    }

    this.memberName = memberName;
    this.onMethod = onMethod;
    this.onField = onField;
    if (annotationClass.isAnnotation()) {
      this.annotationClass = (Class<? extends java.lang.annotation.Annotation>) annotationClass;
    } else {
      throw MESSAGES.notAnAnnotation(annotationClass);
    }
  }
  @SuppressWarnings("unchecked")
  private void parseConstraintDefinitions(
      List<ConstraintDefinitionType> constraintDefinitionList, String defaultPackage) {
    for (ConstraintDefinitionType constraintDefinition : constraintDefinitionList) {
      String annotationClassName = constraintDefinition.getAnnotation();

      Class<?> clazz = getClass(annotationClassName, defaultPackage);
      if (!clazz.isAnnotation()) {
        throw log.getIsNotAnAnnotationException(annotationClassName);
      }
      Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) clazz;

      ValidatedByType validatedByType = constraintDefinition.getValidatedBy();
      List<Class<? extends ConstraintValidator<? extends Annotation, ?>>>
          constraintValidatorClasses = newArrayList();
      if (validatedByType.getIncludeExistingValidators() != null
          && validatedByType.getIncludeExistingValidators()) {
        constraintValidatorClasses.addAll(findConstraintValidatorClasses(annotationClass));
      }
      for (String validatorClassName : validatedByType.getValue()) {
        Class<? extends ConstraintValidator<?, ?>> validatorClass;
        validatorClass =
            (Class<? extends ConstraintValidator<?, ?>>)
                ReflectionHelper.loadClass(validatorClassName, this.getClass());

        if (!ConstraintValidator.class.isAssignableFrom(validatorClass)) {
          throw log.getIsNotAConstraintValidatorClassException(validatorClass);
        }

        constraintValidatorClasses.add(validatorClass);
      }
      constraintHelper.addConstraintValidatorDefinition(
          annotationClass, constraintValidatorClasses);
    }
  }
  @Override
  protected void doParse(
      final Element element,
      final ParserContext parserContext,
      final BeanDefinitionBuilder builder) {
    String serviceRef = element.getAttribute("service-ref");
    builder.addConstructorArgValue(":" + serviceRef);
    builder.addConstructorArgReference(serviceRef);
    String marker = element.getAttribute("marker");
    if (StringUtils.hasLength(marker)) {
      Class<?> theClass =
          ClassUtils.resolveClassName(marker, Thread.currentThread().getContextClassLoader());
      if (!theClass.isAnnotation()) {
        throw new ConfigurationException(
            String.format("The class '%s' is not an annotation", marker));
      }
      builder.addPropertyValue("markerAnnotation", theClass);
    }

    // Register the post processor if there is not already one in this context
    String beanName = NamespaceBeanFactoryPostProcessor.class.getName();
    if (!parserContext.getRegistry().containsBeanDefinition(beanName)) {
      BeanDefinitionBuilder namespacePostProcessor =
          BeanDefinitionBuilder.genericBeanDefinition(NamespaceBeanFactoryPostProcessor.class);
      parserContext.registerBeanComponent(
          new BeanComponentDefinition(namespacePostProcessor.getBeanDefinition(), beanName));
    }
  }
  // this GwtCreateHandler has been introduced to make possible the
  // instanciation of abstract classes
  // that gwt-test-utils doesn't patch right now
  public Object create(Class<?> classLiteral) throws Exception {
    if (classLiteral.isAnnotation()
        || classLiteral.isArray()
        || classLiteral.isEnum()
        || classLiteral.isInterface()
        || !Modifier.isAbstract(classLiteral.getModifiers())) {
      return null;
    }

    Class<?> newClass = cache.get(classLiteral);

    if (newClass != null) {
      return newClass.newInstance();
    }

    CtClass ctClass = GwtClassPool.getCtClass(classLiteral);
    CtClass subClass = GwtClassPool.get().makeClass(classLiteral.getCanonicalName() + "SubClass");

    subClass.setSuperclass(ctClass);

    for (CtMethod m : ctClass.getDeclaredMethods()) {
      if (javassist.Modifier.isAbstract(m.getModifiers())) {
        CtMethod copy = new CtMethod(m, subClass, null);
        subClass.addMethod(copy);
      }
    }

    GwtPatcherUtils.patch(subClass, null);

    newClass = subClass.toClass(GwtClassLoader.get(), null);
    cache.put(classLiteral, newClass);

    return newClass.newInstance();
  }
Example #6
0
  // This method is part of the javax.lang.model API, do not use this in javac code.
  public <A extends Annotation> A getAnnotation(Class<A> annoType) {

    if (!annoType.isAnnotation())
      throw new IllegalArgumentException("Not an annotation type: " + annoType);

    Attribute.Compound c = getAttribute(annoType);
    return c == null ? null : AnnotationProxyMaker.generateAnnotation(c, annoType);
  }