use of org.eclipse.n4js.ts.types.TObjectPrototype in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeBinaryLogicalExpression.
protected Result<TypeRef> applyRuleTypeBinaryLogicalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BinaryLogicalExpression e) throws RuleFailedException {
// output parameter
TypeRef T = null;
final Expression lhs = e.getLhs();
final Expression rhs = e.getRhs();
boolean _xifexpression = false;
if ((lhs instanceof ArrayLiteral)) {
_xifexpression = ((ArrayLiteral) lhs).getElements().isEmpty();
}
final boolean lhsIsEmptyArrayLiteral = _xifexpression;
boolean _xifexpression_1 = false;
if ((rhs instanceof ArrayLiteral)) {
_xifexpression_1 = ((ArrayLiteral) rhs).getElements().isEmpty();
}
final boolean rhsIsEmptyArrayLiteral = _xifexpression_1;
/* G |- e.lhs : var TypeRef L */
Expression _lhs = e.getLhs();
TypeRef L = null;
Result<TypeRef> result = typeInternal(G, _trace_, _lhs);
checkAssignableTo(result.getFirst(), TypeRef.class);
L = (TypeRef) result.getFirst();
/* G |- e.rhs : var TypeRef R */
Expression _rhs = e.getRhs();
TypeRef R = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _rhs);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
R = (TypeRef) result_1.getFirst();
boolean _and = false;
boolean _lhsIsEmptyArrayLiteral = lhsIsEmptyArrayLiteral;
if (!_lhsIsEmptyArrayLiteral) {
_and = false;
} else {
Type _declaredType = null;
if (R != null) {
_declaredType = R.getDeclaredType();
}
TObjectPrototype _arrayType = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals = (_declaredType == _arrayType);
_and = _tripleEquals;
}
if (_and) {
T = R;
} else {
boolean _and_1 = false;
boolean _rhsIsEmptyArrayLiteral = rhsIsEmptyArrayLiteral;
if (!_rhsIsEmptyArrayLiteral) {
_and_1 = false;
} else {
Type _declaredType_1 = null;
if (L != null) {
_declaredType_1 = L.getDeclaredType();
}
TObjectPrototype _arrayType_1 = RuleEnvironmentExtensions.arrayType(G);
boolean _tripleEquals_1 = (_declaredType_1 == _arrayType_1);
_and_1 = _tripleEquals_1;
}
if (_and_1) {
T = L;
} else {
T = this.typeSystemHelper.createUnionType(G, L, R);
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.types.TObjectPrototype in project n4js by eclipse.
the class AllSuperTypeRefsCollector method doProcess.
@Override
protected void doProcess(ContainerType<?> containerType) {
if (containerType instanceof TClass) {
TClass casted = (TClass) containerType;
ParameterizedTypeRef superType = casted.getSuperClassRef();
result.addAll(casted.getImplementedInterfaceRefs());
if (superType != null) {
result.add(superType);
}
} else if (containerType instanceof TInterface) {
TInterface casted = (TInterface) containerType;
result.addAll(casted.getSuperInterfaceRefs());
} else if (containerType instanceof TObjectPrototype) {
TObjectPrototype casted = (TObjectPrototype) containerType;
ParameterizedTypeRef superType = casted.getSuperType();
if (superType != null) {
result.add(superType);
}
} else if (containerType instanceof PrimitiveType) {
PrimitiveType assignmentCompatible = ((PrimitiveType) containerType).getAssignmentCompatible();
if (assignmentCompatible != null) {
ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
typeRef.setDeclaredType(assignmentCompatible);
result.add(typeRef);
}
}
}
use of org.eclipse.n4js.ts.types.TObjectPrototype 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.TObjectPrototype in project n4js by eclipse.
the class MemberVisibilityChecker method getActualDeclaredReceiverType.
/**
* Returns the actual receiver type, which usually simply is the declared type of the receiver type. However, in
* case of classifier references, enums, or structural type references, the actual receiver may be differently
* computed.
*/
private Type getActualDeclaredReceiverType(EObject context, TypeRef receiverType, ResourceSet resourceSet) {
if (receiverType instanceof TypeTypeRef) {
final RuleEnvironment G = RuleEnvironmentExtensions.newRuleEnvironment(context);
return tsh.getStaticType(G, (TypeTypeRef) receiverType);
}
if (receiverType instanceof ThisTypeRef) {
ThisTypeRef thisTypeRef = (ThisTypeRef) receiverType;
if (thisTypeRef.isUseSiteStructuralTyping()) {
FunctionOrFieldAccessor foa = N4JSASTUtils.getContainingFunctionOrAccessor(thisTypeRef);
N4ClassifierDefinition classifier = EcoreUtil2.getContainerOfType(foa, N4ClassifierDefinition.class);
return classifier.getDefinedType();
}
}
if (receiverType instanceof FunctionTypeExpression) {
if (resourceSet == null)
return null;
// Change receiverType to implicit super class Function.
BuiltInTypeScope builtInTypeScope = BuiltInTypeScope.get(resourceSet);
TObjectPrototype functionType = builtInTypeScope.getFunctionType();
return functionType;
}
return receiverType.getDeclaredType();
}
use of org.eclipse.n4js.ts.types.TObjectPrototype in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeCallExpression.
protected Result<TypeRef> applyRuleTypeCallExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedCallExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* G |- expr.target : var TypeRef targetTypeRef */
Expression _target = expr.getTarget();
TypeRef targetTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, _target);
checkAssignableTo(result.getFirst(), TypeRef.class);
targetTypeRef = (TypeRef) result.getFirst();
if ((targetTypeRef instanceof FunctionTypeExprOrRef)) {
final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) targetTypeRef);
final TFunction tFunction = F.getFunctionType();
/* { val inferring = env(G, GUARD_TYPE_CALL_EXPRESSION -> expr, TypeRef) G |- inferring ~> T } or { val G2 = G.wrap; G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) if(expr.eContainer instanceof AwaitExpression && expr.eContainmentFeature === N4JSPackage.eINSTANCE.getAwaitExpression_Expression() && tFunction!==null && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction)) { T = promisifyHelper.extractPromisifiedReturnType(expr); } else { T = F.returnTypeRef ?: G.anyTypeRef; } typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef); G2 |- T ~> T T = versionResolver.resolveVersion(T, F); if (T instanceof BoundThisTypeRef && !(expr.receiver instanceof ThisLiteral || expr.receiver instanceof SuperLiteral)) { G2 |~ T /\ T } } */
{
RuleFailedException previousFailure = null;
try {
Pair<String, ParameterizedCallExpression> _mappedTo = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
final TypeRef inferring = this.<TypeRef>env(G, _mappedTo, TypeRef.class);
/* G |- inferring ~> T */
Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, inferring);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
Pair<String, ParameterizedCallExpression> _mappedTo_1 = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
boolean _add = G2.add(_mappedTo_1, F.getReturnTypeRef());
/* G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) */
if (!_add) {
sneakyThrowRuleFailedException("G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef)");
}
if (((((expr.eContainer() instanceof AwaitExpression) && (expr.eContainmentFeature() == N4JSPackage.eINSTANCE.getAwaitExpression_Expression())) && (tFunction != null)) && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction))) {
T = this.promisifyHelper.extractPromisifiedReturnType(expr);
} else {
TypeRef _elvis = null;
TypeRef _returnTypeRef = F.getReturnTypeRef();
if (_returnTypeRef != null) {
_elvis = _returnTypeRef;
} else {
ParameterizedTypeRef _anyTypeRef = RuleEnvironmentExtensions.anyTypeRef(G);
_elvis = _anyTypeRef;
}
T = _elvis;
}
this.typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef);
/* G2 |- T ~> T */
Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, T);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
T = this.versionResolver.<TypeRef, FunctionTypeExprOrRef>resolveVersion(T, F);
if (((T instanceof BoundThisTypeRef) && (!((expr.getReceiver() instanceof ThisLiteral) || (expr.getReceiver() instanceof SuperLiteral))))) {
/* G2 |~ T /\ T */
Result<TypeRef> result_3 = upperBoundInternal(G2, _trace_, T);
checkAssignableTo(result_3.getFirst(), TypeRef.class);
T = (TypeRef) result_3.getFirst();
}
}
}
} else {
Type _declaredType = null;
if (targetTypeRef != null) {
_declaredType = targetTypeRef.getDeclaredType();
}
TObjectPrototype _functionType = RuleEnvironmentExtensions.functionType(G);
boolean _tripleEquals = (_declaredType == _functionType);
if (_tripleEquals) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
boolean _isDynamic = targetTypeRef.isDynamic();
if (_isDynamic) {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
}
return new Result<TypeRef>(T);
}
Aggregations