I am trying to read some .java
files using a java
code. What I am trying is to find the beginning of all the java methods defined in the .java
file.
Any regular expression
or any other solution to parse a java file to achieve that?
I am trying to read some .java
files using a java
code. What I am trying is to find the beginning of all the java methods defined in the .java
file.
Any regular expression
or any other solution to parse a java file to achieve that?
If you just simply want to extract information, easiest solution would be to compile the target code, and then use reflection to get the names of the methods, etc., like Vinod mentions in the comment above.
If your aim is to modify the actual sources in some way before compilation, or something to that effect, I suppose you are stuck parsing the source text.
A discussion of some lengthy and truly grotesque regular expressions to accomplish method signature matching is discussed here: Regex that Will Match a Java Method Declaration