Search in sources :

Example 6 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project antlr4 by tunnelvisionlabs.

the class NullUsageProcessor method checkPrimitiveTypeAnnotations.

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));
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) PrimitiveType(javax.lang.model.type.PrimitiveType) VariableElement(javax.lang.model.element.VariableElement)

Example 7 with PrimitiveType

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

the class ConstructorParameterPropertyDescriptor method determineSpecificType.

private TypeMirror determineSpecificType(MetadataGenerationEnvironment environment) {
    TypeMirror candidate = getSource().asType();
    TypeMirror elementCandidate = environment.getTypeUtils().extractElementType(candidate);
    if (elementCandidate != null) {
        candidate = elementCandidate;
    }
    PrimitiveType primitiveType = environment.getTypeUtils().getPrimitiveType(candidate);
    return (primitiveType != null) ? primitiveType : candidate;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) PrimitiveType(javax.lang.model.type.PrimitiveType)

Example 8 with PrimitiveType

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

the class TypeDeclarationGenerator method printBoxedOperators.

private void printBoxedOperators() {
    PrimitiveType primitiveType = env.typeUtil().unboxedType(typeElement.asType());
    if (primitiveType == null) {
        return;
    }
    char binaryName = env.typeUtil().getSignatureName(primitiveType).charAt(0);
    String primitiveName = TypeUtil.getName(primitiveType);
    String capName = NameTable.capitalize(primitiveName);
    String primitiveTypeName = NameTable.getPrimitiveObjCType(primitiveType);
    String valueMethod = primitiveName + "Value";
    if (primitiveName.equals("long")) {
        valueMethod = "longLongValue";
    } else if (primitiveName.equals("byte")) {
        valueMethod = "charValue";
    }
    newline();
    printf("BOXED_INC_AND_DEC(%s, %s, %s)\n", capName, valueMethod, typeName);
    if ("DFIJ".indexOf(binaryName) >= 0) {
        printf("BOXED_COMPOUND_ASSIGN_ARITHMETIC(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
    if ("IJ".indexOf(binaryName) >= 0) {
        printf("BOXED_COMPOUND_ASSIGN_MOD(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
    if ("DF".indexOf(binaryName) >= 0) {
        printf("BOXED_COMPOUND_ASSIGN_FPMOD(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
    if ("IJ".indexOf(binaryName) >= 0) {
        printf("BOXED_COMPOUND_ASSIGN_BITWISE(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
    if ("I".indexOf(binaryName) >= 0) {
        printf("BOXED_SHIFT_ASSIGN_32(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
    if ("J".indexOf(binaryName) >= 0) {
        printf("BOXED_SHIFT_ASSIGN_64(%s, %s, %s, %s)\n", capName, valueMethod, primitiveTypeName, typeName);
    }
}
Also used : PrimitiveType(javax.lang.model.type.PrimitiveType)

Example 9 with PrimitiveType

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

the class Autoboxer method boxWithClass.

private void boxWithClass(Expression expr, TypeElement boxedClass) {
    PrimitiveType primitiveType = typeUtil.unboxedType(boxedClass.asType());
    assert primitiveType != null;
    ExecutableElement wrapperMethod = ElementUtil.findMethod(boxedClass, VALUEOF_METHOD, TypeUtil.getQualifiedName(primitiveType));
    assert wrapperMethod != null : "could not find valueOf method for " + boxedClass;
    MethodInvocation invocation = new MethodInvocation(new ExecutablePair(wrapperMethod), new SimpleName(boxedClass));
    expr.replaceWith(invocation);
    invocation.addArgument(expr);
}
Also used : ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) ExecutableElement(javax.lang.model.element.ExecutableElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) PrimitiveType(javax.lang.model.type.PrimitiveType) SuperMethodInvocation(com.google.devtools.j2objc.ast.SuperMethodInvocation) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation)

Example 10 with PrimitiveType

use of javax.lang.model.type.PrimitiveType in project checker-framework by typetools.

the class AnnotatedTypeFactory method getUnboxedType.

/**
 * Returns the annotated primitive type of the given declared type if it is a boxed declared type.
 * Otherwise, it throws <i>IllegalArgumentException</i> exception.
 *
 * <p>In the {@code AnnotatedTypeFactory} implementation, the returned type has the same primary
 * annotations as the given type. Subclasses may override this behavior.
 *
 * @param type the declared type
 * @return the unboxed primitive type
 * @throws IllegalArgumentException if the type given has no unbox conversion
 */
public AnnotatedPrimitiveType getUnboxedType(AnnotatedDeclaredType type) throws IllegalArgumentException {
    PrimitiveType primitiveType = types.unboxedType(type.getUnderlyingType());
    AnnotatedPrimitiveType pt = (AnnotatedPrimitiveType) AnnotatedTypeMirror.createType(primitiveType, this, false);
    pt.addAnnotations(type.getAnnotations());
    return pt;
}
Also used : AnnotatedPrimitiveType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType) PrimitiveType(javax.lang.model.type.PrimitiveType) AnnotatedPrimitiveType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)

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