Search in sources :

Example 21 with TClass

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

the class N4JSASTUtils method getOwnOrSuperCtor.

private static TMember getOwnOrSuperCtor(final ContainerType<?> ownerOfField) {
    TClass klass = (TClass) (ownerOfField instanceof TClass ? ownerOfField : null);
    while (null != klass) {
        final TMember ctor = klass.findOwnedMember(CONSTRUCTOR);
        if (null != ctor) {
            return ctor;
        }
        final ParameterizedTypeRef superClassRef = klass.getSuperClassRef();
        if (null == superClassRef) {
            klass = null;
        } else {
            final Type declaredType = superClassRef.getDeclaredType();
            klass = (TClass) (declaredType instanceof TClass ? declaredType : null);
        }
    }
    return null;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass)

Example 22 with TClass

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

the class N4JSResourceDescriptionStrategy method internalCreateEObjectDescription.

/**
 * Create EObjectDescriptions for elements for which N4JSQualifiedNameProvider provides a FQN; elements with a FQN
 * of <code>null</code> will be ignored.
 */
private void internalCreateEObjectDescription(Type type, IAcceptor<IEObjectDescription> acceptor) {
    final String exportedName = type.getExportedName();
    final String typeName = exportedName != null ? exportedName : type.getName();
    if (typeName != null && typeName.length() != 0) {
        QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type);
        if (qualifiedName != null) {
            // e.g. non-exported declared functions will return null for FQN
            Map<String, String> userData = Collections.singletonMap(ACCESS_MODIFIERY_KEY, String.valueOf(type.getTypeAccessModifier().ordinal()));
            // Add additional user data for descriptions representing a TClass
            if (type instanceof TClass) {
                final TClass tClass = (TClass) type;
                userData = createClassUserData(userData, tClass);
            }
            IEObjectDescription eod = N4JSEObjectDescription.create(qualifiedName, type, userData);
            acceptor.accept(eod);
        }
    }
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) TClass(org.eclipse.n4js.ts.types.TClass) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 23 with TClass

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

the class N4JSMemberRedefinitionValidator method checkMemberRedefinitions.

/**
 * Checks constraints defined in chapter 5.4. Redefinition of Members.
 */
@Check
public void checkMemberRedefinitions(N4ClassifierDefinition n4ClassifierDefinition) {
    if (!(n4ClassifierDefinition.getDefinedType() instanceof TClassifier)) {
        // wrongly parsed
        return;
    }
    TClassifier tClassifier = (TClassifier) n4ClassifierDefinition.getDefinedType();
    getContext().put(TClassifier.class, tClassifier);
    RuleEnvironment g = RuleEnvironmentExtensions.newRuleEnvironment(tClassifier);
    getContext().put(RuleEnvironment.class, g);
    // the context for type variables
    ParameterizedTypeRef classTypeRef = TypeUtils.createTypeRef(tClassifier);
    getContext().put(TYPE_VAR_CONTEXT, classTypeRef);
    MemberCube memberCube = createMemberValidationList();
    final boolean isClass = tClassifier instanceof TClass;
    final Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef = new HashMap<>();
    for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
        MemberMatrix mm = entry.getValue();
        // Set to collect all owned members that are lacking an override annotation.
        Collection<TMember> membersMissingOverrideAnnotation = new HashSet<>();
        if (isClass) {
            constraints_67_MemberOverride_checkEntry(mm, membersMissingOverrideAnnotation);
        }
        if (mm.hasImplemented()) {
            // first mix in
            if (holdConstraints_68_Consumption(mm)) {
                // then check if everything is implemented
                constraints_69_Implementation(mm, membersMissingOverrideAnnotation);
            }
        }
        constraints_60_InheritedConsumedCovariantSpecConstructor(tClassifier, mm);
        constraints_66_NonOverride(mm);
        constraints_42_45_46_AbstractMember(mm, nonAccessibleAbstractMembersBySuperTypeRef);
        unusedGenericTypeVariable(mm);
        checkUnpairedAccessorConsumption(mm, n4ClassifierDefinition);
        checkUnpairedAccessorFilling(mm, n4ClassifierDefinition);
        messageMissingOverrideAnnotation(mm, membersMissingOverrideAnnotation);
    }
    final boolean foundImpossibleExtendsImplements = !nonAccessibleAbstractMembersBySuperTypeRef.isEmpty();
    if (foundImpossibleExtendsImplements) {
        messageImpossibleExtendsImplements(n4ClassifierDefinition, nonAccessibleAbstractMembersBySuperTypeRef);
    }
    if (!foundImpossibleExtendsImplements) {
        // avoid consequential errors
        constraints_41_AbstractClass(tClassifier, memberCube);
    }
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) NameStaticPair(org.eclipse.n4js.ts.types.util.NameStaticPair) MemberList(org.eclipse.n4js.ts.types.util.MemberList) HashMap(java.util.HashMap) MemberMatrix(org.eclipse.n4js.validation.validators.utils.MemberMatrix) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) MemberCube(org.eclipse.n4js.validation.validators.utils.MemberCube) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) TMember(org.eclipse.n4js.ts.types.TMember) TClass(org.eclipse.n4js.ts.types.TClass) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 24 with TClass

use of org.eclipse.n4js.ts.types.TClass 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);
}
Also used : 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) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) SuperLiteral(org.eclipse.n4js.n4JS.SuperLiteral) N4ClassDeclaration(org.eclipse.n4js.n4JS.N4ClassDeclaration) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) 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) EObject(org.eclipse.emf.ecore.EObject) ThisTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) FunctionTypeExprOrRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeExprOrRef) TClass(org.eclipse.n4js.ts.types.TClass)

Example 25 with TClass

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

the class MemberRedefinitionUtils method getFilledClass.

/**
 * Returns the class which is filled by the given static polyfill class definition.
 *
 * Returns {@code null} if staticPolyfillDefinition isn't a valid static polyfill class definition.
 */
public static TClass getFilledClass(N4ClassDefinition staticPolyfillDefinition) {
    if (!(staticPolyfillDefinition.getDefinedType() instanceof TClassifier)) {
        return null;
    }
    TClassifier classifier = (TClassifier) staticPolyfillDefinition.getDefinedType();
    if (!classifier.isStaticPolyfill()) {
        return null;
    }
    ParameterizedTypeRef superClassTypeRef = Iterables.getFirst(classifier.getSuperClassifierRefs(), null);
    if (null == superClassTypeRef) {
        return null;
    }
    Type superClassType = superClassTypeRef.getDeclaredType();
    if (superClassType instanceof TClass && ((TClass) superClassType).getContainingModule().isStaticPolyfillAware()) {
        return (TClass) superClassType;
    } else {
        return null;
    }
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) MemberType(org.eclipse.n4js.ts.types.MemberType) Type(org.eclipse.n4js.ts.types.Type) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

TClass (org.eclipse.n4js.ts.types.TClass)27 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)16 Type (org.eclipse.n4js.ts.types.Type)15 TMember (org.eclipse.n4js.ts.types.TMember)11 TClassifier (org.eclipse.n4js.ts.types.TClassifier)10 TInterface (org.eclipse.n4js.ts.types.TInterface)9 TMethod (org.eclipse.n4js.ts.types.TMethod)8 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 EObject (org.eclipse.emf.ecore.EObject)5 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)5 TField (org.eclipse.n4js.ts.types.TField)5 MemberList (org.eclipse.n4js.ts.types.util.MemberList)5 Collections.emptyList (java.util.Collections.emptyList)4 HashMap (java.util.HashMap)4 Stream (java.util.stream.Stream)4 N4InterfaceDeclaration (org.eclipse.n4js.n4JS.N4InterfaceDeclaration)4 Script (org.eclipse.n4js.n4JS.Script)4