diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java index cc5b446324..cb9d71f919 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/FixSerializationConfig.java @@ -24,8 +24,6 @@ import com.google.common.base.Preconditions; import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; -import com.uber.nullaway.fixserialization.adapters.SerializationV1Adapter; -import com.uber.nullaway.fixserialization.adapters.SerializationV3Adapter; import com.uber.nullaway.fixserialization.out.SuggestedNullableFixInfo; import java.io.IOException; import java.nio.file.Files; @@ -86,7 +84,9 @@ public FixSerializationConfig( this.suggestEnclosing = suggestEnclosing; this.fieldInitInfoEnabled = fieldInitInfoEnabled; this.outputDirectory = outputDirectory; - serializer = new Serializer(this, initializeAdapter(SerializationAdapter.LATEST_VERSION)); + serializer = + new Serializer( + this, SerializationAdapter.getAdapterForVersion(SerializationAdapter.LATEST_VERSION)); } /** @@ -126,32 +126,11 @@ public FixSerializationConfig(String configFilePath, int serializationVersion) { XMLUtil.getValueFromAttribute( document, "/serialization/fieldInitInfo", "active", Boolean.class) .orElse(false); - SerializationAdapter serializationAdapter = initializeAdapter(serializationVersion); + SerializationAdapter serializationAdapter = + SerializationAdapter.getAdapterForVersion(serializationVersion); serializer = new Serializer(this, serializationAdapter); } - /** - * Initializes NullAway serialization adapter according to the requested serialization version. - */ - private SerializationAdapter initializeAdapter(int version) { - switch (version) { - case 1: - return new SerializationV1Adapter(); - case 2: - throw new RuntimeException( - "Serialization version v2 is skipped and was used for an alpha version of the auto-annotator tool. Please use version 3 instead."); - case 3: - return new SerializationV3Adapter(); - default: - throw new RuntimeException( - "Unrecognized NullAway serialization version: " - + version - + ". Supported versions: 1 to " - + SerializationAdapter.LATEST_VERSION - + "."); - } - } - public @Nullable Serializer getSerializer() { return serializer; } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationAdapter.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationAdapter.java index 2f3bc5fc84..ce7e802fdb 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationAdapter.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationAdapter.java @@ -71,4 +71,29 @@ public interface SerializationAdapter { * @return The serialized method symbol. */ String serializeMethodSignature(Symbol.MethodSymbol methodSymbol); + + /** + * Gets the adapter for the given version number. + * + * @param version Version number of the adapter. + * @return Adapter for the given version. + */ + static SerializationAdapter getAdapterForVersion(int version) { + switch (version) { + case 1: + return new SerializationV1Adapter(); + case 2: + throw new RuntimeException( + "Serialization version v2 is skipped and was used for an alpha version of the auto-annotator tool. Please use version 3 instead."); + case 3: + return new SerializationV3Adapter(); + default: + throw new RuntimeException( + "Unrecognized NullAway serialization version: " + + version + + ". Supported versions: 1 to " + + SerializationAdapter.LATEST_VERSION + + "."); + } + } }