use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class InternalTypeSystem method substTypeVariablesImpl.
protected Result<TypeArgument> substTypeVariablesImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeTypeRef typeRef) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeArgument> _result_ = applyRuleSubstTypeVariablesInTypeTypeRef(G, _subtrace_, typeRef);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("substTypeVariablesInTypeTypeRef") + stringRepForEnv(G) + " |- " + stringRep(typeRef) + " ~> " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleSubstTypeVariablesInTypeTypeRef) {
substTypeVariablesThrowException(ruleName("substTypeVariablesInTypeTypeRef") + stringRepForEnv(G) + " |- " + stringRep(typeRef) + " ~> " + "TypeTypeRef", SUBSTTYPEVARIABLESINTYPETYPEREF, e_applyRuleSubstTypeVariablesInTypeTypeRef, typeRef, new ErrorInformation[] { new ErrorInformation(typeRef) });
return null;
}
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class ParameterizedTypeRefStructural_IMImpl method getTypeRefAsString.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getTypeRefAsString() {
TypingStrategy _typingStrategy = this.getTypingStrategy();
Type _declaredType = this.getDeclaredType();
String _rawTypeAsString = null;
if (_declaredType != null) {
_rawTypeAsString = _declaredType.getRawTypeAsString();
}
String _plus = (_typingStrategy + _rawTypeAsString);
String _xifexpression = null;
boolean _isEmpty = this.getTypeArgs().isEmpty();
if (_isEmpty) {
_xifexpression = "";
} else {
final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {
public String apply(final TypeArgument it) {
return it.getTypeRefAsString();
}
};
String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
String _plus_1 = ("<" + _join);
_xifexpression = (_plus_1 + ">");
}
String _plus_2 = (_plus + _xifexpression);
String _xifexpression_1 = null;
boolean _isEmpty_1 = this.getStructuralMembers().isEmpty();
if (_isEmpty_1) {
_xifexpression_1 = "";
} else {
final Function1<TStructMember, String> _function_1 = new Function1<TStructMember, String>() {
public String apply(final TStructMember it) {
return it.getMemberAsString();
}
};
String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TStructMember, String>map(this.getStructuralMembers(), _function_1), "; ");
String _plus_3 = (" with { " + _join_1);
String _plus_4 = (_plus_3 + " }");
String _xifexpression_2 = null;
boolean _isEmpty_2 = this.getPostponedSubstitutions().isEmpty();
if (_isEmpty_2) {
_xifexpression_2 = "";
} else {
final Function1<TypeVariableMapping, String> _function_2 = new Function1<TypeVariableMapping, String>() {
public String apply(final TypeVariableMapping it) {
String _typeAsString = it.getTypeVar().getTypeAsString();
String _plus = (_typeAsString + "->");
String _typeRefAsString = it.getTypeArg().getTypeRefAsString();
return (_plus + _typeRefAsString);
}
};
String _join_2 = IterableExtensions.join(XcoreEListExtensions.<TypeVariableMapping, String>map(this.getPostponedSubstitutions(), _function_2), ", ");
String _plus_5 = (" [[" + _join_2);
_xifexpression_2 = (_plus_5 + "]]");
}
_xifexpression_1 = (_plus_4 + _xifexpression_2);
}
return (_plus_2 + _xifexpression_1);
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument 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.TypeArgument in project n4js by eclipse.
the class TypeUtils method createGeneratorTypeRef.
/**
* For a given generator function, a return type is created of the form {@code Generator<TYield,TReturn,TNext>} in
* case no type or a type other than Generator is declared. In case no type is declared, the types TYield and
* TReturn are inferred from the yield expressions and return statements in the body. The type TNext is
* <code>any</code>. In case a type other than <code>Generator</code> is declared, type type TYield becomes the
* declared type. The type TReturn is still inferred from the return statements. In case the declared type is
* <code>void</code>, both TYield and TReturn become the type <code>undefined</code>.
*
* <p>
* WARNING: this method will resolve proxies in 'successType' (in order to check if it points to type 'void')
*/
public static ParameterizedTypeRef createGeneratorTypeRef(BuiltInTypeScope scope, FunctionDefinition funDef) {
Objects.requireNonNull(scope);
Objects.requireNonNull(funDef);
TypeRef definedReturn = funDef.getReturnTypeRef();
TypeArgument tYield;
TypeArgument tReturn = inferReturnTypeFromReturns(funDef, scope);
if (definedReturn == null) {
tYield = inferYieldExprTypeFromYields(funDef, scope);
} else {
tYield = definedReturn;
if (TypeUtils.isVoid(definedReturn)) {
tReturn = scope.getUndefinedTypeRef();
}
}
ParameterizedTypeRef generatorTypeRef = createGeneratorTypeRef(scope, tYield, tReturn, null);
return generatorTypeRef;
}
use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.
the class TypeUtils method createTypeRef.
/**
* Same as {@link #createTypeRef(Type, TypingStrategy, TypeArgument...)}, but will create unbounded wildcards as
* type arguments if fewer type arguments are provided than the number of type parameters of the given declared.
*/
public static ParameterizedTypeRef createTypeRef(Type declaredType, TypingStrategy typingStrategy, boolean autoCreateTypeArgs, TypeArgument... typeArgs) {
if (declaredType == null) {
// avoid creating a bogus ParameterizedTypeRef with a 'declaredType' property of 'null'
return null;
}
final ParameterizedTypeRef ref;
if (declaredType instanceof TFunction) {
ref = TypeRefsFactory.eINSTANCE.createFunctionTypeRef();
// } else if (declaredType instanceof TStructuralType) {
// throw new IllegalArgumentException("a TStructuralType should not be used as declared type of a TypeRef");
} else if (typingStrategy != TypingStrategy.DEFAULT && typingStrategy != TypingStrategy.NOMINAL) {
ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRefStructural();
} else {
ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
}
ref.setDefinedTypingStrategy(typingStrategy);
ref.setDeclaredType(declaredType);
final EList<TypeArgument> refTypeArgs = ref.getTypeArgs();
for (TypeArgument typeArg : typeArgs) {
refTypeArgs.add(TypeUtils.copyIfContained(typeArg));
}
if (autoCreateTypeArgs) {
final int l = declaredType.getTypeVars().size();
for (int i = refTypeArgs.size(); i < l; i++) {
refTypeArgs.add(createWildcard());
}
}
return ref;
}
Aggregations