diff --git a/compiler/tests/org/jetbrains/jet/types/AbstractJetTypeBindingTest.kt b/compiler/tests/org/jetbrains/jet/types/AbstractJetTypeBindingTest.kt index 4c307dc1cc9..95122de7213 100644 --- a/compiler/tests/org/jetbrains/jet/types/AbstractJetTypeBindingTest.kt +++ b/compiler/tests/org/jetbrains/jet/types/AbstractJetTypeBindingTest.kt @@ -80,7 +80,7 @@ abstract class AbstractJetTypeBindingTest : JetLiteFixture() { } println("typeParameter: ${argument.typeParameterDescriptor.render()}") - val projection = argument.typeProjection.getProjectionKind().toString().let { + val projection = argument.typeProjection.getProjectionKind().label.let { if (it.isNotEmpty()) "$it " else diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java b/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java index 9d9aa4d21bb..457d9f35532 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java @@ -267,7 +267,7 @@ public class CommonSupertypes { for (TypeProjection projection : typeProjections) { Variance projectionKind = projection.getProjectionKind(); - if (projectionKind.allowsInPosition()) { + if (projectionKind.getAllowsInPosition()) { if (ins != null) { ins.add(projection.getType()); } @@ -276,7 +276,7 @@ public class CommonSupertypes { ins = null; } - if (projectionKind.allowsOutPosition()) { + if (projectionKind.getAllowsOutPosition()) { if (outs != null) { outs.add(projection.getType()); } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.java b/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.java deleted file mode 100644 index 1926f106f92..00000000000 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 enum Variance { - INVARIANT("", true, true, 0), - IN_VARIANCE("in", true, false, -1), - OUT_VARIANCE("out", false, true, +1); - - private final String label; - private final boolean allowsInPosition; - private final boolean allowsOutPosition; - private final int superpositionFactor; - - Variance(String label, boolean allowsInPosition, boolean allowsOutPosition, int superpositionFactor) { - this.label = label; - this.allowsInPosition = allowsInPosition; - this.allowsOutPosition = allowsOutPosition; - this.superpositionFactor = superpositionFactor; - } - - public boolean allowsInPosition() { - return allowsInPosition; - } - - public boolean allowsOutPosition() { - return allowsOutPosition; - } - - public Variance superpose(Variance other) { - int r = this.superpositionFactor * other.superpositionFactor; - switch (r) { - case 0: return INVARIANT; - case -1: return IN_VARIANCE; - case +1: return OUT_VARIANCE; - } - throw new IllegalStateException(); - } - - public Variance opposite() { - switch (this) { - case INVARIANT: - return INVARIANT; - case IN_VARIANCE: - return OUT_VARIANCE; - case OUT_VARIANCE: - return IN_VARIANCE; - } - throw new IllegalStateException("Impossible variance: " + this); - } - - @Override - public String toString() { - return label; - } -} diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.kt b/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.kt new file mode 100644 index 00000000000..c7738831097 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/Variance.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2014 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 enum class Variance( + public val label: String, + public val allowsInPosition: Boolean, + public val allowsOutPosition: Boolean, + private val superpositionFactor: Int +) { + INVARIANT : Variance("", true, true, 0) + IN_VARIANCE : Variance("in", true, false, -1) + OUT_VARIANCE : Variance("out", false, true, +1) + + public fun allowsPosition(position: Variance): Boolean + = when (position) { + IN_VARIANCE -> allowsInPosition + OUT_VARIANCE -> allowsOutPosition + INVARIANT -> allowsInPosition && allowsOutPosition + } + + public fun superpose(other: Variance): Variance { + val r = this.superpositionFactor * other.superpositionFactor + return when (r) { + 0 -> INVARIANT + -1 -> IN_VARIANCE + +1 -> OUT_VARIANCE + else -> throw IllegalStateException("Illegal factor: $r") + } + } + + public fun opposite(): Variance { + return when (this) { + INVARIANT -> INVARIANT + IN_VARIANCE -> OUT_VARIANCE + OUT_VARIANCE -> IN_VARIANCE + } + } + + override fun toString() = label +} diff --git a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java index 458bbdf20bd..ae40e531fc1 100644 --- a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java @@ -674,7 +674,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer { if (typeParameter.isReified()) { builder.append(renderKeyword("reified")).append(" "); } - String variance = typeParameter.getVariance().toString(); + String variance = typeParameter.getVariance().getLabel(); if (!variance.isEmpty()) { builder.append(renderKeyword(variance)).append(" "); }