Search in sources :

Example 1 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project buck by facebook.

the class TreeBackedTypesTest method testIsNotSameTypeDifferentTypes.

@Test
public void testIsNotSameTypeDifferentTypes() throws IOException {
    initCompiler();
    PrimitiveType intType = types.getPrimitiveType(TypeKind.INT);
    ArrayType intArrayType = types.getArrayType(intType);
    assertNotSameType(intType, intArrayType);
}
Also used : ArrayType(javax.lang.model.type.ArrayType) PrimitiveType(javax.lang.model.type.PrimitiveType) Test(org.junit.Test)

Example 2 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project buck by facebook.

the class TreeBackedTypesTest method testIsSameTypePrimitiveType.

@Test
public void testIsSameTypePrimitiveType() throws IOException {
    initCompiler();
    for (TypeKind typeKind : TypeKind.values()) {
        if (typeKind.isPrimitive()) {
            PrimitiveType primitiveType = types.getPrimitiveType(typeKind);
            PrimitiveType primitiveType2 = types.getPrimitiveType(typeKind);
            assertSameType(primitiveType, primitiveType2);
        }
    }
}
Also used : TypeKind(javax.lang.model.type.TypeKind) PrimitiveType(javax.lang.model.type.PrimitiveType) Test(org.junit.Test)

Example 3 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project j2objc by google.

the class JdtTypes method resolvePrimitiveType.

private void resolvePrimitiveType(AST ast, TypeKind kind, String pName, String cName) {
    PrimitiveType primitiveType = (PrimitiveType) BindingConverter.getType(ast.resolveWellKnownType(pName));
    TypeElement classElement = BindingConverter.getTypeElement(ast.resolveWellKnownType(cName));
    primitiveTypes.put(kind, primitiveType);
    boxedClasses.put(kind, classElement);
    unboxedTypes.put(classElement, primitiveType);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PrimitiveType(javax.lang.model.type.PrimitiveType)

Example 4 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project mapstruct by mapstruct.

the class TypeFactory method getWrappedType.

public Type getWrappedType(Type type) {
    Type result = type;
    if (type.isPrimitive()) {
        PrimitiveType typeMirror = (PrimitiveType) type.getTypeMirror();
        result = getType(typeUtils.boxedClass(typeMirror));
    }
    return result;
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) ExecutableType(javax.lang.model.type.ExecutableType) PrimitiveType(javax.lang.model.type.PrimitiveType) PrimitiveType(javax.lang.model.type.PrimitiveType)

Example 5 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project mapstruct by mapstruct.

the class MethodMatcher method matchResultType.

private boolean matchResultType(Type resultType, Map<TypeVariable, TypeMirror> genericTypesMap) {
    Type candidateResultType = candidateMethod.getResultType();
    if (!isJavaLangObject(candidateResultType.getTypeMirror()) && !candidateResultType.isVoid()) {
        final Assignability visitedAssignability;
        if (candidateMethod.getReturnType().isVoid()) {
            // for void-methods, the result-type of the candidate needs to be assignable from the given result type
            visitedAssignability = Assignability.VISITED_ASSIGNABLE_FROM;
        } else {
            // for non-void methods, the result-type of the candidate needs to be assignable to the given result
            // type
            visitedAssignability = Assignability.VISITED_ASSIGNABLE_TO;
        }
        TypeMatcher returnTypeMatcher = new TypeMatcher(visitedAssignability, genericTypesMap);
        if (!returnTypeMatcher.visit(candidateResultType.getTypeMirror(), resultType.getTypeMirror())) {
            if (resultType.isPrimitive()) {
                TypeMirror boxedType = typeUtils.boxedClass((PrimitiveType) resultType.getTypeMirror()).asType();
                TypeMatcher boxedReturnTypeMatcher = new TypeMatcher(visitedAssignability, genericTypesMap);
                if (!boxedReturnTypeMatcher.visit(candidateResultType.getTypeMirror(), boxedType)) {
                    return false;
                }
            } else if (candidateResultType.getTypeMirror().getKind().isPrimitive()) {
                TypeMirror boxedCandidateReturnType = typeUtils.boxedClass((PrimitiveType) candidateResultType.getTypeMirror()).asType();
                TypeMatcher boxedReturnTypeMatcher = new TypeMatcher(visitedAssignability, genericTypesMap);
                if (!boxedReturnTypeMatcher.visit(boxedCandidateReturnType, resultType.getTypeMirror())) {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : ArrayType(javax.lang.model.type.ArrayType) Type(org.mapstruct.ap.internal.model.common.Type) DeclaredType(javax.lang.model.type.DeclaredType) PrimitiveType(javax.lang.model.type.PrimitiveType) WildcardType(javax.lang.model.type.WildcardType) TypeMirror(javax.lang.model.type.TypeMirror) PrimitiveType(javax.lang.model.type.PrimitiveType)

Aggregations

PrimitiveType (javax.lang.model.type.PrimitiveType)23 TypeMirror (javax.lang.model.type.TypeMirror)11 TypeElement (javax.lang.model.element.TypeElement)9 DeclaredType (javax.lang.model.type.DeclaredType)6 ArrayType (javax.lang.model.type.ArrayType)5 Test (org.junit.Test)5 WildcardType (javax.lang.model.type.WildcardType)4 Types (javax.lang.model.util.Types)4 Map (java.util.Map)3 TypeKind (javax.lang.model.type.TypeKind)3 Set (java.util.Set)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 Elements (javax.lang.model.util.Elements)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 Expression (com.google.devtools.j2objc.ast.Expression)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)1