TypeProjection interface extracted

This commit is contained in:
Andrey Breslav
2013-09-28 12:02:21 +02:00
parent b98ec9f56b
commit 3960426698
35 changed files with 167 additions and 115 deletions
@@ -165,7 +165,7 @@ public class TypeDeserializer {
}
private TypeProjection typeProjection(ProtoBuf.Type.Argument proto) {
return new TypeProjection(
return new TypeProjectionImpl(
variance(proto.getProjection()),
type(proto.getType())
);
@@ -64,7 +64,7 @@ public class FunctionDescriptorUtil {
for (int i = 0; i < typeArgumentsSize; i++) {
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
JetType typeArgument = typeArguments.get(i);
result.put(typeParameterDescriptor.getTypeConstructor(), new TypeProjection(typeArgument));
result.put(typeParameterDescriptor.getTypeConstructor(), new TypeProjectionImpl(typeArgument));
}
return result;
}
@@ -268,7 +268,7 @@ public class TypeResolver {
arguments.add(SubstitutionUtils.makeStarProjection(parameterDescriptor));
}
else {
arguments.add(new TypeProjection(OUT_VARIANCE, ErrorUtils.createErrorType("*")));
arguments.add(new TypeProjectionImpl(OUT_VARIANCE, ErrorUtils.createErrorType("*")));
}
}
else {
@@ -286,7 +286,7 @@ public class TypeResolver {
}
}
}
arguments.add(new TypeProjection(kind, type));
arguments.add(new TypeProjectionImpl(kind, type));
}
}
return arguments;
@@ -100,7 +100,7 @@ public class CallResolverUtil {
List<TypeProjection> arguments = type.getArguments();
List<TypeProjection> newArguments = Lists.newArrayList();
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
newArguments.add(new TypeProjection(Variance.INVARIANT, DONT_CARE));
newArguments.add(new TypeProjectionImpl(Variance.INVARIANT, DONT_CARE));
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
}
@@ -156,7 +156,7 @@ public class CallResolverUtil {
}
List<TypeProjection> fakeTypeArguments = Lists.newArrayList();
for (TypeProjection typeProjection : receiverType.getArguments()) {
fakeTypeArguments.add(new TypeProjection(typeProjection.getProjectionKind(), DONT_CARE));
fakeTypeArguments.add(new TypeProjectionImpl(typeProjection.getProjectionKind(), DONT_CARE));
}
return new JetTypeImpl(
receiverType.getAnnotations(), receiverType.getConstructor(), receiverType.isNullable(),
@@ -885,7 +885,7 @@ public class CandidateResolver {
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
TypeParameterDescriptor typeParameter = typeParameters.get(i);
JetType typeArgument = typeArguments.get(i);
context.put(typeParameter.getTypeConstructor(), new TypeProjection(typeArgument));
context.put(typeParameter.getTypeConstructor(), new TypeProjectionImpl(typeArgument));
}
TypeSubstitutor substitutor = TypeSubstitutor.create(context);
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
@@ -50,7 +50,7 @@ public class ConstraintsUtil {
ArrayList<Map<TypeConstructor, TypeProjection>> substitutionContexts = Lists.newArrayList();
for (JetType type : conflictingTypes) {
Map<TypeConstructor, TypeProjection> context = Maps.newLinkedHashMap();
context.put(firstConflictingParameter.getTypeConstructor(), new TypeProjection(type));
context.put(firstConflictingParameter.getTypeConstructor(), new TypeProjectionImpl(type));
substitutionContexts.add(context);
}
@@ -59,7 +59,7 @@ public class ConstraintsUtil {
JetType safeType = getSafeValue(constraintSystem, typeParameter);
for (Map<TypeConstructor, TypeProjection> context : substitutionContexts) {
TypeProjection typeProjection = new TypeProjection(safeType);
TypeProjection typeProjection = new TypeProjectionImpl(safeType);
context.put(typeParameter.getTypeConstructor(), typeProjection);
}
}
@@ -158,7 +158,7 @@ public class CastDiagnosticsUtil {
if (supertypeWithVariables != null) {
// Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo
TypeUnifier.UnificationResult solution = TypeUnifier.unify(
new TypeProjection(supertype), new TypeProjection(supertypeWithVariables),
new TypeProjectionImpl(supertype), new TypeProjectionImpl(supertypeWithVariables),
new Predicate<TypeConstructor>() {
@Override
public boolean apply(TypeConstructor typeConstructor) {
@@ -70,15 +70,15 @@ public class TypeUnifier {
Variance knownProjectionKind = knownProjection.getProjectionKind();
Variance withVariablesProjectionKind = projectWithVariables.getProjectionKind();
if (knownProjectionKind == withVariablesProjectionKind && knownProjectionKind != Variance.INVARIANT) {
doUnify(new TypeProjection(known), new TypeProjection(withVariables), isVariable, result);
doUnify(new TypeProjectionImpl(known), new TypeProjectionImpl(withVariables), isVariable, result);
return;
}
// Foo? ~ X? => Foo ~ X
if (known.isNullable() && withVariables.isNullable()) {
doUnify(
new TypeProjection(knownProjectionKind, TypeUtils.makeNotNullable(known)),
new TypeProjection(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
new TypeProjectionImpl(knownProjectionKind, TypeUtils.makeNotNullable(known)),
new TypeProjectionImpl(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
isVariable,
result
);
@@ -101,7 +101,7 @@ public class TypeUnifier {
// Foo ~ X => x |-> Foo
TypeConstructor maybeVariable = withVariables.getConstructor();
if (isVariable.apply(maybeVariable)) {
result.put(maybeVariable, new TypeProjection(knownProjectionKind, known));
result.put(maybeVariable, new TypeProjectionImpl(knownProjectionKind, known));
return;
}