in legacy/java/piranha/src/main/java/com/uber/piranha/XPFlagCleaner.java [786:830]
public Description matchImport(ImportTree importTree, VisitorState visitorState) {
if (shouldSkip(visitorState)) return Description.NO_MATCH;
if (importTree.isStatic()) {
Tree importIdentifier = importTree.getQualifiedIdentifier();
if (importIdentifier.getKind().equals(Kind.MEMBER_SELECT)) {
MemberSelectTree memberSelectTree = (MemberSelectTree) importIdentifier;
String[] fullyQualifiedNameParts = memberSelectTree.getIdentifier().toString().split("\\.");
Preconditions.checkArgument(
fullyQualifiedNameParts.length > 0,
"String.split should never produce a zero-length array. "
+ "The worst case should be the original string wrapped in a length 1 array.");
String importSimpleName = fullyQualifiedNameParts[fullyQualifiedNameParts.length - 1];
if (importSimpleName.equals(xpFlagName)
|| (treatmentGroupsEnum != null
&& memberSelectTree.getExpression().toString().startsWith(treatmentGroupsEnum))) {
return buildDescription(importTree)
.addFix(SuggestedFix.replace(importTree, "", 0, 1))
.build();
} else if (treatmentGroup.length() > 0 && treatmentGroupsEnum == null) {
// Check if this import is for values in the same enum that includes the treatmentGroup
Symbol importSymbol = ASTHelpers.getSymbol(memberSelectTree.getExpression());
if (importSymbol.getKind().equals(ElementKind.ENUM)
&& isTreatmentGroupEnum((Symbol.ClassSymbol) importSymbol)) {
treatmentGroupsEnum = ((Symbol.ClassSymbol) importSymbol).fullname.toString();
return buildDescription(importTree)
.addFix(SuggestedFix.replace(importTree, "", 0, 1))
.build();
}
} else {
// Check if this import matches an enum whose field value matches the flag name to remove
String enumName = memberSelectTree.getIdentifier().toString();
Symbol importSymbol = ASTHelpers.getSymbol(memberSelectTree.getExpression());
if (importSymbol.getKind().equals(ElementKind.ENUM)
&& isEnumConstantMatchingFlagName(
enumName, (Symbol.ClassSymbol) importSymbol, visitorState)) {
return buildDescription(importTree)
.addFix(SuggestedFix.replace(importTree, "", 0, 1))
.build();
}
}
}
}
return Description.NO_MATCH;
}