}
}
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.replace(CharSequence, CharSequence)
} else if (methodName.equals("replace") && numArgs == 2 &&
isCharSequence(target.getParameterType(0)) &&
isCharSequence(target.getParameterType(1))) {
String arg1 = trackString(expr.getArg(0));
String arg2 = trackString(expr.getArg(1));
Variable result = factory.createVariable(VariableType.STRING);
// if either argument is unknown, give up. [TODO make this better]
if (arg1 == null || arg2 == null) {
factory.addStatement(new StringInit(result, Basic.makeAnyString()));
return result;
}
Replace6 rep = new Replace6(arg1, arg2);
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, rep));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.trim()
} else if (methodName.equals("trim") && numArgs == 0) {
UnaryOperation op = new Trim();
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.substring(int) [this method returns a suffix of the string, starting at the specified index]
} else if (methodName.equals("substring") && numArgs == 1) {
UnaryOperation op = new Postfix();
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.substring(int,int)
} else if (methodName.equals("substring") && numArgs == 2) {
UnaryOperation op;
Integer arg1 = trackInteger(expr.getArg(0));
if (arg1 != null && arg1.intValue() == 0) {
op = new Prefix();
} else {
op = new Substring();
}
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.toLowerCase()
} else if (methodName.equals("toLowerCase") && numArgs == 0) {
UnaryOperation op = new ToLowerCase();
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.toUpperCase()
} else if (methodName.equals("toUpperCase") && numArgs == 0) {
UnaryOperation op = new ToUpperCase();
Variable temp = factory.createVariable(VariableType.STRINGBUFFER);
Variable result = factory.createVariable(VariableType.STRING);
factory.addStatement(new StringBufferInit(temp, callee));
factory.addStatement(new StringBufferUnaryOp(temp, op));
factory.addStatement(new StringFromStringBuffer(result, temp));
return result;
// String.split(String)