aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec/Marshallers.java153
1 files changed, 24 insertions, 129 deletions
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 af8a2da6bb..1ab908cfab 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
@@ -14,14 +14,11 @@
package com.google.devtools.build.lib.skyframe.serialization.autocodec;
-import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
@@ -44,7 +41,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import java.util.function.Consumer;
import java.util.regex.Pattern;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ElementKind;
@@ -422,31 +418,6 @@ class Marshallers {
}
};
- private final Marshaller optionalMarshaller =
- new Marshaller() {
- @Override
- public boolean matches(DeclaredType type) {
- return matchesErased(type, Optional.class);
- }
-
- @Override
- public void addSerializationCode(Context context) {
- DeclaredType optionalType =
- (DeclaredType) context.getDeclaredType().getTypeArguments().get(0);
- writeSerializationCode(context.with(optionalType, context.name + ".orNull()"));
- }
-
- @Override
- public void addDeserializationCode(Context context) {
- DeclaredType optionalType =
- (DeclaredType) context.getDeclaredType().getTypeArguments().get(0);
- String optionalName = context.makeName("optional");
- writeDeserializationCode(context.with(optionalType, optionalName));
- context.builder.addStatement(
- "$L = $T.fromNullable($L)", context.name, Optional.class, optionalName);
- }
- };
-
private final Marshaller uuidMarshller =
new Marshaller() {
@Override
@@ -717,106 +688,33 @@ class Marshallers {
@Override
public void addDeserializationCode(Context context) {
- addMapDeserializationCode(
- context,
- (builderName, key, value) ->
- context.builder.addStatement(
- "$T<$T, $T> $L = new $T<>()",
- LinkedHashMap.class,
- key.getTypeName(),
- value.getTypeName(),
- builderName,
- LinkedHashMap.class),
- (builderName) -> context.builder.addStatement("$L = $L", context.name, builderName));
- }
- };
-
- private final Marshaller immutableMapMarshaller =
- new Marshaller() {
- @Override
- public boolean matches(DeclaredType type) {
- return matchesErased(type, ImmutableMap.class);
- }
-
- @Override
- public void addSerializationCode(Context context) {
- mapMarshaller.addSerializationCode(context);
- }
-
- @Override
- public void addDeserializationCode(Context context) {
- addMapDeserializationCode(
- context,
- (builderName, key, value) ->
- context.builder.addStatement(
- "$T<$T, $T> $L = new $T<>()",
- ImmutableMap.Builder.class,
- key.getTypeName(),
- value.getTypeName(),
- builderName,
- ImmutableMap.Builder.class),
- (builderName) ->
- context.builder.addStatement("$L = $L.build()", context.name, builderName));
- }
- };
-
- private final Marshaller immutableSortedMapMarshaller =
- new Marshaller() {
- @Override
- public boolean matches(DeclaredType type) {
- return matchesErased(type, ImmutableSortedMap.class);
- }
-
- @Override
- public void addSerializationCode(Context context) {
- mapMarshaller.addSerializationCode(context);
- }
-
- @Override
- public void addDeserializationCode(Context context) {
- addMapDeserializationCode(
- context,
- (builderName, key, value) ->
- context.builder.addStatement(
- "$T<$T, $T> $L = new $T<>($T.naturalOrder())",
- ImmutableSortedMap.Builder.class,
- key.getTypeName(),
- value.getTypeName(),
- builderName,
- ImmutableSortedMap.Builder.class,
- Comparator.class),
- (builderName) ->
- context.builder.addStatement("$L = $L.build()", context.name, builderName));
+ String builderName = context.makeName("builder");
+ Context key =
+ context.with(
+ context.getDeclaredType().getTypeArguments().get(0), context.makeName("key"));
+ Context value =
+ context.with(
+ context.getDeclaredType().getTypeArguments().get(1), context.makeName("value"));
+ context.builder.addStatement(
+ "$T<$T, $T> $L = new $T<>()",
+ LinkedHashMap.class,
+ key.getTypeName(),
+ value.getTypeName(),
+ builderName,
+ LinkedHashMap.class);
+ String lengthName = context.makeName("length");
+ context.builder.addStatement("int $L = codedIn.readInt32()", lengthName);
+ String indexName = context.makeName("i");
+ context.builder.beginControlFlow(
+ "for (int $L = 0; $L < $L; ++$L)", indexName, indexName, lengthName, indexName);
+ writeDeserializationCode(key);
+ writeDeserializationCode(value);
+ context.builder.addStatement("$L.put($L, $L)", builderName, key.name, value.name);
+ context.builder.endControlFlow();
+ context.builder.addStatement("$L = $L", context.name, builderName);
}
};
- @FunctionalInterface
- private static interface MapBuilderInitializer {
- void initialize(String builderName, Context key, Context value);
- }
-
- /** Helper for map marshallers. */
- private void addMapDeserializationCode(
- Context context, MapBuilderInitializer mapBuilderInitializer, Consumer<String> finisher) {
- String builderName = context.makeName("builder");
- Context key =
- context.with(context.getDeclaredType().getTypeArguments().get(0), context.makeName("key"));
- Context value =
- context.with(
- context.getDeclaredType().getTypeArguments().get(1), context.makeName("value"));
- mapBuilderInitializer.initialize(builderName, key, value);
- String lengthName = context.makeName("length");
- context.builder.addStatement("int $L = codedIn.readInt32()", lengthName);
- String indexName = context.makeName("i");
- context.builder.beginControlFlow(
- "for (int $L = 0; $L < $L; ++$L)", indexName, indexName, lengthName, indexName);
- writeDeserializationCode(key);
- writeDeserializationCode(value);
- context.builder.addStatement("$L.put($L, $L)", builderName, key.name, value.name);
- context.builder.endControlFlow();
- finisher.accept(builderName);
- }
-
private final Marshaller multimapMarshaller =
new Marshaller() {
@Override
@@ -1049,7 +947,6 @@ class Marshallers {
enumMarshaller,
stringMarshaller,
charSequenceMarshaller,
- optionalMarshaller,
supplierMarshaller,
uuidMarshller,
mapEntryMarshaller,
@@ -1057,8 +954,6 @@ class Marshallers {
immutableSetMarshaller,
immutableSortedSetMarshaller,
mapMarshaller,
- immutableMapMarshaller,
- immutableSortedMapMarshaller,
multimapMarshaller,
nestedSetMarshaller,
patternMarshaller,