i am using java parser to read a java file. then i have problem with how to access variable in each method, then modifying the variable name and type in each method.
public static void main(String[] args) throws Exception {
// creates an input stream for the file to be parsed
FileInputStream in = new FileInputStream("test.java");
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
// change the methods names and parameters
changeMethods(cu);
// prints the changed compilation unit
System.out.println(cu.toString());
}
private static void changeMethods(CompilationUnit cu) {
List<TypeDeclaration> types = cu.getTypes();
for (TypeDeclaration type : types) {
List<BodyDeclaration> members = type.getMembers();
for (BodyDeclaration member : members) {
if (member instanceof MethodDeclaration) {
// what must i do?
}
}
}
}
[UPDATE]
For more details, i have a method such as below:
private double[] getExtremeValues(double[] d) {
double min = Double.MAX_VALUE;
double max = -min;
}
in that method, i just want to modify 'double max' with 'double max1'. The second question, how to get 'double[] d' in the method parameter? Please help! Thanks