I want to use JavaParser in order to change all String variable values in a Java source code from any value to ""
.
I can change the value of the global variables, but I cannot manage to change the value of the method level variables.
Looking around, I got help from this and this answers and now I can get the value of every line of code in each method, like so:
static void removeStrings(CompilationUnit cu) {
for (TypeDeclaration typeDec : cu.getTypes()) {
List<BodyDeclaration> members = typeDec.getMembers();
if (members != null) {
for (BodyDeclaration member : members) {
if (member.isMethodDeclaration()) { // If it is a method variable
MethodDeclaration method = (MethodDeclaration) member;
Optional<BlockStmt> block = method.getBody();
NodeList<Statement> statements = block.get().getStatements();
for (Statement tmp : statements) {
// How do I change the values here?
}
}
}
}
}
}
Now, how do I change the values of tmp
if it is a String declaration?