use of javax.lang.model.type.PrimitiveType in project checker-framework by typetools.
the class CFGTranslationPhaseOne method box.
/**
* If the input node is an unboxed primitive type, insert a call to the appropriate valueOf
* method, otherwise leave it alone.
*
* @param node in input node
* @return a Node representing the boxed version of the input, which may simply be the input node
*/
protected Node box(Node node) {
// For boxing conversion, see JLS 5.1.7
if (TypesUtils.isPrimitive(node.getType())) {
PrimitiveType primitive = types.getPrimitiveType(node.getType().getKind());
TypeMirror boxedType = types.getDeclaredType(types.boxedClass(primitive));
TypeElement boxedElement = (TypeElement) ((DeclaredType) boxedType).asElement();
IdentifierTree classTree = treeBuilder.buildClassUse(boxedElement);
handleArtificialTree(classTree);
// No need to handle possible errors from evaluating a class literal here
// since this is synthetic code that can't fail.
ClassNameNode className = new ClassNameNode(classTree);
className.setInSource(false);
insertNodeAfter(className, node);
MemberSelectTree valueOfSelect = treeBuilder.buildValueOfMethodAccess(classTree);
handleArtificialTree(valueOfSelect);
MethodAccessNode valueOfAccess = new MethodAccessNode(valueOfSelect, className);
valueOfAccess.setInSource(false);
insertNodeAfter(valueOfAccess, className);
MethodInvocationTree valueOfCall = treeBuilder.buildMethodInvocation(valueOfSelect, (ExpressionTree) node.getTree());
handleArtificialTree(valueOfCall);
Node boxed = new MethodInvocationNode(valueOfCall, valueOfAccess, Collections.singletonList(node), getCurrentPath());
boxed.setInSource(false);
// Add Throwable to account for unchecked exceptions
addToConvertedLookupMap(node.getTree(), boxed);
insertNodeWithExceptionsAfter(boxed, uncheckedExceptionTypes, valueOfAccess);
return boxed;
} else {
return node;
}
}
use of javax.lang.model.type.PrimitiveType in project j2objc by google.
the class JdtTypes method unboxedType.
@Override
public PrimitiveType unboxedType(TypeMirror t) {
if (t.getKind() == TypeKind.DECLARED) {
TypeElement e = (TypeElement) ((DeclaredType) t).asElement();
PrimitiveType result = unboxedTypes.get(e);
if (result != null) {
return result;
}
}
throw new IllegalArgumentException("No unboxing convertion for: " + t);
}
use of javax.lang.model.type.PrimitiveType in project buck by facebook.
the class TreeBackedTypesTest method testIsNotSameTypePrimitiveType.
@Test
public void testIsNotSameTypePrimitiveType() throws IOException {
initCompiler();
PrimitiveType intType = types.getPrimitiveType(TypeKind.INT);
PrimitiveType longType = types.getPrimitiveType(TypeKind.LONG);
assertNotSameType(intType, longType);
}
use of javax.lang.model.type.PrimitiveType in project RoboBinding by RoboBinding.
the class TypeMirrorWrapperTest method supportedTypeMirrors.
@DataPoints("supportedTypeMirrors")
public static TypeMirrorToWrapped[] supportedTypeMirrors() {
Types types = compilation.getTypes();
NoType voidType = types.getNoType(TypeKind.VOID);
PrimitiveType primitiveType = types.getPrimitiveType(TypeKind.INT);
Elements elements = compilation.getElements();
DeclaredType declaredType = (DeclaredType) elements.getTypeElement(Object.class.getName()).asType();
ArrayType arrayType = types.getArrayType(declaredType);
return new TypeMirrorToWrapped[] { a(voidType).itsWrapped(WrappedVoidType.class), a(primitiveType).itsWrapped(WrappedPrimitiveType.class), a(declaredType).itsWrapped(WrappedDeclaredType.class), a(arrayType).itsWrapped(WrappedArrayType.class) };
}
use of javax.lang.model.type.PrimitiveType in project auto by google.
the class MoreTypesTest method testIsTypeOf.
@Test
public void testIsTypeOf() {
Types types = compilationRule.getTypes();
PrimitiveType intType = types.getPrimitiveType(TypeKind.INT);
TypeMirror integerType = types.boxedClass(intType).asType();
WildcardType wildcardType = types.getWildcardType(null, null);
expect.that(MoreTypes.isTypeOf(int.class, intType)).isTrue();
expect.that(MoreTypes.isTypeOf(Integer.class, integerType)).isTrue();
expect.that(MoreTypes.isTypeOf(Integer.class, intType)).isFalse();
expect.that(MoreTypes.isTypeOf(int.class, integerType)).isFalse();
expect.that(MoreTypes.isTypeOf(Integer.class, FAKE_ERROR_TYPE)).isFalse();
assertThrows(IllegalArgumentException.class, () -> MoreTypes.isTypeOf(Integer.class, wildcardType));
}
Aggregations