Skip to content

Commit

Permalink
Revert "Refactoring tabSeparatedToString logic to prepare for seriali…
Browse files Browse the repository at this point in the history
…zation version 3. (uber#738)"

This reverts commit ff6b090.
  • Loading branch information
msridhar committed Jul 18, 2023
1 parent c1fae8e commit 8b2fcee
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public void serializeSuggestedFixInfo(
if (enclosing) {
suggestedNullableFixInfo.initEnclosing();
}
appendToFile(
suggestedNullableFixInfo.tabSeparatedToString(serializationAdapter),
suggestedFixesOutputPath);
appendToFile(suggestedNullableFixInfo.tabSeparatedToString(), suggestedFixesOutputPath);
}

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

package com.uber.nullaway.fixserialization.adapters;

import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.out.ErrorInfo;

/**
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,21 +54,16 @@ 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));
}

@Override
public int getSerializationVersion() {
return 1;
}

@Override
public String serializeMethodSignature(Symbol.MethodSymbol methodSymbol) {
return methodSymbol.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,23 +67,18 @@ 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));
}

@Override
public int getSerializationVersion() {
return 2;
}

@Override
public String serializeMethodSignature(Symbol.MethodSymbol methodSymbol) {
return methodSymbol.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}

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

Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 8b2fcee

Please sign in to comment.