Serializing information about star projections
This commit is contained in:
@@ -116,6 +116,7 @@ message Type {
|
||||
IN = 0;
|
||||
OUT = 1;
|
||||
INV = 2;
|
||||
STAR = 3;
|
||||
}
|
||||
|
||||
optional Projection projection = 1 [default = INV];
|
||||
|
||||
+10
-4
@@ -373,11 +373,17 @@ public class DescriptorSerializer {
|
||||
@NotNull
|
||||
private ProtoBuf.Type.Argument.Builder typeArgument(@NotNull TypeProjection typeProjection) {
|
||||
ProtoBuf.Type.Argument.Builder builder = ProtoBuf.Type.Argument.newBuilder();
|
||||
ProtoBuf.Type.Argument.Projection projection = projection(typeProjection.getProjectionKind());
|
||||
|
||||
// to avoid storing a default
|
||||
if (projection != ProtoBuf.Type.Argument.Projection.INV) {
|
||||
builder.setProjection(projection);
|
||||
if (typeProjection.isStarProjection()) {
|
||||
builder.setProjection(ProtoBuf.Type.Argument.Projection.STAR);
|
||||
}
|
||||
else {
|
||||
ProtoBuf.Type.Argument.Projection projection = projection(typeProjection.getProjectionKind());
|
||||
|
||||
// to avoid storing a default
|
||||
if (projection != ProtoBuf.Type.Argument.Projection.INV) {
|
||||
builder.setProjection(projection);
|
||||
}
|
||||
}
|
||||
|
||||
builder.setType(type(typeProjection.getType()));
|
||||
|
||||
@@ -5121,6 +5121,10 @@ public final class ProtoBuf {
|
||||
* <code>INV = 2;</code>
|
||||
*/
|
||||
INV(2, 2),
|
||||
/**
|
||||
* <code>STAR = 3;</code>
|
||||
*/
|
||||
STAR(3, 3),
|
||||
;
|
||||
|
||||
/**
|
||||
@@ -5135,6 +5139,10 @@ public final class ProtoBuf {
|
||||
* <code>INV = 2;</code>
|
||||
*/
|
||||
public static final int INV_VALUE = 2;
|
||||
/**
|
||||
* <code>STAR = 3;</code>
|
||||
*/
|
||||
public static final int STAR_VALUE = 3;
|
||||
|
||||
|
||||
public final int getNumber() { return value; }
|
||||
@@ -5144,6 +5152,7 @@ public final class ProtoBuf {
|
||||
case 0: return IN;
|
||||
case 1: return OUT;
|
||||
case 2: return INV;
|
||||
case 3: return STAR;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -95,7 +95,10 @@ public class TypeDeserializer(
|
||||
|
||||
fun typeArguments(protos: List<ProtoBuf.Type.Argument>): List<TypeProjection> =
|
||||
protos.map { proto ->
|
||||
TypeProjectionImpl(variance(proto.getProjection()), type(proto.getType()))
|
||||
val type = type(proto.getType())
|
||||
if (proto.getProjection() == ProtoBuf.Type.Argument.Projection.STAR)
|
||||
StarProjectionImpl(type)
|
||||
else TypeProjectionImpl(variance(proto.getProjection()), type)
|
||||
}.toReadOnlyList()
|
||||
|
||||
override fun toString() = debugName + (if (parent == null) "" else ". Child of ${parent.debugName}")
|
||||
|
||||
+1
@@ -66,4 +66,5 @@ fun variance(variance: ProtoBuf.Type.Argument.Projection) = when (variance) {
|
||||
ProtoBuf.Type.Argument.Projection.IN -> Variance.IN_VARIANCE
|
||||
ProtoBuf.Type.Argument.Projection.OUT -> Variance.OUT_VARIANCE
|
||||
ProtoBuf.Type.Argument.Projection.INV -> Variance.INVARIANT
|
||||
else -> throw IllegalArgumentException("Only IN, OUT and INV are supported. Actual argument: $variance")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user