Search in sources :

Example 1 with UnknownTypeException

use of javax.lang.model.type.UnknownTypeException in project ceylon-compiler by ceylon.

the class ModelChecker method validateUnionTypeInfo.

private void validateUnionTypeInfo(Element ex) {
    UnionTypeInfo ut = ex.getAnnotation(UnionTypeInfo.class);
    assertTrue(ut != null, "UnionType annotation must be present");
    TypeMirror expectedUnionType = ex.asType();
    assertTrue(expectedUnionType.getKind() == TypeKind.UNION, "UNION kind expected");
    try {
        new SimpleTypeVisitor6<Void, Void>() {
        }.visit(expectedUnionType);
        throw new RuntimeException("Expected UnknownTypeException not thrown.");
    } catch (UnknownTypeException ute) {
        // Expected
        ;
    }
    UnionType unionType = new SimpleTypeVisitor7<UnionType, Void>() {

        @Override
        protected UnionType defaultAction(TypeMirror e, Void p) {
            return null;
        }

        @Override
        public UnionType visitUnion(UnionType t, Void p) {
            return t;
        }
    }.visit(expectedUnionType);
    assertTrue(unionType != null, "Must get a non-null union type.");
    assertTrue(ut.value().length == unionType.getAlternatives().size(), "Cardinalities do not match");
    String[] typeNames = ut.value();
    for (int i = 0; i < typeNames.length; i++) {
        TypeMirror typeFromAnnotation = nameToType(typeNames[i]);
        assertTrue(types.isSameType(typeFromAnnotation, unionType.getAlternatives().get(i)), "Types were not equal.");
    }
}
Also used : UnionType(javax.lang.model.type.UnionType) TypeMirror(javax.lang.model.type.TypeMirror) UnknownTypeException(javax.lang.model.type.UnknownTypeException)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)1 UnionType (javax.lang.model.type.UnionType)1 UnknownTypeException (javax.lang.model.type.UnknownTypeException)1