Convert Variance.java -> .kt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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(" ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user