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));
}
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations