Search in sources :

Example 1 with TFormalParameter

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

the class InternalTypeSystem method applyRuleExpectedTypeInFormalParameter.

protected Result<TypeRef> applyRuleExpectedTypeInFormalParameter(final RuleEnvironment G, final RuleApplicationTrace _trace_, final FormalParameter formalParam, final Expression initializer) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = formalParam.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = formalParam.getDeclaredTypeRef();
    } else {
        TFormalParameter _definedTypeElement = formalParam.getDefinedTypeElement();
        TypeRef _typeRef = null;
        if (_definedTypeElement != null) {
            _typeRef = _definedTypeElement.getTypeRef();
        }
        boolean _tripleNotEquals_1 = (_typeRef != null);
        if (_tripleNotEquals_1) {
            T = formalParam.getDefinedTypeElement().getTypeRef();
        } else {
            T = RuleEnvironmentExtensions.anyTypeRef(G);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 2 with TFormalParameter

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

the class InternalTypeSystem method applyRuleTypeFormalParameter.

protected Result<TypeRef> applyRuleTypeFormalParameter(final RuleEnvironment G, final RuleApplicationTrace _trace_, final FormalParameter fpar) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final TypeRef fparTypeRef = fpar.getDeclaredTypeRef();
    if ((fparTypeRef != null)) {
        if (((fparTypeRef instanceof ThisTypeRefStructural) || ((fparTypeRef instanceof FunctionTypeExpression) && IteratorExtensions.<TFormalParameter>exists(Iterators.<TFormalParameter>filter(((FunctionTypeExpression) fparTypeRef).eAllContents(), TFormalParameter.class), ((Function1<TFormalParameter, Boolean>) (TFormalParameter currFpar) -> {
            TypeRef _typeRef = currFpar.getTypeRef();
            return Boolean.valueOf((_typeRef instanceof ThisTypeRef));
        }))))) {
            T = this.typeSystemHelper.bindAndSubstituteThisTypeRef(G, fparTypeRef, fparTypeRef);
        } else {
            TypeRef _xifexpression = null;
            TFormalParameter _definedTypeElement = null;
            if (fpar != null) {
                _definedTypeElement = fpar.getDefinedTypeElement();
            }
            TypeRef _typeRef = null;
            if (_definedTypeElement != null) {
                _typeRef = _definedTypeElement.getTypeRef();
            }
            boolean _tripleNotEquals = (_typeRef != null);
            if (_tripleNotEquals) {
                _xifexpression = fpar.getDefinedTypeElement().getTypeRef();
            } else {
                _xifexpression = fpar.getDeclaredTypeRef();
            }
            T = _xifexpression;
        }
    } else {
        boolean _isHasInitializerAssignment = fpar.isHasInitializerAssignment();
        if (_isHasInitializerAssignment) {
            Expression _initializer = fpar.getInitializer();
            boolean _tripleNotEquals_1 = (_initializer != null);
            if (_tripleNotEquals_1) {
                /* G |- fpar.initializer : var TypeRef E */
                Expression _initializer_1 = fpar.getInitializer();
                TypeRef E = null;
                Result<TypeRef> result = typeInternal(G, _trace_, _initializer_1);
                checkAssignableTo(result.getFirst(), TypeRef.class);
                E = (TypeRef) result.getFirst();
                T = this.typeSystemHelper.sanitizeTypeOfVariableFieldProperty(G, E);
            } else {
                T = RuleEnvironmentExtensions.anyTypeRef(G);
            }
        } else {
            boolean _enforceDynamicTypes = this.jsVariantHelper.enforceDynamicTypes(fpar);
            if (_enforceDynamicTypes) {
                T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
            } else {
                /* T = env(G, fpar, TypeRef) or T = G.anyTypeRef */
                {
                    RuleFailedException previousFailure = null;
                    try {
                        T = this.<TypeRef>env(G, fpar, TypeRef.class);
                    } catch (Exception e) {
                        previousFailure = extractRuleFailedException(e);
                        T = RuleEnvironmentExtensions.anyTypeRef(G);
                    }
                }
            }
        }
    }
    T = TypeUtils.wrapIfVariadic(RuleEnvironmentExtensions.getPredefinedTypes(G).builtInTypeScope, T, fpar);
    return new Result<TypeRef>(T);
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) PromisifyExpression(org.eclipse.n4js.n4JS.PromisifyExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression) N4ClassExpression(org.eclipse.n4js.n4JS.N4ClassExpression) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ThisTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 3 with TFormalParameter

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

the class FormalParameterImpl method setDefinedTypeElement.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setDefinedTypeElement(TFormalParameter newDefinedTypeElement) {
    TFormalParameter oldDefinedTypeElement = definedTypeElement;
    definedTypeElement = newDefinedTypeElement;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.FORMAL_PARAMETER__DEFINED_TYPE_ELEMENT, oldDefinedTypeElement, definedTypeElement));
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 4 with TFormalParameter

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

the class FunctionTypeExprOrRefImpl method getTypeRefAsString.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getTypeRefAsString() {
    String _xifexpression = null;
    TypeRef _declaredThisType = this.getDeclaredThisType();
    boolean _tripleNotEquals = (_declaredThisType != null);
    if (_tripleNotEquals) {
        String _typeRefAsString = this.getDeclaredThisType().getTypeRefAsString();
        String _plus = ("@This(" + _typeRefAsString);
        _xifexpression = (_plus + ") ");
    } else {
        _xifexpression = "";
    }
    String _plus_1 = ("{" + _xifexpression);
    String _plus_2 = (_plus_1 + "function");
    String _xifexpression_1 = null;
    boolean _isGeneric = this.isGeneric();
    if (_isGeneric) {
        final Function1<TypeVariable, String> _function = new Function1<TypeVariable, String>() {

            public String apply(final TypeVariable it) {
                return it.getTypeVariableAsString(FunctionTypeExprOrRefImpl.this.getTypeVarUpperBound(it));
            }
        };
        String _join = IterableExtensions.join(XcoreEListExtensions.<TypeVariable, String>map(this.getTypeVars(), _function), ",");
        String _plus_3 = ("<" + _join);
        _xifexpression_1 = (_plus_3 + ">");
    } else {
        _xifexpression_1 = "";
    }
    String _plus_4 = (_plus_2 + _xifexpression_1);
    String _plus_5 = (_plus_4 + "(");
    final Function1<TFormalParameter, String> _function_1 = new Function1<TFormalParameter, String>() {

        public String apply(final TFormalParameter it) {
            return it.getFormalParameterAsTypesString();
        }
    };
    String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TFormalParameter, String>map(this.getFpars(), _function_1), ",");
    String _plus_6 = (_plus_5 + _join_1);
    String _plus_7 = (_plus_6 + ")");
    String _xifexpression_2 = null;
    TypeRef _returnTypeRef = this.getReturnTypeRef();
    boolean _tripleNotEquals_1 = (_returnTypeRef != null);
    if (_tripleNotEquals_1) {
        String _typeRefAsString_1 = this.getReturnTypeRef().getTypeRefAsString();
        _xifexpression_2 = (":" + _typeRefAsString_1);
    } else {
        _xifexpression_2 = "";
    }
    String _plus_8 = (_plus_7 + _xifexpression_2);
    String _xifexpression_3 = null;
    boolean _isReturnValueOptional = this.isReturnValueOptional();
    if (_isReturnValueOptional) {
        _xifexpression_3 = "?";
    } else {
        _xifexpression_3 = "";
    }
    String _plus_9 = (_plus_8 + _xifexpression_3);
    String _plus_10 = (_plus_9 + "}");
    String _modifiersAsString = this.getModifiersAsString();
    return (_plus_10 + _modifiersAsString);
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1)

Example 5 with TFormalParameter

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

the class FunctionTypeRefImpl method getTypeRefAsString.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getTypeRefAsString() {
    String _xifexpression = null;
    TypeRef _declaredThisType = this.getDeclaredThisType();
    boolean _tripleNotEquals = (_declaredThisType != null);
    if (_tripleNotEquals) {
        String _typeRefAsString = this.getDeclaredThisType().getTypeRefAsString();
        String _plus = ("@This(" + _typeRefAsString);
        _xifexpression = (_plus + ") ");
    } else {
        _xifexpression = "";
    }
    String _plus_1 = ("{" + _xifexpression);
    String _plus_2 = (_plus_1 + "function");
    String _xifexpression_1 = null;
    boolean _isGeneric = this.isGeneric();
    if (_isGeneric) {
        final Function1<TypeVariable, String> _function = new Function1<TypeVariable, String>() {

            public String apply(final TypeVariable it) {
                return it.getTypeVariableAsString(FunctionTypeRefImpl.this.getTypeVarUpperBound(it));
            }
        };
        String _join = IterableExtensions.join(XcoreEListExtensions.<TypeVariable, String>map(this.getTypeVars(), _function), ",");
        String _plus_3 = ("<" + _join);
        _xifexpression_1 = (_plus_3 + ">");
    } else {
        _xifexpression_1 = "";
    }
    String _plus_4 = (_plus_2 + _xifexpression_1);
    String _plus_5 = (_plus_4 + "(");
    final Function1<TFormalParameter, String> _function_1 = new Function1<TFormalParameter, String>() {

        public String apply(final TFormalParameter it) {
            return it.getFormalParameterAsTypesString();
        }
    };
    String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TFormalParameter, String>map(this.getFpars(), _function_1), ",");
    String _plus_6 = (_plus_5 + _join_1);
    String _plus_7 = (_plus_6 + ")");
    String _xifexpression_2 = null;
    TypeRef _returnTypeRef = this.getReturnTypeRef();
    boolean _tripleNotEquals_1 = (_returnTypeRef != null);
    if (_tripleNotEquals_1) {
        String _typeRefAsString_1 = this.getReturnTypeRef().getTypeRefAsString();
        _xifexpression_2 = (":" + _typeRefAsString_1);
    } else {
        _xifexpression_2 = "";
    }
    String _plus_8 = (_plus_7 + _xifexpression_2);
    String _xifexpression_3 = null;
    boolean _isReturnValueOptional = this.isReturnValueOptional();
    if (_isReturnValueOptional) {
        _xifexpression_3 = "?";
    } else {
        _xifexpression_3 = "";
    }
    String _plus_9 = (_plus_8 + _xifexpression_3);
    String _plus_10 = (_plus_9 + "}");
    String _modifiersAsString = this.getModifiersAsString();
    return (_plus_10 + _modifiersAsString);
}
Also used : TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1)

Aggregations

TFormalParameter (org.eclipse.n4js.ts.types.TFormalParameter)22 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)12 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)9 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)7 TypeVariable (org.eclipse.n4js.ts.types.TypeVariable)7 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)6 TMethod (org.eclipse.n4js.ts.types.TMethod)5 FunctionTypeExpression (org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression)4 IntersectionTypeExpression (org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression)4 ThisTypeRefStructural (org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural)4 UnionTypeExpression (org.eclipse.n4js.ts.typeRefs.UnionTypeExpression)4 EPackage (org.eclipse.emf.ecore.EPackage)3 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)3 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)3 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)3 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)3 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)3 CastExpression (org.eclipse.n4js.n4JS.CastExpression)3 CommaExpression (org.eclipse.n4js.n4JS.CommaExpression)3 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)3