0

I've been looking for a Javascript parser on Java that can capture and list all Javascript functions, for example

function beforeSave('Test', request, response) {
    response.body = entity.foo;
    if (request.query.isExist('Test', 'foo', entity.foo)) {
        response.error();
    } else {
        response.success();
    }
}

function afterSave('Test', request, response) {
    response.body = 'done';
    response.success();
}

Is there a Javascript parser library for Java that would be able to list all Functions from a given source text as well as get the function bodies as needed.

quarks
  • 33,478
  • 73
  • 290
  • 513

1 Answers1

0

I believe java.util.regex is the right tool for the job.

With that you can search for keywords in strings. Example for getting the body of the function:

import java.util.regex.*;
Pattern p1 = Pattern.compile("function', \"([^\"]*)\"");
Matcher m1 = p1.matcher(String);
System.out.println(String.format("function=%s",m1.group(1)));

To see more about this go to the question here.

I´m not a Java-expert by any means so check out the other question and the documentation of the library for more information.

Alex
  • 12
  • 1
  • 2