Search in sources :

Example 6 with PrimitiveType

use of org.eclipse.n4js.ts.types.PrimitiveType in project n4js by eclipse.

the class TypeUtils method isRawSuperType.

private static boolean isRawSuperType(Type type, Type superTypeCandidate, RecursionGuard<Type> guard) {
    if (type == superTypeCandidate) {
        return true;
    }
    if (type == null) {
        return false;
    }
    if (guard.tryNext(type)) {
        if (type instanceof TClass) {
            final TClass c = (TClass) type;
            if (isRawSuperType(c.getSuperClassRef(), superTypeCandidate, guard)) {
                return true;
            }
            if (isRawSuperType(c.getImplementedInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TInterface) {
            final TInterface r = (TInterface) type;
            if (isRawSuperType(r.getSuperInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TypeVariable) {
            TypeVariable v = (TypeVariable) type;
            TypeRef ub = v.getDeclaredUpperBound();
            if (ub != null && isRawSuperType(ub, superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof PrimitiveType) {
            PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
            if (isRawSuperType(assignmentCompatible, superTypeCandidate, guard)) {
                return true;
            }
        }
    }
    return false;
}
Also used : TInterface(org.eclipse.n4js.ts.types.TInterface) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) DeferredTypeRef(org.eclipse.n4js.ts.typeRefs.DeferredTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Example 7 with PrimitiveType

use of org.eclipse.n4js.ts.types.PrimitiveType in project n4js by eclipse.

the class TypeUtils method declaredSuperTypes.

/**
 * Convenience method, returns directly declared super types (class, role, interface) of a classifier. May return an
 * empty list but never null. Order is always super class, super roles, super interfaces. For all non-classifiers
 * this method returns an empty list.
 */
@SuppressWarnings("unchecked")
public static Iterable<? extends ParameterizedTypeRef> declaredSuperTypes(final Type type) {
    if (type instanceof TClass) {
        final TClass c = (TClass) type;
        if (c.getSuperClassRef() != null) {
            return Iterables.concat(concat(singletonList(c.getSuperClassRef()), c.getImplementedInterfaceRefs()));
        } else {
            return c.getImplementedInterfaceRefs();
        }
    }
    if (type instanceof TInterface) {
        final TInterface r = (TInterface) type;
        return r.getSuperInterfaceRefs();
    }
    if (type instanceof PrimitiveType) {
        PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
        if (assignmentCompatible != null) {
            ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
            typeRef.setDeclaredType(assignmentCompatible);
            return Collections.singletonList(typeRef);
        }
    }
    if (type instanceof TObjectPrototype) {
        // IDE-1221 string based enums: traversing super types for object prototypes as well
        TObjectPrototype tObjectPrototype = (TObjectPrototype) type;
        if (tObjectPrototype.getSuperType() != null) {
            return singletonList(tObjectPrototype.getSuperType());
        }
    }
    return Collections.emptyList();
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TInterface(org.eclipse.n4js.ts.types.TInterface) TObjectPrototype(org.eclipse.n4js.ts.types.TObjectPrototype) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Example 8 with PrimitiveType

use of org.eclipse.n4js.ts.types.PrimitiveType in project n4js by eclipse.

the class BuiltInTypeScopeTest method testResolveSuperTypeOfBuiltInType.

@SuppressWarnings("javadoc")
@Test
public void testResolveSuperTypeOfBuiltInType() {
    BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
    // trigger loading
    IEObjectDescription intDescription = scope.getSingleElement(QualifiedName.create("i18nKey"));
    PrimitiveType intType = (PrimitiveType) intDescription.getEObjectOrProxy();
    PrimitiveType assCompatType = intType.getAssignmentCompatible();
    Assert.assertFalse(assCompatType.eIsProxy());
    Assert.assertEquals("string", assCompatType.getName());
}
Also used : PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) BuiltInTypeScope(org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Aggregations

PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)8 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)6 TInterface (org.eclipse.n4js.ts.types.TInterface)4 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)3 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)3 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)3 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)3 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)3 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)3 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)3 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)3 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)3 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)2 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)2 AnyType (org.eclipse.n4js.ts.types.AnyType)2 ContainerType (org.eclipse.n4js.ts.types.ContainerType)2 ModuleNamespaceVirtualType (org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType)2 NullType (org.eclipse.n4js.ts.types.NullType)2 TClass (org.eclipse.n4js.ts.types.TClass)2 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)2