untrimmedStr = generateExpression(new AstInorderTraversal(ast), dotNodeResolver, containingMethod);
traverser.fastForwardToNextSiblingOf(ast);
// declare a local variable with the regex pattern in it
int uniq = uniqueNumber.incrementAndGet();
StringBuilderBuilder trimPattern = Implementations.newStringBuilder();
trimPattern.append("^");
if (trimType.equals("LEADING") || trimType.equals("BOTH")) {
trimPattern.append(Stmt.invokeStatic(Comparisons.class, "escapeRegexChar", trimChar));
trimPattern.append("*");
}
trimPattern.append("(.*?)");
if (trimType.equals("TRAILING") || trimType.equals("BOTH")) {
trimPattern.append(Stmt.invokeStatic(Comparisons.class, "escapeRegexChar", trimChar));
trimPattern.append("*");
}
trimPattern.append("$");
containingMethod.append(
Stmt.declareFinalVariable(
"trimmer" + uniq,
RegExp.class,
Stmt.invokeStatic(RegExp.class, "compile", Stmt.load(trimPattern).invoke("toString"))));
return Stmt.nestedCall(
Stmt.loadVariable("trimmer" + uniq).invoke("exec", Stmt.castTo(String.class, Stmt.load(untrimmedStr))
).invoke("getGroup", 1));
}
// for all other functions, we can pre-process the arguments like this:
Statement[] args = new Statement[exprList.getNumberOfChildren()];
for (int i = 0; i < args.length; i++) {
args[i] = generateExpression(traverser, dotNodeResolver, containingMethod);
}
if ("lower".equals(methodNameNode.getOriginalText())) {
return Stmt.castTo(String.class, Stmt.load(args[0])).invoke("toLowerCase");
}
else if ("upper".equals(methodNameNode.getOriginalText())) {
return Stmt.castTo(String.class, Stmt.load(args[0])).invoke("toUpperCase");
}
else if ("concat".equals(methodNameNode.getOriginalText())) {
StringBuilderBuilder sb = Implementations.newStringBuilder();
for (Statement s : args) {
sb.append(s);
}
return Stmt.load(sb).invoke("toString");
}
else if ("substring".equals(methodNameNode.getOriginalText())) {
int uniq = uniqueNumber.incrementAndGet();