use of javax.lang.model.type.TypeKind in project ceylon-compiler by ceylon.
the class LLNI method fieldDefs.
FieldDefsRes fieldDefs(TypeElement clazz, String cname, boolean bottomMost) {
FieldDefsRes res;
int offset;
boolean didTwoWordFields = false;
TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass());
if (superclazz != null) {
String supername = superclazz.getQualifiedName().toString();
res = new FieldDefsRes(clazz, fieldDefs(superclazz, cname, false), bottomMost);
offset = res.parent.byteSize;
} else {
res = new FieldDefsRes(clazz, null, bottomMost);
offset = 0;
}
List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
for (VariableElement field : fields) {
if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) {
offset = doTwoWordFields(res, clazz, offset, cname, false);
didTwoWordFields = true;
}
TypeKind tk = field.asType().getKind();
boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
if (!doubleAlign || !twoWords) {
if (doField(res, field, cname, false))
offset += 4;
}
}
if (doubleAlign && !didTwoWordFields) {
if ((offset % 8) != 0)
offset += 4;
offset = doTwoWordFields(res, clazz, offset, cname, true);
}
res.byteSize = offset;
return res;
}
use of javax.lang.model.type.TypeKind in project ceylon-compiler by ceylon.
the class LLNI method doTwoWordFields.
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz, int offset, String cname, boolean padWord) {
boolean first = true;
List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
for (VariableElement field : fields) {
TypeKind tk = field.asType().getKind();
boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
if (twoWords && doField(res, field, cname, first && padWord)) {
offset += 8;
first = false;
}
}
return offset;
}
use of javax.lang.model.type.TypeKind in project auto by google.
the class MoreTypesTest method equivalence.
@Test
public void equivalence() {
Types types = compilationRule.getTypes();
Elements elements = compilationRule.getElements();
TypeMirror objectType = elements.getTypeElement(Object.class.getCanonicalName()).asType();
TypeMirror stringType = elements.getTypeElement(String.class.getCanonicalName()).asType();
TypeElement mapElement = elements.getTypeElement(Map.class.getCanonicalName());
TypeElement setElement = elements.getTypeElement(Set.class.getCanonicalName());
TypeElement enumElement = elements.getTypeElement(Enum.class.getCanonicalName());
TypeElement funkyBounds = elements.getTypeElement(FunkyBounds.class.getCanonicalName());
TypeElement funkyBounds2 = elements.getTypeElement(FunkyBounds2.class.getCanonicalName());
TypeElement funkierBounds = elements.getTypeElement(FunkierBounds.class.getCanonicalName());
TypeMirror funkyBoundsVar = ((DeclaredType) funkyBounds.asType()).getTypeArguments().get(0);
TypeMirror funkyBounds2Var = ((DeclaredType) funkyBounds2.asType()).getTypeArguments().get(0);
TypeMirror funkierBoundsVar = ((DeclaredType) funkierBounds.asType()).getTypeArguments().get(0);
DeclaredType mapOfObjectToObjectType = types.getDeclaredType(mapElement, objectType, objectType);
TypeMirror mapType = mapElement.asType();
DeclaredType setOfSetOfObject = types.getDeclaredType(setElement, types.getDeclaredType(setElement, objectType));
DeclaredType setOfSetOfString = types.getDeclaredType(setElement, types.getDeclaredType(setElement, stringType));
DeclaredType setOfSetOfSetOfObject = types.getDeclaredType(setElement, setOfSetOfObject);
DeclaredType setOfSetOfSetOfString = types.getDeclaredType(setElement, setOfSetOfString);
WildcardType wildcard = types.getWildcardType(null, null);
EquivalenceTester<TypeMirror> tester = EquivalenceTester.<TypeMirror>of(MoreTypes.equivalence()).addEquivalenceGroup(types.getNullType()).addEquivalenceGroup(types.getNoType(NONE)).addEquivalenceGroup(types.getNoType(VOID)).addEquivalenceGroup(objectType).addEquivalenceGroup(stringType).addEquivalenceGroup(funkyBounds.asType()).addEquivalenceGroup(funkyBounds2.asType()).addEquivalenceGroup(funkierBounds.asType()).addEquivalenceGroup(funkyBoundsVar, funkyBounds2Var).addEquivalenceGroup(funkierBoundsVar).addEquivalenceGroup(enumElement.asType()).addEquivalenceGroup(mapType).addEquivalenceGroup(mapOfObjectToObjectType).addEquivalenceGroup(types.getDeclaredType(mapElement, wildcard, wildcard)).addEquivalenceGroup(types.erasure(mapType), types.erasure(mapOfObjectToObjectType)).addEquivalenceGroup(types.getDeclaredType(mapElement, objectType, stringType)).addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, objectType)).addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, stringType)).addEquivalenceGroup(setOfSetOfObject).addEquivalenceGroup(setOfSetOfString).addEquivalenceGroup(setOfSetOfSetOfObject).addEquivalenceGroup(setOfSetOfSetOfString).addEquivalenceGroup(wildcard).addEquivalenceGroup(types.getWildcardType(objectType, null)).addEquivalenceGroup(types.getWildcardType(stringType, null)).addEquivalenceGroup(types.getWildcardType(null, stringType)).addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, types.getDeclaredType(mapElement, stringType, types.getDeclaredType(setElement, objectType)))).addEquivalenceGroup(FAKE_ERROR_TYPE);
for (TypeKind kind : TypeKind.values()) {
if (kind.isPrimitive()) {
PrimitiveType primitiveType = types.getPrimitiveType(kind);
TypeMirror boxedPrimitiveType = types.boxedClass(primitiveType).asType();
tester.addEquivalenceGroup(primitiveType, types.unboxedType(boxedPrimitiveType));
tester.addEquivalenceGroup(boxedPrimitiveType);
tester.addEquivalenceGroup(types.getArrayType(primitiveType));
tester.addEquivalenceGroup(types.getArrayType(boxedPrimitiveType));
}
}
ImmutableSet<Class<?>> testClasses = ImmutableSet.of(ExecutableElementsGroupA.class, ExecutableElementsGroupB.class, ExecutableElementsGroupC.class, ExecutableElementsGroupD.class, ExecutableElementsGroupE.class);
for (Class<?> testClass : testClasses) {
ImmutableList<TypeMirror> equivalenceGroup = FluentIterable.from(elements.getTypeElement(testClass.getCanonicalName()).getEnclosedElements()).transform(new Function<Element, TypeMirror>() {
@Override
public TypeMirror apply(Element input) {
return input.asType();
}
}).toList();
tester.addEquivalenceGroup(equivalenceGroup);
}
tester.test();
}
use of javax.lang.model.type.TypeKind in project auto by google.
the class Optionalish method getContainedPrimitiveType.
private TypeMirror getContainedPrimitiveType(Types typeUtils) {
String simpleName = optionalType.asElement().getSimpleName().toString();
TypeKind typeKind = PRIMITIVE_TYPE_KINDS.get(simpleName);
Verify.verifyNotNull(typeKind, "Could not get contained type of %s", optionalType);
return typeUtils.getPrimitiveType(typeKind);
}
use of javax.lang.model.type.TypeKind in project tiger by google.
the class NewBindingKey method get.
public static NewBindingKey get(TypeMirror type, @Nullable AnnotationMirror qualifier) {
Preconditions.checkNotNull(type);
TypeKind typeKind = type.getKind();
if (typeKind.equals(TypeKind.ERROR)) {
throw new ResolveTypeMirrorException(type);
}
Preconditions.checkArgument(typeKind.equals(TypeKind.DECLARED) || typeKind.isPrimitive() || typeKind.equals(TypeKind.TYPEVAR) || typeKind.equals(TypeKind.ARRAY), String.format("Unexpected type %s of Kind %s", type, typeKind));
return new NewBindingKey(type, qualifier);
}
Aggregations