Skip to content

Commit

Permalink
Merge branch 'master' into substitute-generics
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Nov 5, 2024
2 parents 6a6ed67 + 17fc1ba commit 6667518
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
+ ".");
}
}
}

0 comments on commit 6667518

Please sign in to comment.