in legacy/objc/src/XPFlagRefactoring/XPFlagRefactoring.cpp [508:544]
virtual void run(const MatchFinder::MatchResult &Result) {
const IfStmt *s = Result.Nodes.getNodeAs<IfStmt>("ifStmt");
const ObjCMessageExpr *msgExpr =
Result.Nodes.getNodeAs<ObjCMessageExpr>("theSelector");
const StringLiteral *strLiteral =
Result.Nodes.getNodeAs<StringLiteral>("theFlag");
ASTContext *context = Result.Context;
// ensure that the string literal, if it exists, matches the flagName.
if (strLiteral != NULL && strLiteral->getString().compare(flagName)) {
return;
}
const Expr *conditionExpr = Result.Nodes.getNodeAs<Expr>("conditionExpr");
Value v = IS_UNKNOWN;
if (conditionExpr != NULL) {
v = XPUtils::evalExpr(conditionExpr, Result, msgExpr, flagType);
}
if (v == IS_UNKNOWN) {
return;
}
string replacementText = "";
if (v == IS_TRUE) {
replacementText = getReplText(s->getThen(), context);
} else {
const Stmt *Else = s->getElse();
if (Else) {
replacementText = getReplText(Else, context);
}
}
llvm::errs() << "Rewriting in IfStmtHandler \n";
FixItRewriterOptions::rewriteCode(context, rewriter, s->getSourceRange(),
s->getBeginLoc(), replacementText);
}