Search in sources :

Example 16 with Type

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

the class InternalTypeSystem method applyRuleUpperBoundParameterizedTypeRef.

protected Result<TypeRef> applyRuleUpperBoundParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef ptr) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    Type _declaredType = ptr.getDeclaredType();
    if ((_declaredType instanceof TypeVariable)) {
        T = ptr;
    } else {
        T = ptr;
    }
    return new Result<TypeRef>(T);
}
Also used : 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) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) 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 17 with Type

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

the class MemberRedefinitionUtils method findThisContextForConstructor.

/**
 * Returns the context type to be used as this binding (see
 * {@link N4JSTypeSystem#createRuleEnvironmentForContext(TypeRef, TypeRef, Resource) here} and
 * {@link RuleEnvironmentExtensions#addThisType(RuleEnvironment, TypeRef)} here) for checking constructor
 * compatibility.
 *
 * For example, given the following code
 *
 * <pre>
 * class C1 {
 *     constructor(@Spec spec: ~i~this) {}
 * }
 *
 * class C2 extends C1 {
 *     public field2;
 * }
 *
 * &#64;CovariantConstructor
 * class C3 extends C2 {
 *     public field3;
 * }
 *
 * class C4 extends C3 {
 *     // XPECT noerrors -->
 *     constructor(@Spec spec: ~i~this) { super(spec); }
 * }
 * </pre>
 *
 * When checking constructor compatibility in C4, we have to use class C3 as the 'this' context on right-hand side,
 * not class C1, because the addition of fields <code>field2</code> and <code>field3</code> does not break the
 * contract of the &#64;CovariantConstructor annotation. Therefore, we cannot simply use the containing type of the
 * right-hand side constructor as 'this' context. In the above example, we would call this method with C4 as
 * <code>baseContext</code> and C1's constructor as <code>ctor</code> and it would return C3 as the 'this' context
 * to use.
 */
public static final Type findThisContextForConstructor(Type baseContext, TMethod ctor) {
    final Type ctorContainer = ctor.getContainingType();
    if (!(baseContext instanceof TClass) || !(ctorContainer instanceof TClass)) {
        return ctorContainer;
    }
    final TClass ctorContainerCasted = (TClass) ctorContainer;
    final TClass baseContextCasted = (TClass) baseContext;
    if (N4JSLanguageUtils.hasCovariantConstructor(ctorContainerCasted)) {
        return ctorContainerCasted;
    }
    final List<TClass> superClassesUpToCtorContainer = new ArrayList<>();
    for (TClass superClass : new ExtendedClassesIterable(baseContextCasted)) {
        if (superClass != ctorContainerCasted) {
            superClassesUpToCtorContainer.add(superClass);
        } else {
            break;
        }
    }
    for (int i = superClassesUpToCtorContainer.size() - 1; i >= 0; i--) {
        final TClass superClass = superClassesUpToCtorContainer.get(i);
        if (N4JSLanguageUtils.hasCovariantConstructor(superClass)) {
            return superClass;
        }
    }
    return baseContext;
}
Also used : MemberType(org.eclipse.n4js.ts.types.MemberType) Type(org.eclipse.n4js.ts.types.Type) ArrayList(java.util.ArrayList) TClass(org.eclipse.n4js.ts.types.TClass) ExtendedClassesIterable(org.eclipse.n4js.ts.types.util.ExtendedClassesIterable)

Example 18 with Type

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

the class FunctionDefinitionImpl method setDefinedType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setDefinedType(Type newDefinedType) {
    Type oldDefinedType = definedType;
    definedType = newDefinedType;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.FUNCTION_DEFINITION__DEFINED_TYPE, oldDefinedType, definedType));
}
Also used : Type(org.eclipse.n4js.ts.types.Type) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 19 with Type

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

the class FunctionDefinitionImpl method getDefinedFunction.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public TFunction getDefinedFunction() {
    final Type defType = this.getDefinedType();
    TFunction _xifexpression = null;
    if ((defType instanceof TFunction)) {
        _xifexpression = ((TFunction) defType);
    }
    return _xifexpression;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TFunction(org.eclipse.n4js.ts.types.TFunction)

Example 20 with Type

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

the class JSDoc2ADocSpecProcessor method addMembers.

/**
 * This method iterates through all members of a N4JS type and creates corresponding {@link SpecFile}s from them.
 * During this process, member tests are linked if available.
 */
private void addMembers(SpecInfo specInfo, Map<String, SpecSection> specsByKey, TreeMap<String, SpecFile> specChangeSet) {
    IdentifiableElement element = specInfo.specElementRef.identifiableElement;
    if (element instanceof TN4Classifier) {
        addMembers(specInfo, (TN4Classifier) element, specsByKey, specChangeSet);
        Type pfaElement = specInfo.specElementRef.polyfillAware;
        if (pfaElement instanceof TN4Classifier) {
            addMembers(specInfo, (TN4Classifier) pfaElement, specsByKey, specChangeSet);
        }
    }
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TN4Classifier(org.eclipse.n4js.ts.types.TN4Classifier) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement)

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