Search in sources :

Example 1 with ResultBuilder

use of com.googlecode.jslint4java.JSLintResult.ResultBuilder in project jslint4java by happygiraffe.

the class JSLint method buildResults.

/**
     * Assemble the {@link JSLintResult} object.
     */
@NeedsContext
private JSLintResult buildResults(final String systemId, final long startNanos, final long endNanos) {
    return (JSLintResult) contextFactory.call(new ContextAction() {

        public Object run(Context cx) {
            ResultBuilder b = new JSLintResult.ResultBuilder(systemId);
            b.duration(TimeUnit.NANOSECONDS.toMillis(endNanos - startNanos));
            for (Issue issue : readErrors(systemId)) {
                b.addIssue(issue);
            }
            // Collect a report on what we've just linted.
            b.report(callReport(false));
            // Extract JSLINT.data() output and set it on the result.
            Object o = lintFunc.get("data", lintFunc);
            // Real JSLINT will always have this, but some of my test stubs don't.
            if (o != UniqueTag.NOT_FOUND) {
                Function reportFunc = (Function) o;
                Scriptable data = (Scriptable) reportFunc.call(cx, lintFunc, null, Context.emptyArgs);
                for (String global : Util.listValueOfType("global", String.class, data)) {
                    b.addGlobal(global);
                }
                b.json(Util.booleanValue("json", data));
                for (JSFunction f : Util.listValue("functions", data, new JSFunctionConverter())) {
                    b.addFunction(f);
                }
            }
            // Extract the list of properties. Note that we don't expose the counts, as it
            // doesn't seem that useful.
            Object properties = lintFunc.get("property", lintFunc);
            if (properties != UniqueTag.NOT_FOUND) {
                for (Object id : ScriptableObject.getPropertyIds((Scriptable) properties)) {
                    b.addProperty(id.toString());
                }
            }
            return b.build();
        }
    });
}
Also used : Context(org.mozilla.javascript.Context) ResultBuilder(com.googlecode.jslint4java.JSLintResult.ResultBuilder) Function(org.mozilla.javascript.Function) ContextAction(org.mozilla.javascript.ContextAction) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable)

Example 2 with ResultBuilder

use of com.googlecode.jslint4java.JSLintResult.ResultBuilder in project jslint4java by happygiraffe.

the class PlainResultFormatterTest method runFormatter.

/**
     * Run the formatter over the current set of issues. The File as input is
     * just a convenient way of passing a name & path together.
     */
private void runFormatter(File file) {
    rf.begin();
    ResultBuilder builder = new JSLintResult.ResultBuilder(file.getName());
    for (Issue issue : issues) {
        builder.addIssue(issue);
    }
    rf.output(builder.build());
    rf.end();
}
Also used : ResultBuilder(com.googlecode.jslint4java.JSLintResult.ResultBuilder) Issue(com.googlecode.jslint4java.Issue)

Aggregations

ResultBuilder (com.googlecode.jslint4java.JSLintResult.ResultBuilder)2 Issue (com.googlecode.jslint4java.Issue)1 Context (org.mozilla.javascript.Context)1 ContextAction (org.mozilla.javascript.ContextAction)1 Function (org.mozilla.javascript.Function)1 Scriptable (org.mozilla.javascript.Scriptable)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1