Minor. Improved usability of CustomTypeVariable API

This commit is contained in:
Andrey Breslav
2014-10-12 23:16:58 +04:00
parent 070a7d4d72
commit 8e8f41e228
3 changed files with 9 additions and 6 deletions
@@ -423,8 +423,8 @@ public class ConstraintSystemImpl implements ConstraintSystem {
// Foo >: T! // Foo >: T!
// both Foo and Foo? transform to Foo! here // both Foo and Foo? transform to Foo! here
if (TypesPackage.isFlexible(parameterType)) { if (TypesPackage.isFlexible(parameterType)) {
CustomTypeVariable typeVariable = parameterType.getCapability(CustomTypeVariable.class); CustomTypeVariable typeVariable = TypesPackage.getCustomTypeVariable(parameterType);
if (typeVariable != null && typeVariable.getIsTypeVariable()) { if (typeVariable != null) {
constrainingType = typeVariable.substitutionResult(constrainingType); constrainingType = typeVariable.substitutionResult(constrainingType);
} }
} }
@@ -47,3 +47,7 @@ public trait CustomTypeVariable : TypeCapability {
} }
public fun JetType.isCustomTypeVariable(): Boolean = this.getCapability(javaClass<CustomTypeVariable>())?.isTypeVariable ?: false public fun JetType.isCustomTypeVariable(): Boolean = this.getCapability(javaClass<CustomTypeVariable>())?.isTypeVariable ?: false
public fun JetType.getCustomTypeVariable(): CustomTypeVariable? =
this.getCapability(javaClass<CustomTypeVariable>())?.let {
if (it.isTypeVariable) it else null
}
@@ -187,9 +187,8 @@ public class TypeSubstitutor {
return TypeUtils.makeStarProjection(typeParameter); return TypeUtils.makeStarProjection(typeParameter);
case NO_CONFLICT: case NO_CONFLICT:
JetType substitutedType; JetType substitutedType;
if (TypesPackage.isCustomTypeVariable(type)) { CustomTypeVariable typeVariable = TypesPackage.getCustomTypeVariable(type);
CustomTypeVariable typeVariable = type.getCapability(CustomTypeVariable.class); if (typeVariable != null) {
assert typeVariable != null;
substitutedType = typeVariable.substitutionResult(replacement.getType()); substitutedType = typeVariable.substitutionResult(replacement.getType());
} }
else { else {