I want to ask, is it possible to get full line method using AST Parser in java file?
example:
public double getAverage(int[] data) {
}
i only get method name (getAverage
) using MethodDeclaration
, while i hope full line (public double getAverage(int[] data) {
The second question, how to read closing of the method ( }
) ?
Thanks :)
There is no direct way to do that but you can get all the required information and build the string yourself.
You can use MethodDeclaration.getModifiers() to get the modifier information which will tell you whether it is public or private.
You can use MethodDeclaration.getReturnType2().resolveBinding().getName() to get the name of the return type
and MethodDeclaration.parameters() will give you information about parameters.
one more trick to do is : String signature= MethodDeclaration.toString().split("{")[0];
but this may not be an efficient way to do.
Thank you