Search in sources :

Example 6 with Type

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

the class AmbiguousImportDescription method getMessage.

@Override
public String getMessage() {
    StringBuilder typeListStr = new StringBuilder();
    IdentifiableElement first = (IdentifiableElement) EcoreUtil.resolve(getEObjectOrProxy(), context);
    String typeIdent = first instanceof Type ? "type" : "variable";
    TModule module = (TModule) first.eContainer();
    typeListStr.append(module.getQualifiedName());
    Set<IdentifiableElement> uniqueTypes = Sets.newLinkedHashSet(elements);
    uniqueTypes.remove(first);
    Iterator<IdentifiableElement> iter = uniqueTypes.iterator();
    while (iter.hasNext()) {
        IdentifiableElement type = iter.next();
        if (iter.hasNext()) {
            typeListStr.append(", ");
        } else {
            typeListStr.append(" and ");
        }
        typeListStr.append(((TModule) type.eContainer()).getQualifiedName());
    }
    if (this.issueCode == IssueCodes.IMP_AMBIGUOUS_WILDCARD) {
        return IssueCodes.getMessageForIMP_AMBIGUOUS_WILDCARD(typeIdent, getName(), typeListStr.toString());
    } else if (this.issueCode == IssueCodes.IMP_AMBIGUOUS) {
        return IssueCodes.getMessageForIMP_AMBIGUOUS(typeIdent, getName(), typeListStr.toString());
    } else if (this.issueCode == IssueCodes.IMP_DUPLICATE_NAMESPACE) {
        return IssueCodes.getMessageForIMP_DUPLICATE_NAMESPACE(getName(), "stub");
    }
    return "Unknown ambiguous import issue: " + this.issueCode + " for " + context + ".";
}
Also used : Type(org.eclipse.n4js.ts.types.Type) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) TModule(org.eclipse.n4js.ts.types.TModule)

Example 7 with Type

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

the class InvisibleTypeOrVariableDescription method getMessage.

@Override
public String getMessage() {
    EObject objectOrProxy = getEObjectOrProxy();
    String name = getName().getLastSegment();
    if (objectOrProxy instanceof TFunction) {
        return IssueCodes.getMessageForVIS_ILLEGAL_FUN_ACCESS(name);
    } else if (objectOrProxy instanceof Type) {
        return IssueCodes.getMessageForVIS_ILLEGAL_TYPE_ACCESS(name);
    }
    return IssueCodes.getMessageForVIS_ILLEGAL_VARIABLE_ACCESS(name);
}
Also used : TFunction(org.eclipse.n4js.ts.types.TFunction) Type(org.eclipse.n4js.ts.types.Type) EObject(org.eclipse.emf.ecore.EObject)

Example 8 with Type

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

the class InternalTypeSystem method applyRuleSubtypeTypeTypeRef.

protected Result<Boolean> applyRuleSubtypeTypeTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeTypeRef left, final TypeTypeRef right) throws RuleFailedException {
    final TypeArgument leftTypeArg = left.getTypeArg();
    final TypeArgument rightTypeArg = right.getTypeArg();
    final boolean leftIsCtorRef = left.isConstructorRef();
    final boolean rightIsCtorRef = right.isConstructorRef();
    final boolean rightHasTypeRef = (rightTypeArg instanceof TypeRef);
    if (((!leftIsCtorRef) && rightIsCtorRef)) {
        /* fail */
        throwForExplicitFail();
    } else {
        if ((rightHasTypeRef && (!rightIsCtorRef))) {
            /* G |- leftTypeArg <: rightTypeArg */
            subtypeInternal(G, _trace_, leftTypeArg, rightTypeArg);
        } else {
            if ((rightHasTypeRef && rightIsCtorRef)) {
                final Type left_staticType = this.typeSystemHelper.getStaticType(G, left);
                final Type right_staticType = this.typeSystemHelper.getStaticType(G, right);
                final boolean leftHasCovariantConstructor = ((left_staticType instanceof TClassifier) && N4JSLanguageUtils.hasCovariantConstructor(((TClassifier) left_staticType)));
                /* !(leftTypeArg instanceof Wildcard || leftTypeArg instanceof ExistentialTypeRef || leftTypeArg instanceof ThisTypeRef) || leftHasCovariantConstructor */
                if (!((!(((leftTypeArg instanceof Wildcard) || (leftTypeArg instanceof ExistentialTypeRef)) || (leftTypeArg instanceof ThisTypeRef))) || leftHasCovariantConstructor)) {
                    sneakyThrowRuleFailedException("!(leftTypeArg instanceof Wildcard || leftTypeArg instanceof ExistentialTypeRef || leftTypeArg instanceof ThisTypeRef) || leftHasCovariantConstructor");
                }
                /* G |- leftTypeArg <: rightTypeArg */
                subtypeInternal(G, _trace_, leftTypeArg, rightTypeArg);
                if (((left_staticType instanceof TypeVariable) || (right_staticType instanceof TypeVariable))) {
                    /* left_staticType === right_staticType */
                    if (!(left_staticType == right_staticType)) {
                        sneakyThrowRuleFailedException("left_staticType === right_staticType");
                    }
                } else {
                    final TMethod leftCtor = this.containerTypesHelper.fromContext(RuleEnvironmentExtensions.getContextResource(G)).findConstructor(((ContainerType<?>) left_staticType));
                    final TMethod rightCtor = this.containerTypesHelper.fromContext(RuleEnvironmentExtensions.getContextResource(G)).findConstructor(((ContainerType<?>) right_staticType));
                    /* leftCtor!==null && rightCtor!==null */
                    if (!((leftCtor != null) && (rightCtor != null))) {
                        sneakyThrowRuleFailedException("leftCtor!==null && rightCtor!==null");
                    }
                    /* G |- leftCtor : var TypeRef leftCtorRef */
                    TypeRef leftCtorRef = null;
                    Result<TypeRef> result = typeInternal(G, _trace_, leftCtor);
                    checkAssignableTo(result.getFirst(), TypeRef.class);
                    leftCtorRef = (TypeRef) result.getFirst();
                    /* G |- rightCtor : var TypeRef rightCtorRef */
                    TypeRef rightCtorRef = null;
                    Result<TypeRef> result_1 = typeInternal(G, _trace_, rightCtor);
                    checkAssignableTo(result_1.getFirst(), TypeRef.class);
                    rightCtorRef = (TypeRef) result_1.getFirst();
                    final RuleEnvironment G_left = RuleEnvironmentExtensions.wrap(G);
                    final RuleEnvironment G_right = RuleEnvironmentExtensions.wrap(G);
                    this.typeSystemHelper.addSubstitutions(G_left, TypeExtensions.ref(left_staticType));
                    RuleEnvironmentExtensions.addThisType(G_left, TypeExtensions.ref(left_staticType));
                    this.typeSystemHelper.addSubstitutions(G_right, TypeExtensions.ref(right_staticType));
                    RuleEnvironmentExtensions.addThisType(G_right, TypeExtensions.ref(right_staticType));
                    /* G_left |- leftCtorRef ~> var TypeRef leftCtorRefSubst */
                    TypeRef leftCtorRefSubst = null;
                    Result<TypeArgument> result_2 = substTypeVariablesInternal(G_left, _trace_, leftCtorRef);
                    checkAssignableTo(result_2.getFirst(), TypeRef.class);
                    leftCtorRefSubst = (TypeRef) result_2.getFirst();
                    /* G_right |- rightCtorRef ~> var TypeRef rightCtorRefSubst */
                    TypeRef rightCtorRefSubst = null;
                    Result<TypeArgument> result_3 = substTypeVariablesInternal(G_right, _trace_, rightCtorRef);
                    checkAssignableTo(result_3.getFirst(), TypeRef.class);
                    rightCtorRefSubst = (TypeRef) result_3.getFirst();
                    /* G |- leftCtorRefSubst <: rightCtorRefSubst */
                    subtypeInternal(G, _trace_, leftCtorRefSubst, rightCtorRefSubst);
                }
            } else {
                /* G |~ leftTypeArg /\ var TypeRef upperBoundLeft */
                TypeRef upperBoundLeft = null;
                Result<TypeRef> result_4 = upperBoundInternal(G, _trace_, leftTypeArg);
                checkAssignableTo(result_4.getFirst(), TypeRef.class);
                upperBoundLeft = (TypeRef) result_4.getFirst();
                /* G |~ leftTypeArg \/ var TypeRef lowerBoundLeft */
                TypeRef lowerBoundLeft = null;
                Result<TypeRef> result_5 = lowerBoundInternal(G, _trace_, leftTypeArg);
                checkAssignableTo(result_5.getFirst(), TypeRef.class);
                lowerBoundLeft = (TypeRef) result_5.getFirst();
                /* G |~ rightTypeArg /\ var TypeRef upperBoundRight */
                TypeRef upperBoundRight = null;
                Result<TypeRef> result_6 = upperBoundInternal(G, _trace_, rightTypeArg);
                checkAssignableTo(result_6.getFirst(), TypeRef.class);
                upperBoundRight = (TypeRef) result_6.getFirst();
                /* G |~ rightTypeArg \/ var TypeRef lowerBoundRight */
                TypeRef lowerBoundRight = null;
                Result<TypeRef> result_7 = lowerBoundInternal(G, _trace_, rightTypeArg);
                checkAssignableTo(result_7.getFirst(), TypeRef.class);
                lowerBoundRight = (TypeRef) result_7.getFirst();
                /* G |- upperBoundLeft <: upperBoundRight */
                subtypeInternal(G, _trace_, upperBoundLeft, upperBoundRight);
                /* G |- lowerBoundRight <: lowerBoundLeft */
                subtypeInternal(G, _trace_, lowerBoundRight, lowerBoundLeft);
            }
        }
    }
    return new Result<Boolean>(true);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) TMethod(org.eclipse.n4js.ts.types.TMethod) 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) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment)

Example 9 with Type

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

the class InternalTypeSystem method applyRuleExpectedTypeInAssignmentExpression.

protected Result<TypeRef> applyRuleExpectedTypeInAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr, final Expression operand) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* { ! jsVariantHelper.isTypeAware(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
    {
        RuleFailedException previousFailure = null;
        try {
            boolean _isTypeAware = this.jsVariantHelper.isTypeAware(expr);
            boolean _not = (!_isTypeAware);
            /* ! jsVariantHelper.isTypeAware(expr) */
            if (!_not) {
                sneakyThrowRuleFailedException("! jsVariantHelper.isTypeAware(expr)");
            }
            Expression _lhs = expr.getLhs();
            boolean _tripleEquals = (operand == _lhs);
            if (_tripleEquals) {
                T = RuleEnvironmentExtensions.bottomTypeRef(G);
            } else {
                T = RuleEnvironmentExtensions.topTypeRef(G);
            }
        } catch (Exception e) {
            previousFailure = extractRuleFailedException(e);
            /* { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
            {
                try {
                    boolean _isTopOfDestructuringAssignment = DestructureUtils.isTopOfDestructuringAssignment(expr);
                    /* DestructureUtils.isTopOfDestructuringAssignment(expr) */
                    if (!_isTopOfDestructuringAssignment) {
                        sneakyThrowRuleFailedException("DestructureUtils.isTopOfDestructuringAssignment(expr)");
                    }
                    Expression _lhs_1 = expr.getLhs();
                    boolean _tripleEquals_1 = (operand == _lhs_1);
                    if (_tripleEquals_1) {
                        T = RuleEnvironmentExtensions.bottomTypeRef(G);
                    } else {
                        T = RuleEnvironmentExtensions.topTypeRef(G);
                    }
                } catch (Exception e_1) {
                    previousFailure = extractRuleFailedException(e_1);
                    /* { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
                    {
                        try {
                            AssignmentOperator _op = expr.getOp();
                            boolean _tripleEquals_2 = (_op == AssignmentOperator.ASSIGN);
                            /* expr.op===AssignmentOperator.ASSIGN */
                            if (!_tripleEquals_2) {
                                sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
                            }
                            Expression _lhs_2 = expr.getLhs();
                            boolean _tripleEquals_3 = (operand == _lhs_2);
                            if (_tripleEquals_3) {
                                T = RuleEnvironmentExtensions.bottomTypeRef(G);
                            } else {
                                /* G |- expr.lhs : T */
                                Expression _lhs_3 = expr.getLhs();
                                Result<TypeRef> result = typeInternal(G, _trace_, _lhs_3);
                                checkAssignableTo(result.getFirst(), TypeRef.class);
                                T = (TypeRef) result.getFirst();
                            }
                        } catch (Exception e_2) {
                            previousFailure = extractRuleFailedException(e_2);
                            /* { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
                            {
                                try {
                                    AssignmentOperator _op_1 = expr.getOp();
                                    boolean _tripleEquals_4 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
                                    /* expr.op===AssignmentOperator.ADD_ASSIGN */
                                    if (!_tripleEquals_4) {
                                        sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
                                    }
                                    Expression _lhs_4 = expr.getLhs();
                                    boolean _tripleEquals_5 = (operand == _lhs_4);
                                    if (_tripleEquals_5) {
                                        T = TypeUtils.createNonSimplifiedIntersectionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G));
                                    } else {
                                        /* G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef */
                                        Expression _lhs_5 = expr.getLhs();
                                        ParameterizedTypeRef lhsTypeRef = null;
                                        Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs_5);
                                        checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
                                        lhsTypeRef = (ParameterizedTypeRef) result_1.getFirst();
                                        Type _declaredType = lhsTypeRef.getDeclaredType();
                                        PrimitiveType _stringType = RuleEnvironmentExtensions.stringType(G);
                                        boolean _tripleEquals_6 = (_declaredType == _stringType);
                                        if (_tripleEquals_6) {
                                            T = RuleEnvironmentExtensions.anyTypeRef(G);
                                        } else {
                                            boolean _isNumeric = RuleEnvironmentExtensions.isNumeric(G, lhsTypeRef.getDeclaredType());
                                            if (_isNumeric) {
                                                T = RuleEnvironmentExtensions.numberTypeRef(G);
                                            } else {
                                                T = RuleEnvironmentExtensions.anyTypeRef(G);
                                            }
                                        }
                                    }
                                } catch (Exception e_3) {
                                    previousFailure = extractRuleFailedException(e_3);
                                    T = RuleEnvironmentExtensions.numberTypeRef(G);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return new Result<TypeRef>(T);
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) 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) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) AssignmentOperator(org.eclipse.n4js.n4JS.AssignmentOperator) 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 10 with Type

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

the class InternalTypeSystem method applyRuleTypeSuperLiteral.

protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
    /* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
    {
        RuleFailedException previousFailure = null;
        try {
            if ((containingMemberDecl == null)) {
                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
            } else {
                EObject _eContainer = containingMemberDecl.eContainer();
                Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
                final TClass containingClass = ((TClass) _definedType);
                final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
                TClassifier effectiveSuperClass = superClass;
                boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
                if (_isStaticPolyfill) {
                    effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
                }
                /* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                {
                    try {
                        /* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
                        if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
                            sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
                        }
                        boolean _isStatic = containingMemberDecl.isStatic();
                        if (_isStatic) {
                            TypeRef _createConstructorTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
                            }
                            T = _createConstructorTypeRef;
                        } else {
                            ParameterizedTypeRef _createTypeRef = null;
                            if (effectiveSuperClass != null) {
                                _createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
                            }
                            T = _createTypeRef;
                        }
                        if ((T != null)) {
                            T = TypeUtils.enforceNominalTyping(T);
                        }
                    } catch (Exception e) {
                        previousFailure = extractRuleFailedException(e);
                        /* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
                        {
                            try {
                                EObject _eContainer_1 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof ParameterizedCallExpression */
                                if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
                                }
                                if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
                                    final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
                                    ParameterizedTypeRef _createTypeRef_1 = null;
                                    if (ctor != null) {
                                        _createTypeRef_1 = TypeUtils.createTypeRef(ctor);
                                    }
                                    T = _createTypeRef_1;
                                } else {
                                    T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                                }
                            } catch (Exception e_1) {
                                previousFailure = extractRuleFailedException(e_1);
                                EObject _eContainer_2 = superLiteral.eContainer();
                                /* superLiteral.eContainer instanceof NewExpression */
                                if (!(_eContainer_2 instanceof NewExpression)) {
                                    sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e_2) {
            previousFailure = extractRuleFailedException(e_2);
            T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
        }
    }
    return new Result<TypeRef>(T);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) TMethod(org.eclipse.n4js.ts.types.TMethod) 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) NewExpression(org.eclipse.n4js.n4JS.NewExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

Type (org.eclipse.n4js.ts.types.Type)84 ContainerType (org.eclipse.n4js.ts.types.ContainerType)32 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)28 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)26 EObject (org.eclipse.emf.ecore.EObject)21 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)21 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)19 AnyType (org.eclipse.n4js.ts.types.AnyType)18 UndefinedType (org.eclipse.n4js.ts.types.UndefinedType)18 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)17 NullType (org.eclipse.n4js.ts.types.NullType)17 VoidType (org.eclipse.n4js.ts.types.VoidType)17 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)16 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)16 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)16 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)16 ModuleNamespaceVirtualType (org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType)16 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)16 Result (org.eclipse.xsemantics.runtime.Result)16 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)15