Package javax.lang.model.element

Examples of javax.lang.model.element.AnnotationValue


  @Override
  public void validate(ProcessingEnvironment procEnv,
      RoundEnvironment roundEnv, TypeElement annotationType,
      AnnotationMirror annotation, ExecutableElement annotationMember,
      Element e, Object value) {
    AnnotationValue expectedValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation, "expectedValue");

    if (!expectedValue.getValue().equals(value)) {
      procEnv.getMessager().printMessage(
          Diagnostic.Kind.ERROR,
          (String) AnnotationProcessingUtils
              .getAnnotationElementValue(procEnv, annotation,
                  "errorMessage").getValue(), e, annotation,
View Full Code Here


  @Override
  public void validate(ProcessingEnvironment procEnv,
      RoundEnvironment roundEnv, TypeElement annotationType,
      AnnotationMirror annotation, ExecutableElement annotationMember,
      Element e, Object value) {
    AnnotationValue referencedAnnotationClassValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation,
            "referencedAnnotationClass");
    AnnotationValue referencedAnnotationMemberValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation,
            "referencedAnnotationMember");
    AnnotationValue nullableValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation, "nullable");
    AnnotationValue scopeValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation, "scope");

    DeclaredType referencedAnnotationClass = (DeclaredType) referencedAnnotationClassValue
        .getValue();
    TypeElement referencedAnnotationTypeElement = (TypeElement) referencedAnnotationClass
        .asElement();
    ConstraintScope scope = ConstraintScope.valueOf(scopeValue.getValue()
        .toString());
    Boolean nullable = Boolean.valueOf(nullableValue.getValue().toString());
    Map<Element, Set<Element>> elements = new HashMap<Element, Set<Element>>();

    switch (scope) {
    case GLOBAL:
      elements.put(e, (Set<Element>) roundEnv
          .getElementsAnnotatedWith(referencedAnnotationTypeElement));
      break;
    case CLASS:
      switch (e.getKind()) {
      case CONSTRUCTOR:
      case FIELD:
      case METHOD:
        elements.put(e, new HashSet<Element>());

        for (Element classMemberElement : procEnv.getElementUtils()
            .getAllMembers((TypeElement) e.getEnclosingElement())) {
          if (AnnotationProcessingUtils
              .findAnnotationMirror(procEnv, classMemberElement,
                  referencedAnnotationTypeElement) != null) {
            elements.get(e).add(classMemberElement);
          }
        }

        break;
      case ENUM:
      case INTERFACE:
      case CLASS:
        elements.put(e, new HashSet<Element>());

        for (Element classMemberElement : procEnv.getElementUtils()
            .getAllMembers((TypeElement) e)) {
          if (AnnotationProcessingUtils
              .findAnnotationMirror(procEnv, classMemberElement,
                  referencedAnnotationTypeElement) != null) {
            elements.get(e).add(classMemberElement);
          }
        }

        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
        assert (referencedAnnotationMirror != null);

        AnnotationValue referencedAnnotationValue = AnnotationProcessingUtils
            .getAnnotationElementValue(procEnv,
                referencedAnnotationMirror,
                referencedAnnotationMemberValue.getValue()
                    .toString());

        if (referencedAnnotationValue != null) {
          memberName = referencedAnnotationValue.getValue();
        }

        if (memberName == null) {
          procEnv.getMessager().printMessage(
              Diagnostic.Kind.ERROR,
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public void validate(ProcessingEnvironment procEnv,
      RoundEnvironment roundEnv, TypeElement annotationType,
      AnnotationMirror annotation, ExecutableElement e) {
    AnnotationValue expectedExceptionTypes = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation,
            "expectedExceptions");
    AnnotationValue strictValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation, "strict");
    Boolean strict = (Boolean) strictValue.getValue();

    if (!matches(procEnv, strict, e.getThrownTypes(),
        getTypeMirrors((List<AnnotationValue>) expectedExceptionTypes
            .getValue()))) {
      procEnv.getMessager().printMessage(
View Full Code Here

  @Override
  public void validate(ProcessingEnvironment procEnv,
      RoundEnvironment roundEnv, TypeElement annotationType,
      AnnotationMirror annotation, ExecutableElement e) {
    AnnotationValue expectedReturnType = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation,
            "expectedReturnType");
    AnnotationValue strictValue = AnnotationProcessingUtils
        .getAnnotationElementValue(procEnv, annotation, "strict");
    Boolean strict = (Boolean) strictValue.getValue();

    if (!matches(procEnv, strict, e.getReturnType(),
        (TypeMirror) expectedReturnType.getValue())) {
      procEnv.getMessager().printMessage(
          Diagnostic.Kind.ERROR,
View Full Code Here

       
        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");
       
        // if there is no annotation parameter value, this method handles events from the templated widget itself: nothing more to check.
        // if the method is also annotated with @SinkNative, the values refer to template elements and we can't (easily) check them
        if (eventHandlerAnnotationValue != null && !hasSinkNative) {
          @SuppressWarnings("unchecked")
          List<AnnotationValue> eventHandlerAnnotationValues = (List<AnnotationValue>) eventHandlerAnnotationValue.getValue();
          for (AnnotationValue av : eventHandlerAnnotationValues) {
            String referencedFieldName = (String) av.getValue();
            Element referencedField = getField(enclosingClassElement, referencedFieldName);
            if (referencedField == null || !types.isAssignable(referencedField.asType(), gwtWidgetType)) {
              processingEnv.getMessager().printMessage(
View Full Code Here

   *
   * @param target a class that bears the {@code Templated} annotation.
   */
  private String getReferencedTemplate(Element target) {
    String templateRef = "";
    AnnotationValue paramValue = getAnnotationParamValueWithoutDefaults(target, TypeNames.TEMPLATED, "value");
    if (paramValue != null) {
      templateRef = paramValue.getValue().toString();
    }
    if (templateRef.equals("")) {
      templateRef = target.getSimpleName() + ".html";
    }
    return templateRef;
View Full Code Here

                    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() )
                    {
                        AnnotationValue typeValue = getAnnotationValue(annotation, "type");

                        if (typeValue != null)
                        {
                            _typeMap.put(packageName + "." + className, (String) typeValue.getValue());
                            processingEnv.getMessager()
                                    .printMessage(Diagnostic.Kind.NOTE,
                                                  "looking for " + packageName + "." + className);
                            _categoryMap.put(packageName + "." + className, getCategory((TypeElement) e));
View Full Code Here

   *         such value exists within the given annotation mirror or such a
   *         value exists but is not an array-typed one.
   */
  public List<? extends AnnotationValue> getAnnotationArrayValue(AnnotationMirror annotationMirror, String name) {

    AnnotationValue annotationValue = getAnnotationValue( annotationMirror, name );

    if ( annotationValue == null ) {
      return Collections.<AnnotationValue>emptyList();
    }

    List<? extends AnnotationValue> theValue = annotationValue.accept(
        new SimpleAnnotationValueVisitor6<List<? extends AnnotationValue>, Void>() {

          @Override
          public List<? extends AnnotationValue> visitArray(List<? extends AnnotationValue> values, Void p) {
            return values;
View Full Code Here

    return constraintMetaAnnotation;
  }

  private List<? extends AnnotationValue> getValidatorClassesFromConstraintMetaAnnotation(AnnotationMirror constraintMetaAnnotation) {

    AnnotationValue validatedBy = annotationApiHelper.getAnnotationValue( constraintMetaAnnotation, "validatedBy" );

    return validatedBy.accept(
        new SimpleAnnotationValueVisitor6<List<? extends AnnotationValue>, Void>() {

          @Override
          public List<? extends AnnotationValue> visitArray(List<? extends AnnotationValue> values, Void p) {
            return values;
View Full Code Here

  private ImmutableMap<String, AnnotationValue> getDefaultValues(TypeElement annotationElement) {
    ImmutableMap.Builder<String, AnnotationValue> defaultValues = ImmutableMap.builder();
    for (ExecutableElement member :
        ElementFilter.methodsIn(annotationElement.getEnclosedElements())) {
      String name = member.getSimpleName().toString();
      AnnotationValue defaultValue = member.getDefaultValue();
      if (defaultValue != null) {
        defaultValues.put(name, defaultValue);
      }
    }
    return defaultValues.build();
View Full Code Here

TOP

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

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.