Common code extracted to a method
This commit is contained in:
+2
-12
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.KotlinToJavaTypesMap;
|
||||
@@ -186,18 +187,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
Variance altProjectionKind;
|
||||
if (type instanceof JetUserType) {
|
||||
JetTypeProjection typeProjection = ((JetUserType) type).getTypeArguments().get(i);
|
||||
switch (typeProjection.getProjectionKind()) {
|
||||
case IN:
|
||||
altProjectionKind = Variance.IN_VARIANCE;
|
||||
break;
|
||||
case OUT:
|
||||
altProjectionKind = Variance.OUT_VARIANCE;
|
||||
break;
|
||||
case STAR:
|
||||
throw new IllegalStateException("star projection should have been processed above");
|
||||
default:
|
||||
altProjectionKind = Variance.INVARIANT;
|
||||
}
|
||||
altProjectionKind = TypeResolver.resolveProjectionKind(typeProjection.getProjectionKind());
|
||||
if (altProjectionKind != projectionKind && projectionKind != Variance.INVARIANT) {
|
||||
throw new AlternativeSignatureMismatchException("Projection kind mismatch, actual: %s, in alternative signature: %s",
|
||||
projectionKind, altProjectionKind);
|
||||
|
||||
@@ -304,19 +304,7 @@ public class TypeResolver {
|
||||
else {
|
||||
// TODO : handle the Foo<in *> case
|
||||
type = resolveType(scope, argumentElement.getTypeReference(), trace, checkBounds);
|
||||
Variance kind = null;
|
||||
switch (projectionKind) {
|
||||
case IN:
|
||||
kind = IN_VARIANCE;
|
||||
break;
|
||||
case OUT:
|
||||
kind = OUT_VARIANCE;
|
||||
break;
|
||||
case NONE:
|
||||
kind = INVARIANT;
|
||||
break;
|
||||
}
|
||||
assert kind != null;
|
||||
Variance kind = resolveProjectionKind(projectionKind);
|
||||
if (constructor.getParameters().size() > i) {
|
||||
TypeParameterDescriptor parameterDescriptor = constructor.getParameters().get(i);
|
||||
if (kind != INVARIANT && parameterDescriptor.getVariance() != INVARIANT) {
|
||||
@@ -334,6 +322,26 @@ public class TypeResolver {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Variance resolveProjectionKind(@NotNull JetProjectionKind projectionKind) {
|
||||
Variance kind = null;
|
||||
switch (projectionKind) {
|
||||
case IN:
|
||||
kind = IN_VARIANCE;
|
||||
break;
|
||||
case OUT:
|
||||
kind = OUT_VARIANCE;
|
||||
break;
|
||||
case NONE:
|
||||
kind = INVARIANT;
|
||||
break;
|
||||
default:
|
||||
// NOTE: Star projections must be handled before this method is called
|
||||
throw new IllegalStateException("Illegal projection kind:" + projectionKind);
|
||||
}
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType, BindingTrace trace) {
|
||||
Collection<? extends DeclarationDescriptor> descriptors = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace);
|
||||
|
||||
Reference in New Issue
Block a user