Search in sources :

Example 16 with TypeKind

use of javax.lang.model.type.TypeKind in project immutables by immutables.

the class Imports method collectBuiltins.

private void collectBuiltins(Map<String, TypeMirror> collected) {
    for (TypeKind kind : TypeKind.values()) {
        if (kind.isPrimitive()) {
            TypeElement boxedClass = types.boxedClass(types.getPrimitiveType(kind));
            collected.put(boxedClass.getSimpleName().toString(), boxedClass.asType());
        }
    }
    TypeElement typeElement = elements.getTypeElement(String.class.getCanonicalName());
    collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
    typeElement = elements.getTypeElement(Templates.Invokable.class.getCanonicalName());
    collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypeKind(javax.lang.model.type.TypeKind) Templates(org.immutables.generator.Templates)

Example 17 with TypeKind

use of javax.lang.model.type.TypeKind in project androidannotations by androidannotations.

the class ValidatorHelper method returnTypeIsVoidOrBoolean.

public void returnTypeIsVoidOrBoolean(ExecutableElement executableElement, ElementValidation valid) {
    TypeMirror returnType = executableElement.getReturnType();
    TypeKind returnKind = returnType.getKind();
    if (returnKind != TypeKind.BOOLEAN && returnKind != TypeKind.VOID && !returnType.toString().equals(CanonicalNameConstants.BOOLEAN)) {
        valid.addError("%s can only be used on a method with a boolean or a void return type");
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeKind(javax.lang.model.type.TypeKind)

Example 18 with TypeKind

use of javax.lang.model.type.TypeKind in project realm-java by realm.

the class Utils method getGenericTypeForContainer.

// Note that, because subclassing subclasses of RealmObject is forbidden,
// there is no need to deal with constructs like:  <code>RealmResults&lt;? extends Foos&lt;</code>.
public static DeclaredType getGenericTypeForContainer(VariableElement field) {
    TypeMirror fieldType = field.asType();
    TypeKind kind = fieldType.getKind();
    if (kind != TypeKind.DECLARED) {
        return null;
    }
    List<? extends TypeMirror> args = ((DeclaredType) fieldType).getTypeArguments();
    if (args.size() <= 0) {
        return null;
    }
    fieldType = args.get(0);
    kind = fieldType.getKind();
    if (kind != TypeKind.DECLARED) {
        return null;
    }
    return (DeclaredType) fieldType;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeKind(javax.lang.model.type.TypeKind) DeclaredType(javax.lang.model.type.DeclaredType)

Example 19 with TypeKind

use of javax.lang.model.type.TypeKind in project spring-boot by spring-projects.

the class TypeUtils method getWrapperOrPrimitiveFor.

public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
    Class<?> candidate = getWrapperFor(typeMirror);
    if (candidate != null) {
        return this.env.getElementUtils().getTypeElement(candidate.getName()).asType();
    }
    TypeKind primitiveKind = getPrimitiveFor(typeMirror);
    if (primitiveKind != null) {
        return this.env.getTypeUtils().getPrimitiveType(primitiveKind);
    }
    return null;
}
Also used : TypeKind(javax.lang.model.type.TypeKind)

Example 20 with TypeKind

use of javax.lang.model.type.TypeKind in project lwjgl by LWJGL.

the class TypeInfo method getTypeInfos.

private static Collection<TypeInfo> getTypeInfos(TypeMap type_map, VariableElement param) {
    List<? extends AnnotationMirror> annotations = Utils.getSortedAnnotations(param.getAnnotationMirrors());
    GLvoid void_annotation = param.getAnnotation(GLvoid.class);
    Map<Class, TypeInfo> types = new HashMap<Class, TypeInfo>();
    Collection<TypeInfo> multityped_result = new ArrayList<TypeInfo>();
    boolean add_default_type = true;
    for (AnnotationMirror annotation : annotations) {
        NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
        if (native_type_annotation != null) {
            Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
            Signedness signedness = type_map.getSignednessFromType(annotation_type);
            Class inverse_type = type_map.getInverseType(annotation_type);
            String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
            if (inverse_type != null) {
                if (types.containsKey(inverse_type)) {
                    TypeInfo inverse_type_info = types.get(inverse_type);
                    String inverse_auto_type = inverse_type_info.getAutoType();
                    auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type : inverse_auto_type + " : " + auto_type;
                    auto_type = UNSIGNED_PARAMETER_NAME + " ? " + auto_type;
                    signedness = Signedness.BOTH;
                    types.remove(inverse_type);
                    multityped_result.remove(inverse_type_info);
                }
            }
            Class type;
            TypeKind kind;
            kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
            if (Utils.getNIOBufferType(param.asType()) != null) {
                type = getBufferTypeFromPrimitiveKind(kind, annotation);
            } else {
                type = getTypeFromPrimitiveKind(kind);
            }
            TypeInfo type_info = new TypeInfo(type, signedness, auto_type);
            types.put(annotation_type, type_info);
            multityped_result.add(type_info);
            add_default_type = false;
        }
    }
    if (add_default_type) {
        TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
        Collection<TypeInfo> result = new ArrayList<TypeInfo>();
        result.add(default_type_info);
        return result;
    } else {
        return multityped_result;
    }
}
Also used : TypeKind(javax.lang.model.type.TypeKind) AnnotationMirror(javax.lang.model.element.AnnotationMirror) GLvoid(org.lwjgl.util.generator.opengl.GLvoid)

Aggregations

TypeKind (javax.lang.model.type.TypeKind)24 TypeMirror (javax.lang.model.type.TypeMirror)8 TypeElement (javax.lang.model.element.TypeElement)6 VariableElement (javax.lang.model.element.VariableElement)4 DeclaredType (javax.lang.model.type.DeclaredType)4 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 PrimitiveType (javax.lang.model.type.PrimitiveType)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ClassName (com.squareup.javapoet.ClassName)1 JavaFile (com.squareup.javapoet.JavaFile)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 TypeSpec (com.squareup.javapoet.TypeSpec)1