TypeProjection interface extracted
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeProjectionImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -95,17 +96,17 @@ public class FunctionTypesUtil {
|
||||
|
||||
List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(arity + 2);
|
||||
if (receiverParameter != null) {
|
||||
typeArguments.add(new TypeProjection(receiverParameter.getType()));
|
||||
typeArguments.add(new TypeProjectionImpl(receiverParameter.getType()));
|
||||
}
|
||||
else if (kFunction && expectedThisObject != null) {
|
||||
typeArguments.add(new TypeProjection(expectedThisObject.getType()));
|
||||
typeArguments.add(new TypeProjectionImpl(expectedThisObject.getType()));
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor parameter : descriptor.getValueParameters()) {
|
||||
typeArguments.add(new TypeProjection(parameter.getType()));
|
||||
typeArguments.add(new TypeProjectionImpl(parameter.getType()));
|
||||
}
|
||||
|
||||
typeArguments.add(new TypeProjection(descriptor.getReturnType()));
|
||||
typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));
|
||||
|
||||
ClassDescriptor classDescriptor;
|
||||
if (kFunction) {
|
||||
|
||||
@@ -584,7 +584,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private ClassifierDescriptor getSubstituteForTypeParameterOf(@NotNull ClassDescriptor trait, int index) {
|
||||
TypeParameterDescriptor listTypeParameter = trait.getTypeConstructor().getParameters().get(index);
|
||||
TypeSubstitutor deepSubstitutor = SubstitutionUtils.buildDeepSubstitutor(descriptor.getDefaultType());
|
||||
TypeProjection substitute = deepSubstitutor.substitute(new TypeProjection(listTypeParameter.getDefaultType()));
|
||||
TypeProjection substitute = deepSubstitutor.substitute(new TypeProjectionImpl(listTypeParameter.getDefaultType()));
|
||||
assert substitute != null : "Couldn't substitute: " + descriptor;
|
||||
ClassifierDescriptor classifier = substitute.getType().getConstructor().getDeclarationDescriptor();
|
||||
assert classifier != null : "No classifier: " + substitute.getType();
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeProjectionImpl;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -75,7 +75,7 @@ class PropagationHeuristics {
|
||||
arrayTypeFromSuper.getAnnotations(),
|
||||
arrayTypeFromSuper.getConstructor(),
|
||||
arrayTypeFromSuper.isNullable(),
|
||||
Arrays.asList(new TypeProjection(Variance.OUT_VARIANCE, elementTypeInSuper)),
|
||||
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
|
||||
JetScope.EMPTY);
|
||||
|
||||
data.reportError("Return type is not a subtype of overridden method. " +
|
||||
|
||||
+1
-1
@@ -451,7 +451,7 @@ public class SignaturesPropagationData {
|
||||
JetType type = modifyTypeAccordingToSuperMethods(argumentType, argTypesFromSuper, TYPE_ARGUMENT);
|
||||
Variance projectionKind = calculateArgumentProjectionKindFromSuper(argument, projectionsFromSuper);
|
||||
|
||||
resultArguments.add(new TypeProjection(projectionKind, type));
|
||||
resultArguments.add(new TypeProjectionImpl(projectionKind, type));
|
||||
}
|
||||
return resultArguments;
|
||||
}
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
else {
|
||||
altProjectionKind = projectionKind;
|
||||
}
|
||||
return new TypeProjection(altProjectionKind, alternativeArgumentType);
|
||||
return new TypeProjectionImpl(altProjectionKind, alternativeArgumentType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -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++) {
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ public class TypeUnifierTest extends JetLiteFixture {
|
||||
assert typeReference != null;
|
||||
JetType type = typeResolver.resolveType(withX, typeReference, JetTestUtils.DUMMY_TRACE, true);
|
||||
|
||||
return new TypeProjection(getProjectionKind(typeStr, projection), type);
|
||||
return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type);
|
||||
}
|
||||
|
||||
private static Variance getProjectionKind(String typeStr, JetTypeProjection projection) {
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeProjectionImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.*;
|
||||
@@ -263,7 +264,7 @@ public final class DescriptorResolverUtils {
|
||||
for (Map.Entry<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameter : originalToAltTypeParameters
|
||||
.entrySet()) {
|
||||
typeSubstitutionContext.put(originalToAltTypeParameter.getKey().getTypeConstructor(),
|
||||
new TypeProjection(originalToAltTypeParameter.getValue().getDefaultType()));
|
||||
new TypeProjectionImpl(originalToAltTypeParameter.getValue().getDefaultType()));
|
||||
}
|
||||
return TypeSubstitutor.create(typeSubstitutionContext);
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeProjectionImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -157,7 +157,7 @@ public final class JavaAnnotationArgumentResolver {
|
||||
ClassDescriptor jlClass = classResolver.resolveClass(JL_CLASS_FQ_NAME, IGNORE_KOTLIN_SOURCES);
|
||||
if (jlClass == null) return null;
|
||||
|
||||
List<TypeProjection> arguments = Collections.singletonList(new TypeProjection(type));
|
||||
List<TypeProjectionImpl> arguments = Collections.singletonList(new TypeProjectionImpl(type));
|
||||
JetTypeImpl javaClassType = new JetTypeImpl(
|
||||
jlClass.getAnnotations(),
|
||||
jlClass.getTypeConstructor(),
|
||||
|
||||
+5
-5
@@ -51,7 +51,7 @@ public class JavaTypeTransformer {
|
||||
@NotNull TypeUsage howThisTypeIsUsed
|
||||
) {
|
||||
if (!(type instanceof JavaWildcardType)) {
|
||||
return new TypeProjection(transformToType(type, howThisTypeIsUsed, typeVariableResolver));
|
||||
return new TypeProjectionImpl(transformToType(type, howThisTypeIsUsed, typeVariableResolver));
|
||||
}
|
||||
|
||||
JavaWildcardType wildcardType = (JavaWildcardType) type;
|
||||
@@ -62,7 +62,7 @@ public class JavaTypeTransformer {
|
||||
|
||||
Variance variance = wildcardType.isExtends() ? OUT_VARIANCE : IN_VARIANCE;
|
||||
|
||||
return new TypeProjection(variance, transformToType(bound, UPPER_BOUND, typeVariableResolver));
|
||||
return new TypeProjectionImpl(variance, transformToType(bound, UPPER_BOUND, typeVariableResolver));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -181,7 +181,7 @@ public class JavaTypeTransformer {
|
||||
Variance projectionKind = parameter.getVariance() == OUT_VARIANCE || howThisTypeIsUsed == SUPERTYPE
|
||||
? INVARIANT
|
||||
: OUT_VARIANCE;
|
||||
arguments.add(new TypeProjection(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType()));
|
||||
arguments.add(new TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -190,7 +190,7 @@ public class JavaTypeTransformer {
|
||||
if (parameters.size() != javaTypeArguments.size()) {
|
||||
// Most of the time this means there is an error in the Java code
|
||||
for (TypeParameterDescriptor parameter : parameters) {
|
||||
arguments.add(new TypeProjection(ErrorUtils.createErrorType(parameter.getName().asString())));
|
||||
arguments.add(new TypeProjectionImpl(ErrorUtils.createErrorType(parameter.getName().asString())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -204,7 +204,7 @@ public class JavaTypeTransformer {
|
||||
|
||||
if (typeProjection.getProjectionKind() == typeParameterDescriptor.getVariance()) {
|
||||
// remove redundant 'out' and 'in'
|
||||
arguments.add(new TypeProjection(INVARIANT, typeProjection.getType()));
|
||||
arguments.add(new TypeProjectionImpl(INVARIANT, typeProjection.getType()));
|
||||
}
|
||||
else {
|
||||
arguments.add(typeProjection);
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public class SingleAbstractMethodUtils {
|
||||
Variance kind = argument.getProjectionKind();
|
||||
if (kind != INVARIANT && variance != INVARIANT) {
|
||||
if (kind == variance) {
|
||||
arguments.add(new TypeProjection(argument.getType()));
|
||||
arguments.add(new TypeProjectionImpl(argument.getType()));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.List;
|
||||
public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor, ClassOrNamespaceDescriptor {
|
||||
|
||||
@NotNull
|
||||
JetScope getMemberScope(List<TypeProjection> typeArguments);
|
||||
JetScope getMemberScope(List<? extends TypeProjection> typeArguments);
|
||||
|
||||
@NotNull
|
||||
JetScope getUnsubstitutedInnerClassesScope();
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
public JetScope getMemberScope(List<? extends TypeProjection> typeArguments) {
|
||||
assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Illegal number of type arguments: expected "
|
||||
+ getTypeConstructor().getParameters().size() + " but was " + typeArguments.size()
|
||||
+ " for " + getTypeConstructor() + " " + getTypeConstructor().getParameters();
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
public JetScope getMemberScope(List<? extends TypeProjection> typeArguments) {
|
||||
assert typeArguments.size() == typeConstructor.getParameters().size() : typeArguments;
|
||||
if (typeConstructor.getParameters().isEmpty()) {
|
||||
return memberDeclarations;
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
public JetScope getMemberScope(List<? extends TypeProjection> typeArguments) {
|
||||
JetScope memberScope = original.getMemberScope(typeArguments);
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return memberScope;
|
||||
|
||||
@@ -261,7 +261,7 @@ public class OverridingUtil {
|
||||
TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
|
||||
substitutionContext.put(
|
||||
superTypeParameter.getTypeConstructor(),
|
||||
new TypeProjection(subTypeParameter.getDefaultType()));
|
||||
new TypeProjectionImpl(subTypeParameter.getDefaultType()));
|
||||
}
|
||||
return TypeSubstitutor.create(substitutionContext);
|
||||
}
|
||||
|
||||
+3
-3
@@ -126,9 +126,9 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
};
|
||||
|
||||
public ConstraintSystemImpl() {
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjectionImpl(
|
||||
TypeUtils.CANT_INFER_TYPE_PARAMETER));
|
||||
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(TypeUtils.DONT_CARE));
|
||||
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjectionImpl(TypeUtils.DONT_CARE));
|
||||
}
|
||||
|
||||
private TypeSubstitutor createTypeSubstitutorWithDefaultForUnknownTypeParameter(@Nullable final TypeProjection defaultTypeProjection) {
|
||||
@@ -142,7 +142,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
if (typeParameterBounds.containsKey(descriptor)) {
|
||||
JetType value = getTypeBounds(descriptor).getValue();
|
||||
if (value != null && !TypeUtils.equalsOrContainsAsArgument(value, TypeUtils.DONT_CARE)) {
|
||||
return new TypeProjection(value);
|
||||
return new TypeProjectionImpl(value);
|
||||
}
|
||||
return defaultTypeProjection;
|
||||
}
|
||||
|
||||
@@ -219,20 +219,20 @@ public class CommonSupertypes {
|
||||
JetType intersection = TypeUtils.intersect(JetTypeChecker.INSTANCE, ins);
|
||||
if (intersection == null) {
|
||||
if (outs != null) {
|
||||
return new TypeProjection(OUT_VARIANCE, commonSupertype(outs));
|
||||
return new TypeProjectionImpl(OUT_VARIANCE, commonSupertype(outs));
|
||||
}
|
||||
return new TypeProjection(OUT_VARIANCE, commonSupertype(parameterDescriptor.getUpperBounds()));
|
||||
return new TypeProjectionImpl(OUT_VARIANCE, commonSupertype(parameterDescriptor.getUpperBounds()));
|
||||
}
|
||||
Variance projectionKind = variance == IN_VARIANCE ? Variance.INVARIANT : IN_VARIANCE;
|
||||
return new TypeProjection(projectionKind, intersection);
|
||||
return new TypeProjectionImpl(projectionKind, intersection);
|
||||
}
|
||||
else if (outs != null) {
|
||||
Variance projectionKind = variance == OUT_VARIANCE ? Variance.INVARIANT : OUT_VARIANCE;
|
||||
return new TypeProjection(projectionKind, commonSupertype(outs));
|
||||
return new TypeProjectionImpl(projectionKind, commonSupertype(outs));
|
||||
}
|
||||
else {
|
||||
Variance projectionKind = variance == OUT_VARIANCE ? Variance.INVARIANT : OUT_VARIANCE;
|
||||
return new TypeProjection(projectionKind, commonSupertype(parameterDescriptor.getUpperBounds()));
|
||||
return new TypeProjectionImpl(projectionKind, commonSupertype(parameterDescriptor.getUpperBounds()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DescriptorSubstitutor {
|
||||
descriptor.getIndex());
|
||||
substituted.setInitialized();
|
||||
|
||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType()));
|
||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substituted.getDefaultType()));
|
||||
|
||||
substitutedMap.put(descriptor, substituted);
|
||||
result.add(substituted);
|
||||
@@ -106,7 +106,7 @@ public class DescriptorSubstitutor {
|
||||
for (TypeParameterDescriptor descriptor : topologicallySortTypeParameters(typeParameters)) {
|
||||
JetType upperBoundsAsType = descriptor.getUpperBoundsAsType();
|
||||
JetType substitutedUpperBoundsAsType = substitutor.substitute(upperBoundsAsType, Variance.INVARIANT);
|
||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substitutedUpperBoundsAsType));
|
||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substitutedUpperBoundsAsType));
|
||||
}
|
||||
|
||||
return substitutor;
|
||||
|
||||
@@ -29,11 +29,11 @@ import java.util.List;
|
||||
public final class JetTypeImpl extends AnnotatedImpl implements JetType {
|
||||
|
||||
private final TypeConstructor constructor;
|
||||
private final List<TypeProjection> arguments;
|
||||
private final List<? extends TypeProjection> arguments;
|
||||
private final boolean nullable;
|
||||
private final JetScope memberScope;
|
||||
|
||||
public JetTypeImpl(List<AnnotationDescriptor> annotations, TypeConstructor constructor, boolean nullable, @NotNull List<TypeProjection> arguments, JetScope memberScope) {
|
||||
public JetTypeImpl(List<AnnotationDescriptor> annotations, TypeConstructor constructor, boolean nullable, @NotNull List<? extends TypeProjection> arguments, JetScope memberScope) {
|
||||
super(annotations);
|
||||
|
||||
if (memberScope instanceof ErrorUtils.ErrorScope) {
|
||||
@@ -67,7 +67,8 @@ public final class JetTypeImpl extends AnnotatedImpl implements JetType {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeProjection> getArguments() {
|
||||
return arguments;
|
||||
//noinspection unchecked
|
||||
return (List) arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,13 +98,13 @@ public class SubstitutionUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<TypeConstructor, TypeProjection> buildSubstitutionContext(@NotNull List<TypeParameterDescriptor> parameters, @NotNull List<TypeProjection> contextArguments) {
|
||||
public static Map<TypeConstructor, TypeProjection> buildSubstitutionContext(@NotNull List<TypeParameterDescriptor> parameters, @NotNull List<? extends TypeProjection> contextArguments) {
|
||||
Map<TypeConstructor, TypeProjection> parameterValues = new HashMap<TypeConstructor, TypeProjection>();
|
||||
fillInSubstitutionContext(parameters, contextArguments, parameterValues);
|
||||
return parameterValues;
|
||||
}
|
||||
|
||||
private static void fillInSubstitutionContext(List<TypeParameterDescriptor> parameters, List<TypeProjection> contextArguments, Map<TypeConstructor, TypeProjection> parameterValues) {
|
||||
private static void fillInSubstitutionContext(List<TypeParameterDescriptor> parameters, List<? extends TypeProjection> contextArguments, Map<TypeConstructor, TypeProjection> parameterValues) {
|
||||
if (parameters.size() != contextArguments.size()) {
|
||||
throw new IllegalArgumentException("type parameter count != context arguments");
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class SubstitutionUtils {
|
||||
|
||||
@NotNull
|
||||
public static TypeProjection makeStarProjection(@NotNull TypeParameterDescriptor parameterDescriptor) {
|
||||
return new TypeProjection(parameterDescriptor.getVariance() == Variance.OUT_VARIANCE
|
||||
return new TypeProjectionImpl(parameterDescriptor.getVariance() == Variance.OUT_VARIANCE
|
||||
? Variance.INVARIANT
|
||||
: Variance.OUT_VARIANCE, parameterDescriptor.getUpperBoundsAsType());
|
||||
}
|
||||
|
||||
@@ -18,54 +18,10 @@ package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TypeProjection {
|
||||
private final Variance projection;
|
||||
private final JetType type;
|
||||
|
||||
public TypeProjection(@NotNull Variance projection, @NotNull JetType type) {
|
||||
this.projection = projection;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TypeProjection(JetType type) {
|
||||
this(Variance.INVARIANT, type);
|
||||
}
|
||||
public interface TypeProjection {
|
||||
@NotNull
|
||||
Variance getProjectionKind();
|
||||
|
||||
@NotNull
|
||||
public Variance getProjectionKind() {
|
||||
return projection;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (projection == Variance.INVARIANT) {
|
||||
return type.toString();
|
||||
}
|
||||
return projection + " " + type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TypeProjection that = (TypeProjection) o;
|
||||
|
||||
if (projection != that.projection) return false;
|
||||
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = projection != null ? projection.hashCode() : 0;
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
JetType getType();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
public abstract class TypeProjectionBase implements TypeProjection {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (getProjectionKind() == Variance.INVARIANT) {
|
||||
return getType().toString();
|
||||
}
|
||||
return getProjectionKind() + " " + getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof TypeProjection)) return false;
|
||||
|
||||
TypeProjection that = (TypeProjection) o;
|
||||
|
||||
if (getProjectionKind() != that.getProjectionKind()) return false;
|
||||
if (!getType().equals(that.getType())) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = getProjectionKind().hashCode();
|
||||
result = 31 * result + (getType().hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TypeProjectionImpl extends TypeProjectionBase {
|
||||
private final Variance projection;
|
||||
private final JetType type;
|
||||
|
||||
public TypeProjectionImpl(@NotNull Variance projection, @NotNull JetType type) {
|
||||
this.projection = projection;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TypeProjectionImpl(@NotNull JetType type) {
|
||||
this(Variance.INVARIANT, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Variance getProjectionKind() {
|
||||
return projection;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class TypeSubstitutor {
|
||||
}
|
||||
|
||||
try {
|
||||
return unsafeSubstitute(new TypeProjection(howThisTypeIsUsed, type), 0).getType();
|
||||
return unsafeSubstitute(new TypeProjectionImpl(howThisTypeIsUsed, type), 0).getType();
|
||||
} catch (SubstitutionException e) {
|
||||
return ErrorUtils.createErrorType(e.getMessage());
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class TypeSubstitutor {
|
||||
|
||||
@Nullable
|
||||
public JetType substitute(@NotNull JetType type, @NotNull Variance howThisTypeIsUsed) {
|
||||
TypeProjection projection = substitute(new TypeProjection(howThisTypeIsUsed, type));
|
||||
TypeProjection projection = substitute(new TypeProjectionImpl(howThisTypeIsUsed, type));
|
||||
return projection == null ? null : projection.getType();
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class TypeSubstitutor {
|
||||
JetType substitutedType = TypeUtils.makeNullableAsSpecified(replacement.getType(), resultingIsNullable);
|
||||
Variance resultingProjectionKind = combine(originalProjection.getProjectionKind(), replacement.getProjectionKind());
|
||||
|
||||
return new TypeProjection(resultingProjectionKind, substitutedType);
|
||||
return new TypeProjectionImpl(resultingProjectionKind, substitutedType);
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class TypeSubstitutor {
|
||||
type.isNullable(), // Same nullability
|
||||
substitutedArguments,
|
||||
new SubstitutingScope(type.getMemberScope(), this));
|
||||
return new TypeProjection(originalProjection.getProjectionKind(), substitutedType);
|
||||
return new TypeProjectionImpl(originalProjection.getProjectionKind(), substitutedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class TypeSubstitutor {
|
||||
case NO_CONFLICT:
|
||||
// if the corresponding type parameter is already co/contra-variant, there's not need for an explicit projection
|
||||
if (typeParameter.getVariance() != Variance.INVARIANT) {
|
||||
substitutedTypeArgument = new TypeProjection(Variance.INVARIANT, substitutedTypeArgument.getType());
|
||||
substitutedTypeArgument = new TypeProjectionImpl(Variance.INVARIANT, substitutedTypeArgument.getType());
|
||||
}
|
||||
break;
|
||||
case OUT_IN_IN_POSITION:
|
||||
|
||||
@@ -381,7 +381,7 @@ public class TypeUtils {
|
||||
public static List<TypeProjection> getDefaultTypeProjections(List<TypeParameterDescriptor> parameters) {
|
||||
List<TypeProjection> result = new ArrayList<TypeProjection>();
|
||||
for (TypeParameterDescriptor parameterDescriptor : parameters) {
|
||||
result.add(new TypeProjection(parameterDescriptor.getDefaultType()));
|
||||
result.add(new TypeProjectionImpl(parameterDescriptor.getDefaultType()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -472,7 +472,7 @@ public class TypeUtils {
|
||||
List<TypeProjection> projections = ContainerUtil.map(typeArguments, new com.intellij.util.Function<JetType, TypeProjection>() {
|
||||
@Override
|
||||
public TypeProjection fun(JetType type) {
|
||||
return new TypeProjection(type);
|
||||
return new TypeProjectionImpl(type);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -713,7 +713,7 @@ public class TypeUtils {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameterDescriptors) {
|
||||
constructors.add(typeParameterDescriptor.getTypeConstructor());
|
||||
}
|
||||
final TypeProjection projection = new TypeProjection(type);
|
||||
final TypeProjection projection = new TypeProjectionImpl(type);
|
||||
|
||||
return TypeSubstitutor.create(new TypeSubstitution() {
|
||||
@Override
|
||||
|
||||
@@ -685,7 +685,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public JetType getArrayType(@NotNull Variance projectionType, @NotNull JetType argument) {
|
||||
List<TypeProjection> types = Collections.singletonList(new TypeProjection(projectionType, argument));
|
||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||
return new JetTypeImpl(
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
getArray().getTypeConstructor(),
|
||||
@@ -703,7 +703,7 @@ public class KotlinBuiltIns {
|
||||
@NotNull
|
||||
public JetType getEnumType(@NotNull JetType argument) {
|
||||
Variance projectionType = Variance.INVARIANT;
|
||||
List<TypeProjection> types = Collections.singletonList(new TypeProjection(projectionType, argument));
|
||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||
return new JetTypeImpl(
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
getEnum().getTypeConstructor(),
|
||||
@@ -798,7 +798,7 @@ public class KotlinBuiltIns {
|
||||
}
|
||||
|
||||
private static TypeProjection defaultProjection(JetType returnType) {
|
||||
return new TypeProjection(Variance.INVARIANT, returnType);
|
||||
return new TypeProjectionImpl(Variance.INVARIANT, returnType);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1026,7 +1026,7 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
TypeParameterDescriptor typeParameter = typeParameters.get(i);
|
||||
JetType newArgument = substituteType(projection.getType(), substitution, typeParameter.getVariance());
|
||||
newArguments.add(new TypeProjection(Variance.INVARIANT, newArgument));
|
||||
newArguments.add(new TypeProjectionImpl(Variance.INVARIANT, newArgument));
|
||||
i++;
|
||||
}
|
||||
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(),
|
||||
@@ -1354,7 +1354,7 @@ public class CreateFunctionFromUsageFix extends CreateFromUsageFixBase {
|
||||
JetType[] returnJetTypeParameterTypes = guessTypesForExpression(variableExpr, context);
|
||||
if (returnJetTypeParameterTypes.length != 1) return null;
|
||||
|
||||
TypeProjection returnJetTypeParameterType = new TypeProjection(returnJetTypeParameterTypes[0]);
|
||||
TypeProjection returnJetTypeParameterType = new TypeProjectionImpl(returnJetTypeParameterTypes[0]);
|
||||
List<TypeProjection> returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType);
|
||||
returnJetType = new JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isNullable(),
|
||||
returnJetTypeArguments, returnJetType.getMemberScope());
|
||||
|
||||
Reference in New Issue
Block a user