use of org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef in project n4js by eclipse.
the class TypeUtils method createClassifierBoundThisTypeRef.
/**
* from type{S} to type{this[S]}, as Part of IDE-785
*
* @param actualThisTypeRef
* must not be null, must not contain a this unbound-this-type-ref.
*/
public static TypeTypeRef createClassifierBoundThisTypeRef(TypeTypeRef actualThisTypeRef) {
if (actualThisTypeRef == null) {
throw new NullPointerException("Actual this type must not be null!");
}
TypeArgument typeArg = actualThisTypeRef.getTypeArg();
final BoundThisTypeRef boundThisTypeRef;
if (typeArg instanceof ParameterizedTypeRef) {
boundThisTypeRef = createBoundThisTypeRef((ParameterizedTypeRef) typeArg);
} else if (typeArg instanceof BoundThisTypeRef) {
boundThisTypeRef = (BoundThisTypeRef) typeArg;
} else {
// invalid use
throw new IllegalArgumentException("Cannot turn unbound type{this} into type{this[X]}, must be called with type{X}!");
}
TypeTypeRef classifierBoundThisTypeRef = createTypeTypeRef(boundThisTypeRef, false);
// TODO is there anything else to copy ?
return classifierBoundThisTypeRef;
}
use of org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleUpperBoundThisTypeRef.
protected Result<TypeRef> applyRuleUpperBoundThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BoundThisTypeRef boundThisTypeRef) throws RuleFailedException {
// output parameter
TypeRef T = null;
T = TypeUtils.createResolvedThisTypeRef(boundThisTypeRef);
TypeUtils.copyTypeModifiers(T, boundThisTypeRef);
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef 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);
}
use of org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubstTypeVariablesThisTypeRef.
protected Result<TypeArgument> applyRuleSubstTypeVariablesThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ThisTypeRef thisTypeRef) throws RuleFailedException {
// output parameter
ThisTypeRef T = null;
/* { val BoundThisTypeRef boundRefFromEnv = G.getThisType() as BoundThisTypeRef; if (boundRefFromEnv !== null) { val boundRef = TypeUtils.createBoundThisTypeRef(boundRefFromEnv.actualThisTypeRef); boundRef.setTypingStrategy(thisTypeRef.typingStrategy); TypeUtils.copyTypeModifiers(boundRef, thisTypeRef); T = boundRef; } else { T = thisTypeRef } } or { T = thisTypeRef } */
{
RuleFailedException previousFailure = null;
try {
TypeRef _thisType = RuleEnvironmentExtensions.getThisType(G);
final BoundThisTypeRef boundRefFromEnv = ((BoundThisTypeRef) _thisType);
if ((boundRefFromEnv != null)) {
final BoundThisTypeRef boundRef = TypeUtils.createBoundThisTypeRef(boundRefFromEnv.getActualThisTypeRef());
boundRef.setTypingStrategy(thisTypeRef.getTypingStrategy());
TypeUtils.copyTypeModifiers(boundRef, thisTypeRef);
T = boundRef;
} else {
T = thisTypeRef;
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
T = thisTypeRef;
}
}
return new Result<TypeArgument>(T);
}
use of org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleLowerBoundThisTypeRef.
protected Result<TypeRef> applyRuleLowerBoundThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BoundThisTypeRef boundThisTypeRef) throws RuleFailedException {
// output parameter
TypeRef T = null;
T = RuleEnvironmentExtensions.undefinedTypeRef(G);
TypeUtils.copyTypeModifiers(T, boundThisTypeRef);
return new Result<TypeRef>(T);
}
Aggregations