diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java index db6d8c7250..87154d0a39 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/Serializer.java @@ -77,9 +77,7 @@ public void serializeSuggestedFixInfo( if (enclosing) { suggestedNullableFixInfo.initEnclosing(); } - appendToFile( - suggestedNullableFixInfo.tabSeparatedToString(serializationAdapter), - suggestedFixesOutputPath); + appendToFile(suggestedNullableFixInfo.tabSeparatedToString(), suggestedFixesOutputPath); } /** @@ -93,7 +91,7 @@ public void serializeErrorInfo(ErrorInfo errorInfo) { } public void serializeFieldInitializationInfo(FieldInitializationInfo info) { - appendToFile(info.tabSeparatedToString(serializationAdapter), fieldInitializationOutputPath); + appendToFile(info.tabSeparatedToString(), fieldInitializationOutputPath); } /** Cleared the content of the file if exists and writes the header in the first line. */ @@ -203,10 +201,9 @@ public static Path pathToSourceFileFromURI(@Nullable URI uri) { * Serializes the given {@link Symbol} to a string. * * @param symbol The symbol to serialize. - * @param adapter adapter used to serialize symbols. * @return The serialized symbol. */ - public static String serializeSymbol(@Nullable Symbol symbol, SerializationAdapter adapter) { + public static String serializeSymbol(@Nullable Symbol symbol) { if (symbol == null) { return "null"; } @@ -216,7 +213,7 @@ public static String serializeSymbol(@Nullable Symbol symbol, SerializationAdapt return symbol.name.toString(); case METHOD: case CONSTRUCTOR: - return adapter.serializeMethodSignature((Symbol.MethodSymbol) symbol); + return symbol.toString(); default: return symbol.flatName().toString(); } 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 c7ef01bc0b..0120ef785f 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 @@ -22,7 +22,6 @@ package com.uber.nullaway.fixserialization.adapters; -import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.out.ErrorInfo; /** @@ -63,12 +62,4 @@ public interface SerializationAdapter { * @return Supporting serialization version number. */ int getSerializationVersion(); - - /** - * Serializes the signature of the given {@link Symbol.MethodSymbol} to a string. - * - * @param methodSymbol The method symbol to serialize. - * @return The serialized method symbol. - */ - String serializeMethodSignature(Symbol.MethodSymbol methodSymbol); } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV1Adapter.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV1Adapter.java index b0ad0cc9c6..d622cec71e 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV1Adapter.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV1Adapter.java @@ -24,7 +24,6 @@ import static com.uber.nullaway.fixserialization.out.ErrorInfo.EMPTY_NONNULL_TARGET_LOCATION_STRING; -import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.SerializationService; import com.uber.nullaway.fixserialization.Serializer; import com.uber.nullaway.fixserialization.location.SymbolLocation; @@ -55,11 +54,11 @@ public String serializeError(ErrorInfo errorInfo) { "\t", errorInfo.getErrorMessage().getMessageType().toString(), SerializationService.escapeSpecialCharacters(errorInfo.getErrorMessage().getMessage()), - Serializer.serializeSymbol(errorInfo.getRegionClass(), this), - Serializer.serializeSymbol(errorInfo.getRegionMember(), this), + Serializer.serializeSymbol(errorInfo.getRegionClass()), + Serializer.serializeSymbol(errorInfo.getRegionMember()), (errorInfo.getNonnullTarget() != null ? SymbolLocation.createLocationFromSymbol(errorInfo.getNonnullTarget()) - .tabSeparatedToString(this) + .tabSeparatedToString() : EMPTY_NONNULL_TARGET_LOCATION_STRING)); } @@ -67,9 +66,4 @@ public String serializeError(ErrorInfo errorInfo) { public int getSerializationVersion() { return 1; } - - @Override - public String serializeMethodSignature(Symbol.MethodSymbol methodSymbol) { - return methodSymbol.toString(); - } } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV2Adapter.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV2Adapter.java index 6b72441852..eda75d6d03 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV2Adapter.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/adapters/SerializationV2Adapter.java @@ -24,7 +24,6 @@ import static com.uber.nullaway.fixserialization.out.ErrorInfo.EMPTY_NONNULL_TARGET_LOCATION_STRING; -import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.SerializationService; import com.uber.nullaway.fixserialization.Serializer; import com.uber.nullaway.fixserialization.location.SymbolLocation; @@ -68,13 +67,13 @@ public String serializeError(ErrorInfo errorInfo) { "\t", errorInfo.getErrorMessage().getMessageType().toString(), SerializationService.escapeSpecialCharacters(errorInfo.getErrorMessage().getMessage()), - Serializer.serializeSymbol(errorInfo.getRegionClass(), this), - Serializer.serializeSymbol(errorInfo.getRegionMember(), this), + Serializer.serializeSymbol(errorInfo.getRegionClass()), + Serializer.serializeSymbol(errorInfo.getRegionMember()), String.valueOf(errorInfo.getOffset()), errorInfo.getPath() != null ? errorInfo.getPath().toString() : "null", (errorInfo.getNonnullTarget() != null ? SymbolLocation.createLocationFromSymbol(errorInfo.getNonnullTarget()) - .tabSeparatedToString(this) + .tabSeparatedToString() : EMPTY_NONNULL_TARGET_LOCATION_STRING)); } @@ -82,9 +81,4 @@ public String serializeError(ErrorInfo errorInfo) { public int getSerializationVersion() { return 2; } - - @Override - public String serializeMethodSignature(Symbol.MethodSymbol methodSymbol) { - return methodSymbol.toString(); - } } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/FieldLocation.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/FieldLocation.java index 19ca23dae1..71c8989f99 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/FieldLocation.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/FieldLocation.java @@ -24,7 +24,6 @@ import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.Serializer; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; import javax.lang.model.element.ElementKind; /** subtype of {@link AbstractSymbolLocation} targeting class fields. */ @@ -39,13 +38,13 @@ public FieldLocation(Symbol target) { } @Override - public String tabSeparatedToString(SerializationAdapter adapter) { + public String tabSeparatedToString() { return String.join( "\t", type.toString(), - Serializer.serializeSymbol(enclosingClass, adapter), + Serializer.serializeSymbol(enclosingClass), "null", - Serializer.serializeSymbol(variableSymbol, adapter), + Serializer.serializeSymbol(variableSymbol), "null", path != null ? path.toString() : "null"); } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodLocation.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodLocation.java index f3c3022842..c53075d904 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodLocation.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodLocation.java @@ -24,7 +24,6 @@ import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.Serializer; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; import javax.lang.model.element.ElementKind; /** subtype of {@link AbstractSymbolLocation} targeting methods. */ @@ -39,12 +38,12 @@ public MethodLocation(Symbol target) { } @Override - public String tabSeparatedToString(SerializationAdapter adapter) { + public String tabSeparatedToString() { return String.join( "\t", type.toString(), - Serializer.serializeSymbol(enclosingClass, adapter), - Serializer.serializeSymbol(enclosingMethod, adapter), + Serializer.serializeSymbol(enclosingClass), + Serializer.serializeSymbol(enclosingMethod), "null", "null", path != null ? path.toString() : "null"); diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodParameterLocation.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodParameterLocation.java index ff4f0a542e..622d3109b2 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodParameterLocation.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/MethodParameterLocation.java @@ -25,7 +25,6 @@ import com.google.common.base.Preconditions; import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.Serializer; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; import javax.lang.model.element.ElementKind; /** subtype of {@link AbstractSymbolLocation} targeting a method parameter. */ @@ -60,13 +59,13 @@ public MethodParameterLocation(Symbol target) { } @Override - public String tabSeparatedToString(SerializationAdapter adapter) { + public String tabSeparatedToString() { return String.join( "\t", type.toString(), - Serializer.serializeSymbol(enclosingClass, adapter), - Serializer.serializeSymbol(enclosingMethod, adapter), - Serializer.serializeSymbol(paramSymbol, adapter), + Serializer.serializeSymbol(enclosingClass), + Serializer.serializeSymbol(enclosingMethod), + Serializer.serializeSymbol(paramSymbol), String.valueOf(index), path != null ? path.toString() : "null"); } diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/SymbolLocation.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/SymbolLocation.java index 262df711e1..5824866b2e 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/SymbolLocation.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/location/SymbolLocation.java @@ -23,7 +23,6 @@ package com.uber.nullaway.fixserialization.location; import com.sun.tools.javac.code.Symbol; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; /** Provides method for symbol locations. */ public interface SymbolLocation { @@ -33,10 +32,9 @@ public interface SymbolLocation { * of the element, symbol of the containing class, symbol of the enclosing method, symbol of the * variable, index of the element and uri to containing file. * - * @param adapter adapter used to serialize symbols. * @return string representation of contents in a line seperated by tabs. */ - String tabSeparatedToString(SerializationAdapter adapter); + String tabSeparatedToString(); /** * Creates header of an output file containing all {@link SymbolLocation} written in string which diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/FieldInitializationInfo.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/FieldInitializationInfo.java index dac0c6d117..b5caca2697 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/FieldInitializationInfo.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/FieldInitializationInfo.java @@ -24,7 +24,6 @@ import com.sun.tools.javac.code.Symbol; import com.uber.nullaway.fixserialization.Serializer; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; import com.uber.nullaway.fixserialization.location.SymbolLocation; /** @@ -46,13 +45,12 @@ public FieldInitializationInfo(Symbol.MethodSymbol initializerMethod, Symbol fie /** * Returns string representation of content of an object. * - * @param adapter adapter used to serialize symbols. * @return string representation of contents of an object in a line seperated by tabs. */ - public String tabSeparatedToString(SerializationAdapter adapter) { - return initializerMethodLocation.tabSeparatedToString(adapter) + public String tabSeparatedToString() { + return initializerMethodLocation.tabSeparatedToString() + '\t' - + Serializer.serializeSymbol(field, adapter); + + Serializer.serializeSymbol(field); } /** diff --git a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java index fb271cd644..68377a818d 100644 --- a/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java +++ b/nullaway/src/main/java/com/uber/nullaway/fixserialization/out/SuggestedNullableFixInfo.java @@ -25,7 +25,6 @@ import com.sun.source.util.TreePath; import com.uber.nullaway.ErrorMessage; import com.uber.nullaway.fixserialization.Serializer; -import com.uber.nullaway.fixserialization.adapters.SerializationAdapter; import com.uber.nullaway.fixserialization.location.SymbolLocation; import java.util.Objects; @@ -69,17 +68,16 @@ public int hashCode() { /** * returns string representation of content of an object. * - * @param adapter adapter used to serialize symbols. * @return string representation of contents of an object in a line separated by tabs. */ - public String tabSeparatedToString(SerializationAdapter adapter) { + public String tabSeparatedToString() { return String.join( "\t", - symbolLocation.tabSeparatedToString(adapter), + symbolLocation.tabSeparatedToString(), errorMessage.getMessageType().toString(), "nullable", - Serializer.serializeSymbol(classAndMemberInfo.getClazz(), adapter), - Serializer.serializeSymbol(classAndMemberInfo.getMember(), adapter)); + Serializer.serializeSymbol(classAndMemberInfo.getClazz()), + Serializer.serializeSymbol(classAndMemberInfo.getMember())); } /** Finds the class and member of program point where triggered this type change. */