Search in sources :

Example 1 with ParameterizedTypeRefStructural

use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural in project n4js by eclipse.

the class InternalTypeSystem method applyRuleTypeObjectLiteral.

protected Result<TypeRef> applyRuleTypeObjectLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ObjectLiteral ol) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final ParameterizedTypeRefStructural ptr = TypeRefsFactory.eINSTANCE.createParameterizedTypeRefStructural();
    ptr.setDeclaredType(RuleEnvironmentExtensions.objectType(G));
    Type _definedType = ol.getDefinedType();
    ptr.setStructuralType(((TStructuralType) _definedType));
    ptr.setDefinedTypingStrategy(TypingStrategy.STRUCTURAL);
    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) ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural) 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) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 2 with ParameterizedTypeRefStructural

use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural in project n4js by eclipse.

the class TypeUtils method createResolvedThisTypeRef.

/**
 * Creates the corresponding plain {@link ParameterizedTypeRef} for a given {@link BoundThisTypeRef}. For example,
 * <code>~~this[C]</code> will be turned into <code>~~C</code>.
 */
public static ParameterizedTypeRef createResolvedThisTypeRef(BoundThisTypeRef boundThisTypeRef) {
    if (boundThisTypeRef == null) {
        throw new NullPointerException("Bound this type must not be null!");
    }
    if (boundThisTypeRef.getActualThisTypeRef() == null) {
        throw new NullPointerException("Actual this type of the provided bound this type must not be null!");
    }
    final List<TypeArgument> targsAsList = boundThisTypeRef.getActualThisTypeRef().getTypeArgs();
    final TypeArgument[] targs = targsAsList.toArray(new TypeArgument[targsAsList.size()]);
    final ParameterizedTypeRef resolvedTypeRef = createTypeRef(boundThisTypeRef.getActualThisTypeRef().getDeclaredType(), boundThisTypeRef.getTypingStrategy(), targs);
    if (!boundThisTypeRef.getTypeArgs().isEmpty()) {
        resolvedTypeRef.getTypeArgs().clear();
        resolvedTypeRef.getTypeArgs().addAll(TypeUtils.copyAll(boundThisTypeRef.getTypeArgs()));
    }
    // set structural typing info
    if (resolvedTypeRef instanceof ParameterizedTypeRefStructural)
        copyStructuralTypingInfo((ParameterizedTypeRefStructural) resolvedTypeRef, boundThisTypeRef);
    // copy other properties
    copyTypeModifiers(resolvedTypeRef, boundThisTypeRef);
    return resolvedTypeRef;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 3 with ParameterizedTypeRefStructural

use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural in project n4js by eclipse.

the class TypeUtils method createBoundThisTypeRef.

/**
 * Creates a new this type reference bound to the given actual type. This method also sets the typing strategy and
 * structural members. The returned type is normalized in terms of only the actual type is never structurally typed.
 * E.g., {@code ~this[~C]} is normalized to {@code ~this[C]}.
 *
 * cf. N4JS Spec, Constraints 63 (Normalized This Type)
 *
 * @param actualThisTypeRef
 *            must not be null
 */
public static BoundThisTypeRef createBoundThisTypeRef(ParameterizedTypeRef actualThisTypeRef) {
    if (actualThisTypeRef == null) {
        throw new NullPointerException("Actual this type must not be null!");
    }
    BoundThisTypeRef boundThisTypeRef = TypeRefsFactory.eINSTANCE.createBoundThisTypeRef();
    ParameterizedTypeRef clonedActualThisType = TypeUtils.copy(actualThisTypeRef);
    boundThisTypeRef.setActualThisTypeRef(clonedActualThisType);
    // IDEBUG-161: Constraints 66 (Type Inference
    boundThisTypeRef.setDefinedTypingStrategy(TypingStrategy.NOMINAL);
    // Heuristic for This-Keyword)
    if (actualThisTypeRef instanceof ParameterizedTypeRefStructural) {
        // set structural typing info
        copyStructuralTypingInfo(boundThisTypeRef, (ParameterizedTypeRefStructural) actualThisTypeRef);
        // and set clonedActualThisType to nominal type
        ((ParameterizedTypeRefStructural) clonedActualThisType).getAstStructuralMembers().clear();
        ((ParameterizedTypeRefStructural) clonedActualThisType).getGenStructuralMembers().clear();
        ((ParameterizedTypeRefStructural) clonedActualThisType).setStructuralType(null);
        ((ParameterizedTypeRefStructural) clonedActualThisType).setDefinedTypingStrategy(TypingStrategy.NOMINAL);
    }
    return boundThisTypeRef;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)

Example 4 with ParameterizedTypeRefStructural

use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural in project n4js by eclipse.

the class TypeUtils method createParameterizedTypeRefStructural.

/**
 * Creates a structural type reference for the given TStructuralType, e.g. <code>~Object with { ... }</code>.
 * <p>
 * For important details on structural type references, see {@link StructuralTypeRef}.
 */
public static ParameterizedTypeRefStructural createParameterizedTypeRefStructural(Type declaredType, TypingStrategy typingStrategy, TStructuralType structuralType) {
    final ParameterizedTypeRefStructural ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRefStructural();
    ref.setDeclaredType(declaredType);
    ref.setDefinedTypingStrategy(typingStrategy);
    ref.setStructuralType(structuralType);
    return ref;
}
Also used : ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural)

Example 5 with ParameterizedTypeRefStructural

use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural in project n4js by eclipse.

the class TypeUtils method createParameterizedTypeRefStructural.

/**
 * Creates a structural type reference for the given, programmatically generated members. Use this method only as a
 * last resort, as explained {@link StructuralTypeRef here}.
 * <p>
 * For important details on structural type references, see {@link StructuralTypeRef}.
 */
public static ParameterizedTypeRefStructural createParameterizedTypeRefStructural(Type declaredType, TypingStrategy typingStrategy, TStructMember... members) {
    final ParameterizedTypeRefStructural ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRefStructural();
    ref.setDeclaredType(declaredType);
    ref.setDefinedTypingStrategy(typingStrategy);
    ref.getGenStructuralMembers().addAll(Arrays.asList(members));
    return ref;
}
Also used : ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural)

Aggregations

ParameterizedTypeRefStructural (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural)9 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)7 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)5 EPackage (org.eclipse.emf.ecore.EPackage)3 FunctionTypeExpression (org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression)3 IntersectionTypeExpression (org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression)3 ThisTypeRefNominal (org.eclipse.n4js.ts.typeRefs.ThisTypeRefNominal)3 ThisTypeRefStructural (org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural)3 UnionTypeExpression (org.eclipse.n4js.ts.typeRefs.UnionTypeExpression)3 VersionedParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRef)3 VersionedParameterizedTypeRefStructural (org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRefStructural)3 Wildcard (org.eclipse.n4js.ts.typeRefs.Wildcard)3 TAnonymousFormalParameter (org.eclipse.n4js.ts.types.TAnonymousFormalParameter)3 TFormalParameter (org.eclipse.n4js.ts.types.TFormalParameter)3 TypeVariable (org.eclipse.n4js.ts.types.TypeVariable)3 Action (org.eclipse.xtext.Action)3 Parameter (org.eclipse.xtext.Parameter)3 ParserRule (org.eclipse.xtext.ParserRule)3 PropertyNameValuePair (org.eclipse.n4js.n4JS.PropertyNameValuePair)2 TaggedTemplateString (org.eclipse.n4js.n4JS.TaggedTemplateString)2