in legacy/java/piranha/src/main/java/com/uber/piranha/XPFlagCleaner.java [1180:1229]
private void recursiveScanTestMethodStats(
BlockTree blockTree, VisitorState state, TestMethodCounters counters, int depth) {
for (StatementTree statement : blockTree.getStatements()) {
if (statement.getKind().equals(Tree.Kind.BLOCK)) {
recursiveScanTestMethodStats(blockTree, state, counters, depth + 1);
} else if (statement.getKind().equals(Kind.EXPRESSION_STATEMENT)) {
counters.statements += 1;
ExpressionTree expr = ((ExpressionStatementTree) statement).getExpression();
if (!expr.getKind().equals(Kind.METHOD_INVOCATION)) {
continue;
}
MethodInvocationTree mit = (MethodInvocationTree) expr;
if (!mit.getMethodSelect().getKind().equals(Tree.Kind.MEMBER_SELECT)) {
continue; // Can't resolve to API call
}
// We scan for config method records of type SET_* here directly, since getXPAPI(...) will
// resolve
// only when the flag name matches, and we want to verify that no calls are being made to
// set
// unrelated flags (i.e. count them in counters.allSetters).
for (PiranhaMethodRecord methodRecord : config.getMethodRecordsForName(mit, state)) {
if (methodRecord.getApiType().equals(XPFlagCleaner.API.SET_TREATED)) {
counters.allSetters += 1;
// If the test is asking for the flag in treated condition, but we are setting it to
// control (in a top level statement), then this test is obsolete.
// Remember that we are scanning for all setters, however, so now we must check that
// call is for the
// flag being passed to Piranha.
if (!isTreated && depth == 0) {
if (getXPAPI(mit, state).equals(API.SET_TREATED)) {
counters.topLevelObsoleteSetters += 1;
}
}
} else if (methodRecord.getApiType().equals(XPFlagCleaner.API.SET_CONTROL)) {
counters.allSetters += 1;
// Analogous to the case above, but now we are checking if the test is asking for the
// flag in the control
// condition, while we are setting it to treated everywhere
if (isTreated && depth == 0) {
if (getXPAPI(mit, state).equals(API.SET_CONTROL)) {
counters.topLevelObsoleteSetters += 1;
}
}
}
}
} else {
counters.statements += 1;
}
}
}