use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.
the class N4MethodDeclarationImpl method existsExplicitSuperCall.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean existsExplicitSuperCall() {
final Function1<ExpressionStatement, Expression> _function = new Function1<ExpressionStatement, Expression>() {
public Expression apply(final ExpressionStatement it) {
return it.getExpression();
}
};
final Function1<ParameterizedCallExpression, Boolean> _function_1 = new Function1<ParameterizedCallExpression, Boolean>() {
public Boolean apply(final ParameterizedCallExpression it) {
Expression _target = it.getTarget();
return Boolean.valueOf((_target instanceof SuperLiteral));
}
};
final boolean existsSuperCall = IteratorExtensions.<ParameterizedCallExpression>exists(Iterators.<ParameterizedCallExpression>filter(IteratorExtensions.<ExpressionStatement, Expression>map(Iterators.<ExpressionStatement>filter(EcoreUtilN4.<Statement>getAllDirectlyFoundContentsOfType(this.getBody(), Statement.class), ExpressionStatement.class), _function), ParameterizedCallExpression.class), _function_1);
return existsSuperCall;
}
use of org.eclipse.n4js.n4JS.ParameterizedCallExpression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleExpectedTypeOfArgument.
protected Result<TypeRef> applyRuleExpectedTypeOfArgument(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Argument argument, final Expression argumentExpression) throws RuleFailedException {
// output parameter
TypeRef T = null;
final EObject expr = argument.eContainer();
if ((expr instanceof NewExpression)) {
boolean _contains = ((NewExpression) expr).getArguments().contains(argument);
boolean _not = (!_contains);
if (_not) {
} else {
/* G |- expr.callee : var TypeTypeRef ctorTypeRef */
Expression _callee = ((NewExpression) expr).getCallee();
TypeTypeRef ctorTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, _callee);
checkAssignableTo(result.getFirst(), TypeTypeRef.class);
ctorTypeRef = (TypeTypeRef) result.getFirst();
TypeRef typeRefOfInstanceToCreate = this.typeSystemHelper.createTypeRefFromStaticType(G, ctorTypeRef, ((TypeArgument[]) Conversions.unwrapArray(((NewExpression) expr).getTypeArgs(), TypeArgument.class)));
Type _declaredType = typeRefOfInstanceToCreate.getDeclaredType();
ContainerType<?> typeOfInstanceToCreate = ((ContainerType<?>) _declaredType);
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
this.typeSystemHelper.addSubstitutions(G2, typeRefOfInstanceToCreate);
RuleEnvironmentExtensions.addThisType(G2, typeRefOfInstanceToCreate);
TMethod ctor = this.containerTypesHelper.fromContext(((NewExpression) expr).eResource()).findConstructor(typeOfInstanceToCreate);
TFormalParameter _fparForArgIdx = null;
if (ctor != null) {
_fparForArgIdx = ctor.getFparForArgIdx(ECollections.indexOf(((NewExpression) expr).getArguments(), argument, 0));
}
final TFormalParameter fpar = _fparForArgIdx;
if ((fpar == null)) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
final TypeRef paramType = fpar.getTypeRef();
if ((paramType == null)) {
T = RuleEnvironmentExtensions.anyTypeRef(G2);
} else {
/* G2 |- paramType ~> T */
Result<TypeArgument> result_1 = substTypeVariablesInternal(G2, _trace_, paramType);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
}
}
}
} else {
if ((expr instanceof ParameterizedCallExpression)) {
boolean _contains_1 = ((ParameterizedCallExpression) expr).getArguments().contains(argument);
/* expr.arguments.contains(argument) */
if (!_contains_1) {
sneakyThrowRuleFailedException("expr.arguments.contains(argument)");
}
/* G |- expr.target : var TypeRef targetTypeRef */
Expression _target = ((ParameterizedCallExpression) expr).getTarget();
TypeRef targetTypeRef = null;
Result<TypeRef> result_2 = typeInternal(G, _trace_, _target);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
targetTypeRef = (TypeRef) result_2.getFirst();
if ((targetTypeRef instanceof FunctionTypeExprOrRef)) {
final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) targetTypeRef);
final int argIndex = ECollections.indexOf(((ParameterizedCallExpression) expr).getArguments(), argument, 0);
final TFormalParameter fpar_1 = F.getFparForArgIdx(argIndex);
if ((fpar_1 == null)) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
final TypeRef paramType_1 = fpar_1.getTypeRef();
if ((paramType_1 == null)) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
this.typeSystemHelper.addSubstitutions(G2_1, ((ParameterizedCallExpression) expr), F);
Expression _target_1 = ((ParameterizedCallExpression) expr).getTarget();
if ((_target_1 instanceof SuperLiteral)) {
N4ClassDeclaration _containerOfType = EcoreUtil2.<N4ClassDeclaration>getContainerOfType(expr, N4ClassDeclaration.class);
Type _definedType = null;
if (_containerOfType != null) {
_definedType = _containerOfType.getDefinedType();
}
final Type containingClass = _definedType;
if ((containingClass instanceof TClass)) {
RuleEnvironmentExtensions.addThisType(G2_1, TypeExtensions.ref(containingClass));
ParameterizedTypeRef _superClassRef = ((TClass) containingClass).getSuperClassRef();
boolean _tripleNotEquals = (_superClassRef != null);
if (_tripleNotEquals) {
this.typeSystemHelper.addSubstitutions(G2_1, ((TClass) containingClass).getSuperClassRef());
}
if ((paramType_1 instanceof ThisTypeRefStructural)) {
RuleEnvironmentExtensions.addThisType(G2_1, ((TClass) containingClass).getSuperClassRef());
}
}
}
/* G2 |- paramType ~> T */
Result<TypeArgument> result_3 = substTypeVariablesInternal(G2_1, _trace_, paramType_1);
checkAssignableTo(result_3.getFirst(), TypeRef.class);
T = (TypeRef) result_3.getFirst();
}
}
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.ParameterizedCallExpression 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