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.

2
  • 1
    Java is not java script. Commented Oct 17, 2018 at 18:13
  • Ecmascript parser for Java Commented Oct 17, 2018 at 18:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.