I am trying to identify methods in Java source. All was going well, but this one brought my code to a halt because my method did not identify the class name. It was messy in any case, I firstly identified that it was a method, then I ran a second expression to try and extract the class name, which is where it went wrong. Here is my specifics:
example:
public double calculateAmount (int iCode, double dRate, double dAmount) {
Rules:
1. It will always start with
public
2. The datatype may be anything (i.e the
double may be
int,
void, etc)
3. It may or may not include parameters between the parentheses
4. The line will always end with {
I have had advice in a previous question to treat the full source as one string. For a number of reasons and because I am already a long way into line-by-line analysis, I am working one line at a time.
So far I have this but have not been able to resolve it in a Regex tester:
1. I can identify
public :
\bpublic
2. Then we have a space and another word :
\bpublic\s+\w+\s+
3. Then we have my method name - how do I capture this?
\bpublic\s+\w+\s+ ~~~~~~
4. Next we have 2 parentheses, possibly with something in between, but not necessarily
\bpublic\s+\w+\s+ ~~~~~~ \(.*\)
5. We end with a { :
\bpublic\s+\w+\s+ ~~~~~~ \(.*\)\s+\{
Thanks in advance!