private Node replaceExpression(NodeTraversal t, Node expr, Node parent) {
    Node replacement;
    String key = null;
    String replacementString;
    switch (expr.getToken()) {
      case STRING:
        key = expr.getString();
        replacementString = getReplacement(key);
        replacement = IR.string(replacementString);
        break;
      case TEMPLATELIT:
      case ADD:
      case NAME:
        StringBuilder keyBuilder = new StringBuilder();
        Node keyNode = IR.string("");
        replacement = buildReplacement(t, expr, keyNode, keyBuilder);
        key = keyBuilder.toString();
        if (key.equals(placeholderToken)) {
          // There is no static text in expr - only a placeholder - so just return expr directly.
          // In this case, replacement is just the string join ('`' + expr), which is not useful.
          return expr;
        }
        replacementString = getReplacement(key);
        keyNode.setString(replacementString);
        break;
      default:
        // This may be a function call or a variable reference. We don't
        // replace these.
        return expr;
    }

    checkNotNull(key);
    checkNotNull(replacementString);
    recordReplacement(key);

    replacement.useSourceInfoIfMissingFromForTree(expr);
    parent.replaceChild(expr, replacement);
    t.reportCodeChange();
    return replacement;
  }
private Node replaceExpression ( NodeTraversal t , Node expr , Node parent ) { Node replacement ; String key = null ; String replacementString ; switch ( expr . getToken ( ) ) { case STRING : key = expr . getString ( ) ; replacementString = getReplacement ( key ) ; replacement = IR . string ( replacementString ) ; break ; case TEMPLATELIT : case ADD : case NAME : StringBuilder keyBuilder = new StringBuilder ( ) ; Node keyNode = IR . string ( "" ) ; replacement = buildReplacement ( t , expr , keyNode , keyBuilder ) ; key = keyBuilder . toString ( ) ; if ( key . equals ( placeholderToken ) ) { return expr ; } replacementString = getReplacement ( key ) ; keyNode . setString ( replacementString ) ; break ; default : return expr ; } checkNotNull ( key ) ; checkNotNull ( replacementString ) ; recordReplacement ( key ) ; replacement . useSourceInfoIfMissingFromForTree ( expr ) ; parent . replaceChild ( expr , replacement ) ; t . reportCodeChange ( ) ; return replacement ; }
Replaces a string expression with a short encoded string expression.

@param t The traversal
@param expr The expression node
@param parent The expression node's parent
@return The replacement node (or the original expression if no replacement is made)