Package javax.lang.model.element

Examples of javax.lang.model.element.AnnotationValue


  /**
   * Returns a string representation of the default value of the given annotation member, suitable
   * for inclusion in a Java source file as the initializer of a variable of the appropriate type.
   */
  String sourceForm(ExecutableElement memberMethod) {
    AnnotationValue defaultValue = memberMethod.getDefaultValue();
    TypeMirror type = memberMethod.getReturnType();
    StringBuilder sb = new StringBuilder();
    SourceFormVisitor visitor = new SourceFormVisitor(sb, memberMethod);
    visitor.visit(defaultValue);
    return sb.toString();
View Full Code Here


    public TypeKind getKind() {
      return getTypeMirror().getKind();
    }

    public String getDefaultValue() {
      AnnotationValue defaultValue = method.getDefaultValue();
      if (defaultValue == null) {
        return null;
      } else {
        return annotationDefaults.sourceForm(method);
      }
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

    Map<? extends ExecutableElement, ? extends AnnotationValue> valueIndex =
        providerAnnotation.getElementValues();
    log("annotation values: " + valueIndex);

    AnnotationValue value = valueIndex.values().iterator().next();
    return (DeclaredType) value.getValue();
  }
View Full Code Here

      Map<String, AnnotationValue> values =
          Mirrors.simplifyAnnotationValueMap(elements.getElementValuesWithDefaults(mirror));
      checkState(values.size() == 3);

      // className value is a string, so we can just call toString
      AnnotationValue classNameValue = values.get("className");
      String className = classNameValue.getValue().toString();
      if (!className.isEmpty() && !isValidIdentifier(className)) {
        messager.printMessage(ERROR,
            String.format("\"%s\" is not a valid Java identifier", className),
            element, mirror, classNameValue);
        return Optional.absent();
      }

      AnnotationValue extendingValue = checkNotNull(values.get("extending"));
      TypeElement extendingType = AnnotationValues.asType(extendingValue);
      if (extendingType == null) {
        messager.printMessage(ERROR, "Unable to find the type: "
            + extendingValue.getValue().toString(),
                element, mirror, extendingValue);
        return Optional.absent();
      } else if (!isValidSupertypeForClass(extendingType)) {
        messager.printMessage(ERROR,
            String.format("%s is not a valid supertype for a factory. "
                + "Supertypes must be non-final classes.",
                    extendingType.getQualifiedName()),
            element, mirror, extendingValue);
        return Optional.absent();
      }
      ImmutableList<ExecutableElement> noParameterConstructors =
          FluentIterable.from(ElementFilter.constructorsIn(extendingType.getEnclosedElements()))
              .filter(new Predicate<ExecutableElement>() {
                @Override public boolean apply(ExecutableElement constructor) {
                  return constructor.getParameters().isEmpty();
                }
              })
              .toList();
      if (noParameterConstructors.size() == 0) {
        messager.printMessage(ERROR,
            String.format("%s is not a valid supertype for a factory. "
                + "Factory supertypes must have a no-arg constructor.",
                    extendingType.getQualifiedName()),
            element, mirror, extendingValue);
        return Optional.absent();
      } else if (noParameterConstructors.size() > 1) {
        throw new IllegalStateException("Multiple constructors with no parameters??");
      }

      AnnotationValue implementingValue = checkNotNull(values.get("implementing"));
      ImmutableSet.Builder<TypeElement> builder = ImmutableSet.builder();
      for (AnnotationValue implementingTypeValue : AnnotationValues.asList(implementingValue)) {
        builder.add(AnnotationValues.asType(implementingTypeValue));
      }
      ImmutableSet<TypeElement> implementingTypes = builder.build();
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) {
      if (paramValue.getValue().toString().startsWith("#")) {
        // use simple name
      }
      else if (paramValue.getValue().toString().contains("#")) {
        String[] split = paramValue.getValue().toString().split("#");
        if (split != null && split.length > 0) {
          // use html part
          templateRef = split[0];
        }
      }
      else {
        templateRef = paramValue.getValue().toString();
      }
    }
    if (templateRef.equals("")) {
      templateRef = target.getSimpleName() + ".html";
    }
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) &&!types.isAssignable(referencedField.asType(), gwtElementType))) {
              processingEnv.getMessager().printMessage(
View Full Code Here

        // Process the values.
        Set<? extends ExecutableElement> keys = annotationMirror.getElementValues().keySet();
       
        for (ExecutableElement annotationElement : keys) {
            AnnotationValue annotationValue = annotationMirror.getElementValues().get(annotationElement);
            String attribute = annotationElement.getSimpleName().toString();
            Object attributeValue = annotationValue.accept(this, arg1);
            annotation.addAttribute(attribute, attributeValue);
        }

        return annotation;
    }
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

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.