Skip to content

Commit

Permalink
Revert "Refactoring in symbol serialization (uber#736)"
Browse files Browse the repository at this point in the history
This reverts commit 457a129.
  • Loading branch information
msridhar committed Jul 19, 2023
1 parent 937b217 commit ce7e084
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.uber.nullaway.fixserialization;

import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.ErrorMessage;
import com.uber.nullaway.fixserialization.adapters.SerializationAdapter;
import com.uber.nullaway.fixserialization.out.ErrorInfo;
Expand Down Expand Up @@ -196,26 +195,4 @@ public static Path pathToSourceFileFromURI(@Nullable URI uri) {
return path;
}
}

/**
* Serializes the given {@link Symbol} to a string.
*
* @param symbol The symbol to serialize.
* @return The serialized symbol.
*/
public static String serializeSymbol(@Nullable Symbol symbol) {
if (symbol == null) {
return "null";
}
switch (symbol.getKind()) {
case FIELD:
case PARAMETER:
return symbol.name.toString();
case METHOD:
case CONSTRUCTOR:
return symbol.toString();
default:
return symbol.flatName().toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static com.uber.nullaway.fixserialization.out.ErrorInfo.EMPTY_NONNULL_TARGET_LOCATION_STRING;

import com.uber.nullaway.fixserialization.SerializationService;
import com.uber.nullaway.fixserialization.Serializer;
import com.uber.nullaway.fixserialization.location.SymbolLocation;
import com.uber.nullaway.fixserialization.out.ErrorInfo;

Expand Down Expand Up @@ -54,8 +53,10 @@ public String serializeError(ErrorInfo errorInfo) {
"\t",
errorInfo.getErrorMessage().getMessageType().toString(),
SerializationService.escapeSpecialCharacters(errorInfo.getErrorMessage().getMessage()),
Serializer.serializeSymbol(errorInfo.getRegionClass()),
Serializer.serializeSymbol(errorInfo.getRegionMember()),
(errorInfo.getRegionClass() != null
? errorInfo.getRegionClass().flatName().toString()
: "null"),
(errorInfo.getRegionMember() != null ? errorInfo.getRegionMember().toString() : "null"),
(errorInfo.getNonnullTarget() != null
? SymbolLocation.createLocationFromSymbol(errorInfo.getNonnullTarget())
.tabSeparatedToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static com.uber.nullaway.fixserialization.out.ErrorInfo.EMPTY_NONNULL_TARGET_LOCATION_STRING;

import com.uber.nullaway.fixserialization.SerializationService;
import com.uber.nullaway.fixserialization.Serializer;
import com.uber.nullaway.fixserialization.location.SymbolLocation;
import com.uber.nullaway.fixserialization.out.ErrorInfo;

Expand Down Expand Up @@ -67,8 +66,10 @@ public String serializeError(ErrorInfo errorInfo) {
"\t",
errorInfo.getErrorMessage().getMessageType().toString(),
SerializationService.escapeSpecialCharacters(errorInfo.getErrorMessage().getMessage()),
Serializer.serializeSymbol(errorInfo.getRegionClass()),
Serializer.serializeSymbol(errorInfo.getRegionMember()),
(errorInfo.getRegionClass() != null
? errorInfo.getRegionClass().flatName().toString()
: "null"),
(errorInfo.getRegionMember() != null ? errorInfo.getRegionMember().toString() : "null"),
String.valueOf(errorInfo.getOffset()),
errorInfo.getPath() != null ? errorInfo.getPath().toString() : "null",
(errorInfo.getNonnullTarget() != 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.Serializer;
import javax.lang.model.element.ElementKind;

/** subtype of {@link AbstractSymbolLocation} targeting class fields. */
Expand All @@ -42,9 +41,9 @@ public String tabSeparatedToString() {
return String.join(
"\t",
type.toString(),
Serializer.serializeSymbol(enclosingClass),
enclosingClass.flatName(),
"null",
Serializer.serializeSymbol(variableSymbol),
variableSymbol.toString(),
"null",
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.Serializer;
import javax.lang.model.element.ElementKind;

/** subtype of {@link AbstractSymbolLocation} targeting methods. */
Expand All @@ -42,8 +41,8 @@ public String tabSeparatedToString() {
return String.join(
"\t",
type.toString(),
Serializer.serializeSymbol(enclosingClass),
Serializer.serializeSymbol(enclosingMethod),
enclosingClass.flatName(),
enclosingMethod.toString(),
"null",
"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.google.common.base.Preconditions;
import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.Serializer;
import javax.lang.model.element.ElementKind;

/** subtype of {@link AbstractSymbolLocation} targeting a method parameter. */
Expand Down Expand Up @@ -63,9 +62,9 @@ public String tabSeparatedToString() {
return String.join(
"\t",
type.toString(),
Serializer.serializeSymbol(enclosingClass),
Serializer.serializeSymbol(enclosingMethod),
Serializer.serializeSymbol(paramSymbol),
enclosingClass.flatName(),
enclosingMethod.toString(),
paramSymbol.toString(),
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.out;

import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.Serializer;
import com.uber.nullaway.fixserialization.location.SymbolLocation;

/**
Expand All @@ -50,7 +49,7 @@ public FieldInitializationInfo(Symbol.MethodSymbol initializerMethod, Symbol fie
public String tabSeparatedToString() {
return initializerMethodLocation.tabSeparatedToString()
+ '\t'
+ Serializer.serializeSymbol(field);
+ field.getSimpleName().toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.sun.source.util.TreePath;
import com.uber.nullaway.ErrorMessage;
import com.uber.nullaway.fixserialization.Serializer;
import com.uber.nullaway.fixserialization.location.SymbolLocation;
import java.util.Objects;

Expand Down Expand Up @@ -76,8 +75,10 @@ public String tabSeparatedToString() {
symbolLocation.tabSeparatedToString(),
errorMessage.getMessageType().toString(),
"nullable",
Serializer.serializeSymbol(classAndMemberInfo.getClazz()),
Serializer.serializeSymbol(classAndMemberInfo.getMember()));
(classAndMemberInfo.getClazz() == null ? "null" : classAndMemberInfo.getClazz().flatName()),
(classAndMemberInfo.getMember() == null
? "null"
: classAndMemberInfo.getMember().toString()));
}

/** Finds the class and member of program point where triggered this type change. */
Expand Down

0 comments on commit ce7e084

Please sign in to comment.