Package javax.lang.model.element

Examples of javax.lang.model.element.AnnotationMirror


        }

        break;

      case ANNOTATION_TYPE:
        AnnotationMirror stereotypeAnnotationMirror = AnnotationProcessingUtils
            .findAnnotationMirror(procEnv, e,
                "javax.enterprise.inject.Stereotype");

        if (stereotypeAnnotationMirror == null) {
          procEnv.getMessager()
              .printMessage(
                  Diagnostic.Kind.ERROR,
                  "Annotation targets other than stereotyped annotation, enum, interface, class, constructor, field and methods are not supported",
                  e, annotation);
          break;
        }

        Set<Element> stereotypeAnnotatedElements = (Set<Element>) roundEnv
            .getElementsAnnotatedWith((TypeElement) e);

        for (Element stereotypeAnnotatedElement : stereotypeAnnotatedElements) {

          // Always add the element to the map, otherwise it won't be
          // validated
          elements.put(stereotypeAnnotatedElement,
              new HashSet<Element>());

          switch (stereotypeAnnotatedElement.getKind()) {
          case CONSTRUCTOR:
          case FIELD:
          case METHOD:
            for (Element classMemberElement : procEnv
                .getElementUtils()
                .getAllMembers(
                    (TypeElement) stereotypeAnnotatedElement
                        .getEnclosingElement())) {
              if (AnnotationProcessingUtils
                  .findAnnotationMirror(procEnv,
                      classMemberElement, annotationType) != null) {
                elements.get(stereotypeAnnotatedElement).add(
                    classMemberElement);
              }
            }

            break;
          case INTERFACE:
          case CLASS:
          case ENUM:
            for (Element classMemberElement : procEnv
                .getElementUtils()
                .getAllMembers(
                    (TypeElement) stereotypeAnnotatedElement)) {
              if (AnnotationProcessingUtils
                  .findAnnotationMirror(procEnv,
                      classMemberElement, annotationType) != null) {
                elements.get(stereotypeAnnotatedElement).add(
                    classMemberElement);
              }
            }

            break;
          default:
            procEnv.getMessager().printMessage(
                Diagnostic.Kind.ERROR,
                "Feature not yet implemented",
                stereotypeAnnotatedElement, annotation);
            break;
          }
        }

        break;
      default:
        procEnv.getMessager()
            .printMessage(
                Diagnostic.Kind.ERROR,
                "Annotation targets other than stereotyped annotation, enum, interface, class, constructor, field and methods are not supported",
                e, annotation);
        break;
      }
      break;
    case ELEMENT:
      elements.put(e, new HashSet<Element>(Arrays.asList(e)));
      break;
    }

    boolean unique;

    for (Map.Entry<Element, Set<Element>> elementEntry : elements
        .entrySet()) {
      unique = true;

      for (Element lookupElement : elementEntry.getValue()) {
        AnnotationMirror referencedAnnotationMirror = AnnotationProcessingUtils
            .findAnnotationMirror(lookupElement, annotationType);

        if (!e.equals(lookupElement)) {
          if (value
              .equals(AnnotationProcessingUtils
View Full Code Here


          }
        }

        break;
      case ANNOTATION_TYPE:
        AnnotationMirror stereotypeAnnotationMirror = AnnotationProcessingUtils
            .findAnnotationMirror(procEnv, e,
                "javax.enterprise.inject.Stereotype");

        if (stereotypeAnnotationMirror == null) {
          procEnv.getMessager()
              .printMessage(
                  Diagnostic.Kind.ERROR,
                  "Annotation targets other than stereotyped annotation, enum, interface, class, constructor, field and methods are not supported",
                  e, annotation);
          break;
        }

        Set<Element> stereotypeAnnotatedElements = (Set<Element>) roundEnv
            .getElementsAnnotatedWith((TypeElement) e);

        for (Element stereotypeAnnotatedElement : stereotypeAnnotatedElements) {

          // Always add the element to the map, otherwise it won't be
          // validated
          elements.put(stereotypeAnnotatedElement,
              new HashSet<Element>());

          switch (stereotypeAnnotatedElement.getKind()) {
          case CONSTRUCTOR:
          case FIELD:
          case METHOD:
            for (Element classMemberElement : procEnv
                .getElementUtils()
                .getAllMembers(
                    (TypeElement) stereotypeAnnotatedElement
                        .getEnclosingElement())) {
              if (AnnotationProcessingUtils.findAnnotationMirror(
                  procEnv, classMemberElement,
                  referencedAnnotationTypeElement) != null) {
                elements.get(stereotypeAnnotatedElement).add(
                    classMemberElement);
              }
            }

            break;
          case INTERFACE:
          case CLASS:
            // Maybe add here support for subtype checking, so that
            // abstract classes or interfaces must not explicitly
            // fullfill a
            // referencing constraint, but also a subtype can do
          case ENUM:
            for (Element classMemberElement : procEnv
                .getElementUtils()
                .getAllMembers(
                    (TypeElement) stereotypeAnnotatedElement)) {
              if (AnnotationProcessingUtils.findAnnotationMirror(
                  procEnv, classMemberElement,
                  referencedAnnotationTypeElement) != null) {
                elements.get(stereotypeAnnotatedElement).add(
                    classMemberElement);
              }
            }

            break;
          default:
            procEnv.getMessager().printMessage(
                Diagnostic.Kind.ERROR,
                "Feature not yet implemented",
                stereotypeAnnotatedElement, annotation);
            break;
          }
        }

        break;
      default:
        procEnv.getMessager()
            .printMessage(
                Diagnostic.Kind.ERROR,
                "Annotation targets other than stereotyped annotation, enum, interface, class, constructor, field and methods are not supported",
                e, annotation);
        break;
      }
      break;
    case ELEMENT:
      if (AnnotationProcessingUtils.findAnnotationMirror(procEnv, e,
          referencedAnnotationTypeElement) != null) {
        elements.put(e, new HashSet<Element>(Arrays.asList(e)));
      }

      break;
    }

    OUTER: for (Map.Entry<Element, Set<Element>> elementEntry : elements
        .entrySet()) {
      for (Element lookupElement : elementEntry.getValue()) {
        AnnotationMirror referencedAnnotationMirror = AnnotationProcessingUtils
            .findAnnotationMirror(procEnv, lookupElement,
                referencedAnnotationTypeElement);
        Object memberName = null;

        // Should never be null here
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public void validate(ProcessingEnvironment procEnv,
      RoundEnvironment roundEnv, TypeElement annotationType,
      AnnotationMirror annotation, Element e) {
    AnnotationMirror steretypeAnnotation = AnnotationProcessingUtils
        .findAnnotationMirror(procEnv, e,
            "javax.enterprise.inject.Stereotype");

    if (!(e instanceof ExecutableElement) && steretypeAnnotation == null) {
      procEnv.getMessager()
View Full Code Here

        if (((ExecutableElement) target).getReturnType().getKind() != TypeKind.VOID) {
          processingEnv.getMessager().printMessage(
                  Kind.ERROR, "@EventHandler methods must return void", target);
        }
       
        AnnotationMirror eventHandlerAnnotation = getAnnotation(target, TypeNames.EVENT_HANDLER);
        TypeElement enclosingClassElement = (TypeElement) target.getEnclosingElement();
        boolean hasSinkNative = hasAnnotation(target, TypeNames.SINK_NATIVE);
       
        AnnotationValue eventHandlerAnnotationValue = getAnnotationParamValueWithoutDefaults(target, TypeNames.EVENT_HANDLER, "value");
       
View Full Code Here

                if (e.getKind().equals(ElementKind.INTERFACE) || e.getKind().equals(ElementKind.CLASS))
                {
                    PackageElement packageElement = elementUtils.getPackageOf(e);
                    String packageName = packageElement.getQualifiedName().toString();
                    String className = e.getSimpleName().toString();
                    AnnotationMirror annotation = getAnnotation(e, annotationElement);

                    AnnotationValue registerValue = getAnnotationValue(annotation, "register");

                    if(registerValue == null || (Boolean) registerValue.getValue() )
                    {
View Full Code Here

      DeclaredType constraintAnnotationType, TypeMirror type) {

    Set<TypeMirror> theValue = CollectionHelper.newHashSet();

    //the Constraint meta-annotation at the type declaration, e.g. "@Constraint(validatedBy = CheckCaseValidator.class)"
    AnnotationMirror constraintMetaAnnotation = getConstraintMetaAnnotation( constraintAnnotationType );

    //the validator classes, e.g. [CheckCaseValidator.class]
    List<? extends AnnotationValue> validatorClassReferences = getValidatorClassesFromConstraintMetaAnnotation(
        constraintMetaAnnotation
    );
View Full Code Here

   */
  private AnnotationMirror getConstraintMetaAnnotation(DeclaredType annotationType) {

    List<? extends AnnotationMirror> annotationMirrors = annotationType.asElement().getAnnotationMirrors();

    AnnotationMirror constraintMetaAnnotation = annotationApiHelper.getMirror(
        annotationMirrors, Constraint.class
    );

    if ( constraintMetaAnnotation == null ) {
      throw new IllegalArgumentException( "Given type " + annotationType + " isn't a constraint annotation type." );
View Full Code Here

  }

  @Override
  public Set<ConstraintCheckError> checkAnnotationType(TypeElement element, AnnotationMirror annotation) {

    AnnotationMirror constraintMirror = annotationApiHelper.getMirror(
        element.getAnnotationMirrors(), Constraint.class
    );
    boolean atLeastOneValidatorGiven = !annotationApiHelper.getAnnotationArrayValue(
        constraintMirror, "validatedBy"
    ).isEmpty();
View Full Code Here

  }

  private Set<TypeMirror> determineSupportedTypes(DeclaredType constraintAnnotationType) {

    //the Constraint meta-annotation at the type declaration, e.g. "@Constraint(validatedBy = CheckCaseValidator.class)"
    AnnotationMirror constraintMetaAnnotation = getConstraintMetaAnnotation( constraintAnnotationType );

    //the validator classes, e.g. [CheckCaseValidator.class]
    List<? extends AnnotationValue> validatorClassReferences = getValidatorClassesFromConstraintMetaAnnotation(
        constraintMetaAnnotation
    );
View Full Code Here

   */
  private AnnotationMirror getConstraintMetaAnnotation(DeclaredType annotationType) {

    List<? extends AnnotationMirror> annotationMirrors = annotationType.asElement().getAnnotationMirrors();

    AnnotationMirror constraintMetaAnnotation = annotationApiHelper.getMirror(
        annotationMirrors, BeanValidationTypes.CONSTRAINT
    );

    if ( constraintMetaAnnotation == null ) {
      throw new IllegalArgumentException( "Given type " + annotationType + " isn't a constraint annotation type." );
View Full Code Here

TOP

Related Classes of javax.lang.model.element.AnnotationMirror

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.