Package javax.lang.model.element

Examples of javax.lang.model.element.AnnotationValue


   *         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

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

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

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

    ConstraintScope scope = ConstraintScope.valueOf(scopeValue.getValue()
        .toString());
    Map<Element, Set<Element>> elements = new HashMap<Element, Set<Element>>();

    switch (scope) {
    case GLOBAL:
View Full Code Here

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

    if (!expectedValue.getValue().equals(value)) {
      procEnv.getMessager().printMessage(
          Diagnostic.Kind.ERROR,
          (String) AnnotationProcessingUtil
              .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 = AnnotationProcessingUtil
        .getAnnotationElementValue(procEnv, annotation,
            "referencedAnnotationClass");
    AnnotationValue referencedAnnotationMemberValue = AnnotationProcessingUtil
        .getAnnotationElementValue(procEnv, annotation,
            "referencedAnnotationMember");
    AnnotationValue nullableValue = AnnotationProcessingUtil
        .getAnnotationElementValue(procEnv, annotation, "nullable");
    AnnotationValue scopeValue = AnnotationProcessingUtil
        .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 (AnnotationProcessingUtil
              .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 (AnnotationProcessingUtil
              .findAnnotationMirror(procEnv, classMemberElement,
                  referencedAnnotationTypeElement) != null) {
            elements.get(e).add(classMemberElement);
          }
        }

        break;
      case ANNOTATION_TYPE:
        AnnotationMirror stereotypeAnnotationMirror = AnnotationProcessingUtil
            .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 (AnnotationProcessingUtil.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 (AnnotationProcessingUtil.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 (AnnotationProcessingUtil.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 = AnnotationProcessingUtil
            .findAnnotationMirror(procEnv, lookupElement,
                referencedAnnotationTypeElement);
        Object memberName = null;

        // Should never be null here
        assert (referencedAnnotationMirror != null);

        AnnotationValue referencedAnnotationValue = AnnotationProcessingUtil
            .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 = AnnotationProcessingUtil
        .getAnnotationElementValue(procEnv, annotation,
            "expectedExceptions");
    AnnotationValue strictValue = AnnotationProcessingUtil
        .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 = AnnotationProcessingUtil
        .getAnnotationElementValue(procEnv, annotation,
            "expectedReturnType");
    AnnotationValue strictValue = AnnotationProcessingUtil
        .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

        //Extract required information
        final TypeElement classElement = (TypeElement) element;

        final String annotationName = ClientAPIModule.getWorkbenchEditorClass().getName();
        AnnotationValue action = null;

        String identifier = null;
        Integer priority = 0;
        List<String> associatedResources = null;
        Integer preferredHeight = null;
View Full Code Here

            for ( final AnnotationMirror am : o.getAnnotationMirrors() ) {

                if ( className.equals( am.getAnnotationType().toString() ) ) {
                    for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet() ) {
                        if ( annotationName.equals( entry.getKey().getSimpleName().toString() ) ) {
                            AnnotationValue value = entry.getValue();
                            identifierValue = value.getValue().toString();
                        }
                    }
                }
            }
            return identifierValue;
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.