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;
}
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();
}
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());
}
Aggregations