I wish to parse java source code files, and extract the methods source code.
I would need a method like this :
/** Returns a map with key = method name ; value = method source code */
Map<String,String> getMethods(File javaFile);
Is there a simple way to achieve this, a library to help me build my method, etc. ?
Download the java parser from https://javaparser.org/
You’ll have to write some code. This code will invoke the parser… it will return you a CompilationUnit:
Note: SEDInputStream is a subclass of input stream. You can use a FileInputStream if you want.
You’ll have to create a visitor. Your visitor will be easy because you’re only interested in methods:
To invoke the visitor, do this: