Examples of TypeMirror


Examples of javax.lang.model.type.TypeMirror

    }
  }

  public static String extractClosestRealTypeAsString(TypeMirror type, Context context) {
    if ( type instanceof TypeVariable ) {
      final TypeMirror compositeUpperBound = ( ( TypeVariable ) type ).getUpperBound();
      final Types types = context.getProcessingEnvironment().getTypeUtils();
      final List<? extends TypeMirror> upperBounds = types.directSupertypes( compositeUpperBound );
      if ( upperBounds.size() == 0 ) {
        return compositeUpperBound.toString();
      }
      else {
        //take the first one
        return extractClosestRealTypeAsString( upperBounds.get( 0 ), context );
      }
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

    assert parameterName != null;

    String targetEntityName = null;
    Object parameterValue = TypeUtils.getAnnotationValue( mirror, parameterName );
    if ( parameterValue != null ) {
      TypeMirror parameterType = ( TypeMirror ) parameterValue;
      if ( !parameterType.getKind().equals( TypeKind.VOID ) ) {
        targetEntityName = parameterType.toString();
      }
    }
    return targetEntityName;
  }
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

    if ( targetEntity != null ) {
      return targetEntity;
    }
    final List<? extends TypeMirror> mirrors = declaredType.getTypeArguments();
    if ( mirrors.size() == 1 ) {
      final TypeMirror type = mirrors.get( 0 );
      return TypeUtils.extractClosestRealTypeAsString( type, context );
    }
    else if ( mirrors.size() == 2 ) {
      return TypeUtils.extractClosestRealTypeAsString( mirrors.get( 1 ), context );
    }
View Full Code Here

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

Examples of javax.lang.model.type.TypeMirror

        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

Examples of javax.lang.model.type.TypeMirror

    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

Examples of javax.lang.model.type.TypeMirror

            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

Examples of javax.lang.model.type.TypeMirror

      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

Examples of javax.lang.model.type.TypeMirror

    }
  }

  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

Examples of javax.lang.model.type.TypeMirror

  }

  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
TOP
Copyright © 2018 www.massapi.com. 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.