Search in sources :

Example 11 with TypeKind

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

Example 12 with TypeKind

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;
}
Also used : TypeKind(javax.lang.model.type.TypeKind) VariableElement(javax.lang.model.element.VariableElement)

Example 13 with TypeKind

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();
}
Also used : Types(javax.lang.model.util.Types) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeParameterElement(javax.lang.model.element.TypeParameterElement) TypeKind(javax.lang.model.type.TypeKind) Elements(javax.lang.model.util.Elements) Function(com.google.common.base.Function) WildcardType(javax.lang.model.type.WildcardType) TypeMirror(javax.lang.model.type.TypeMirror) PrimitiveType(javax.lang.model.type.PrimitiveType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 14 with TypeKind

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);
}
Also used : TypeKind(javax.lang.model.type.TypeKind)

Example 15 with 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);
}
Also used : TypeKind(javax.lang.model.type.TypeKind)

Aggregations

TypeKind (javax.lang.model.type.TypeKind)24 TypeMirror (javax.lang.model.type.TypeMirror)8 TypeElement (javax.lang.model.element.TypeElement)6 VariableElement (javax.lang.model.element.VariableElement)4 DeclaredType (javax.lang.model.type.DeclaredType)4 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 PrimitiveType (javax.lang.model.type.PrimitiveType)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ClassName (com.squareup.javapoet.ClassName)1 JavaFile (com.squareup.javapoet.JavaFile)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 TypeSpec (com.squareup.javapoet.TypeSpec)1