in legacy/java/piranha/src/main/java/com/uber/piranha/XPFlagCleaner.java [497:540]
public boolean isEnumConstantMatchingFlagName(
String enumName, @Nullable Symbol.ClassSymbol classSymbol, VisitorState state) {
if (classSymbol == null) return false;
// Skip any enums that have no configuration
ImmutableCollection<PiranhaEnumRecord> enumRecords =
this.config.getEnumRecordsForName(classSymbol.getSimpleName().toString());
if (enumRecords.isEmpty()) {
return false;
}
// Check cached matches
EnumWithClassSymbol enumWithClassSymbol = new EnumWithClassSymbol(enumName, classSymbol);
if (enumsMatchingConstructorArgsCache.containsKey(enumWithClassSymbol)) {
return enumsMatchingConstructorArgsCache.get(enumWithClassSymbol);
}
// TODO: Find constructor arguments purely through the symbol table; without the need for state
// Then, we will be able remove the following exception
ClassTree enumClassTree = ASTHelpers.findClass(classSymbol, state);
if (enumClassTree == null) {
throw new PiranhaRuntimeException(
"Detected enum constant of class "
+ classSymbol.className()
+ ", which is mentioned by"
+ " Piranha's configuration as part of enumProperties. However, enum definition source"
+ " is not available when looking at this usage (this can happen when cleaning up flags"
+ " across build targets)."
+ "\n\nIf you are trying to use Piranha to clean up enum flags based on the string"
+ " argument to their constructor (e.g. using enumProperties), the current"
+ " implementation will fail to match flag usages on a separate target as that"
+ " containing the enum source, resulting in partial clean up.");
}
Matcher<Tree> matchVarDeclWithNewClassInitPassingFlag =
contains(
VariableTree.class,
PiranhaUtils.variableNameInitializer(
enumName, enumConstructorArgsContainsFlagNameMatcher(enumRecords)));
boolean result = matchVarDeclWithNewClassInitPassingFlag.matches(enumClassTree, state);
enumsMatchingConstructorArgsCache.put(enumWithClassSymbol, result);
return result;
}