Package javax.lang.model.type

Examples of javax.lang.model.type.TypeMirror


        String fqElementName = returnedElement.getQualifiedName().toString();
        String collection = COLLECTIONS.get( fqElementName );
        String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
        if ( collection != null ) {
          if ( TypeUtils.containsAnnotation( element, ElementCollection.class ) ) {
            TypeMirror collectionElementType = getCollectionElementType( declaredType, fqElementName );
            final TypeElement collectionElement = ( TypeElement ) context.getProcessingEnvironment()
                .getTypeUtils()
                .asElement( collectionElementType );
            this.parent.context.processElement(
                collectionElement,
View Full Code Here


        return null;
      }
    }

    private TypeMirror getCollectionElementType(DeclaredType t, String fqElementName) {
      TypeMirror collectionElementType;
      if ( Map.class.getCanonicalName().equals( fqElementName ) ) {
        collectionElementType = t.getTypeArguments().get( 1 );
      }
      else {
        collectionElementType = t.getTypeArguments().get( 0 );
View Full Code Here

    public AnnotationMetaAttribute visitExecutable(ExecutableType t, Element p) {
      String string = p.getSimpleName().toString();

      // TODO: implement proper property get/is/boolean detection
      if ( string.startsWith( "get" ) || string.startsWith( "is" ) ) {
        TypeMirror returnType = t.getReturnType();

        return returnType.accept( this, p );
      }
      else {
        return null;
      }
    }
View Full Code Here

            param.getValue());
       
        return false;
      }
     
      TypeMirror type = param.getValue().asType();
      if (!(type.getKind().isPrimitive() || ProcessorUtil.isString(type))) {
        messager.printMessage(
            ERROR,
            "Only primitive and string types supported",
            param.getValue());
       
View Full Code Here

      if (element.getKind() != ElementKind.METHOD) {
        continue;
      }

      ExecutableElement executableElement = (ExecutableElement)element;
      TypeMirror returnType = executableElement.getReturnType();
      if (returnType instanceof NoType && returnType.getKind() == TypeKind.VOID) {
        String error = String.format("void method cannot be annotated with %s", annotationType.getSimpleName());
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, error, element, getAnnotationMirror(element, annotationType));
      }
    }
  }
View Full Code Here

    }
  }

  private void checkPrimitiveTypeAnnotations(Set<? extends Element> elements, Diagnostic.Kind kind, TypeElement annotationType) {
    for (Element element : elements) {
      TypeMirror typeToCheck;
      switch (element.getKind()) {
      case FIELD:
      case PARAMETER:
      case LOCAL_VARIABLE:
        // checking variable type
        VariableElement variableElement = (VariableElement)element;
        typeToCheck = variableElement.asType();
        break;

      case METHOD:
        // checking return type
        ExecutableElement executableElement = (ExecutableElement)element;
        typeToCheck = executableElement.getReturnType();
        break;

      default:
        continue;
      }

      if (typeToCheck instanceof PrimitiveType && typeToCheck.getKind().isPrimitive()) {
        String error = String.format("%s with a primitive type %s be annotated with %s", element.getKind().toString().replace('_', ' ').toLowerCase(), kind == Diagnostic.Kind.ERROR ? "cannot" : "should not", annotationType.getSimpleName());
        processingEnv.getMessager().printMessage(kind, error, element, getAnnotationMirror(element, annotationType));
      }
    }
  }
View Full Code Here

  }

  private Set<ConstraintCheckError> checkAnnotationValue(TypeElement element, AnnotationMirror annotation) {
    Set<ConstraintCheckError> errors = CollectionHelper.newHashSet();
    AnnotationValue value = annotationApiHelper.getAnnotationValue( annotation, "value" );
    TypeMirror valueType = (TypeMirror) value.getValue();
    TypeElement valueElement = (TypeElement) typeUtils.asElement( valueType );

    if ( valueElement.getKind().isInterface() || valueElement.getModifiers().contains( Modifier.ABSTRACT ) ) {
      errors.add(
          new ConstraintCheckError(
              element,
              annotation,
              "GROUP_SEQUENCE_PROVIDER_ANNOTATION_VALUE_MUST_BE_AN_IMPLEMENTATION_CLASS"
          )
      );

    }
    else {
      //the TypeElement hosting the annotation is a concrete implementation of the DefaultGroupSequenceProvider
      //interface. In that case, we need to check that it has a public default constructor.
      if ( !hasPublicDefaultConstructor( valueElement ) ) {
        errors.add(
            new ConstraintCheckError(
                element,
                annotation,
                "GROUP_SEQUENCE_PROVIDER_ANNOTATION_VALUE_CLASS_MUST_HAVE_DEFAULT_CONSTRUCTOR",
                valueType
            )
        );
      }
    }

    TypeMirror genericProviderType = retrieveGenericProviderType( valueType );
    if ( !typeUtils.isSubtype( element.asType(), genericProviderType ) ) {
      errors.add(
          new ConstraintCheckError(
              element,
              annotation,
View Full Code Here

    return typeMirror.accept(
        new SimpleTypeVisitor6<TypeMirror, Void>() {

          @Override
          public TypeMirror visitDeclared(DeclaredType declaredType, Void aVoid) {
            TypeMirror eraseType = typeUtils.erasure( declaredType );
            if ( typeUtils.isSameType( eraseType, defaultGroupSequenceProviderType ) ) {
              List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
              if ( !typeArguments.isEmpty() ) {
                return typeArguments.get( 0 );
              }
              return null;
            }

            List<? extends TypeMirror> superTypes = typeUtils.directSupertypes( declaredType );
            for ( TypeMirror superType : superTypes ) {
              TypeMirror genericProviderType = superType.accept( this, aVoid );
              if ( genericProviderType != null ) {
                return genericProviderType;
              }
            }
            return null;
View Full Code Here

        constraintMetaAnnotation
    );

    for ( AnnotationValue oneValidatorClassReference : validatorClassReferences ) {

      TypeMirror supportedType = getSupportedType( oneValidatorClassReference );

      if ( typeUtils.isAssignable( type, supportedType ) ) {
        theValue.add( supportedType );
      }
    }
View Full Code Here

    return annotationApiHelper.keepLowestTypePerHierarchy( theValue );
  }

  private TypeMirror getSupportedType(AnnotationValue oneValidatorClassReference) {

    TypeMirror validatorType = oneValidatorClassReference.accept(
        new SimpleAnnotationValueVisitor6<TypeMirror, Void>() {

          @Override
          public TypeMirror visitType(TypeMirror t, Void p) {
            return t;
          }
        }, null
    );

    // contains the bindings of the type parameters from the implemented
    // ConstraintValidator interface, e.g. "ConstraintValidator<CheckCase, String>"
    TypeMirror constraintValidatorImplementation = getConstraintValidatorSuperType( validatorType );

    return constraintValidatorImplementation.accept(
        new TypeKindVisitor6<TypeMirror, Void>() {

          @Override
          public TypeMirror visitDeclared(DeclaredType constraintValidatorImplementation, Void p) {
            // 2nd type parameter contains the data type supported by current validator class, e.g. "String"
            return constraintValidatorImplementation.getTypeArguments().get( 1 );
          }

        }, null
    );
  }
View Full Code Here

TOP

Related Classes of javax.lang.model.type.TypeMirror

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.