diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/BUILD | 2 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java | 44 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/BUILD index 3404be03a8..b6944d42a2 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/BUILD @@ -52,6 +52,8 @@ java_library( deps = [ ":autocodec-annotation", ":unsafe-provider", + "//src/main/java/com/google/devtools/build/lib/collect/nestedset", + "//src/main/java/com/google/devtools/build/lib/collect/nestedset:serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", "//third_party:auto_service", "//third_party:auto_value", diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java index fbe0a19251..1d9ab157d4 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Maps; import com.google.common.hash.HashCode; +import com.google.devtools.build.lib.collect.nestedset.NestedSetCodec; import com.google.devtools.build.lib.skyframe.serialization.InjectingObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationCodeGenerator.Context; @@ -690,6 +691,48 @@ class Marshallers { } }; + private final Marshaller nestedSetMarshaller = + new Marshaller() { + @Override + public boolean matches(DeclaredType type) { + // env.getElementUtils().getTypeElement mysteriously does not recognize NestedSet, so we + // do String comparison. + return env.getTypeUtils() + .erasure(type) + .toString() + .equals("com.google.devtools.build.lib.collect.nestedset.NestedSet"); + } + + @Override + public void addSerializationCode(Context context) { + TypeMirror typeParameter = context.getDeclaredType().getTypeArguments().get(0); + String nestedSetCodec = context.makeName("nestedSetCodec"); + context.builder.addStatement( + "$T<$T> $L = new $T<>($T.CODEC)", + NestedSetCodec.class, + typeParameter, + nestedSetCodec, + NestedSetCodec.class, + typeParameter); + context.builder.addStatement("$L.serialize($L, codedOut)", nestedSetCodec, context.name); + } + + @Override + public void addDeserializationCode(Context context) { + TypeMirror typeParameter = context.getDeclaredType().getTypeArguments().get(0); + String nestedSetCodec = context.makeName("nestedSetCodec"); + context.builder.addStatement( + "$T<$T> $L = new $T<>($T.CODEC)", + NestedSetCodec.class, + typeParameter, + nestedSetCodec, + NestedSetCodec.class, + typeParameter); + context.builder.addStatement( + "$L = $L.deserialize(codedIn)", context.name, nestedSetCodec); + } + }; + private final Marshaller codecMarshaller = new Marshaller() { @Override @@ -752,6 +795,7 @@ class Marshallers { immutableMapMarshaller, immutableSortedMapMarshaller, multimapMarshaller, + nestedSetMarshaller, patternMarshaller, hashCodeMarshaller, protoMarshaller, |