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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations