当前位置: 首页>>代码示例>>Java>>正文


Java ErrorManager.getNumberOfErrors方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.ErrorManager.getNumberOfErrors方法的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager.getNumberOfErrors方法的具体用法?Java ErrorManager.getNumberOfErrors怎么用?Java ErrorManager.getNumberOfErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.ErrorManager的用法示例。


在下文中一共展示了ErrorManager.getNumberOfErrors方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compileErrorTest

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
@Test
public void compileErrorTest() {
    final Options options = new Options("");
    final ErrorManager errors = new ErrorManager();
    final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
    final Global oldGlobal = Context.getGlobal();
    Context.setGlobal(cx.createGlobal());
    try {
        final ScriptFunction script = cx.compileScript(sourceFor("<evalCompileErrorTest>", "*/"), Context.getGlobal());
        if (script != null) {
            fail("Invalid script compiled without errors");
        }
        if (errors.getNumberOfErrors() != 1) {
            fail("Wrong number of errors: " + errors.getNumberOfErrors());
        }
    } finally {
        Context.setGlobal(oldGlobal);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ContextTest.java

示例2: compileScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Compiles the given script files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, new Source(fileName, new File(fileName)), errors).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            //null - pass no code installer - this is compile only
            new Compiler(env).compile(functionNode);
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:50,代码来源:Shell.java

示例3: compileScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            new Compiler(
                   context,
                   env,
                   null, //null - pass no code installer - this is compile only
                   functionNode.getSource(),
                   context.getErrorManager(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:61,代码来源:Shell.java

示例4: runScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Runs the given JavaScript files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to run
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private int runScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            if ("-".equals(fileName)) {
                final int res = readEvalPrint(context, global);
                if (res != SUCCESS) {
                    return res;
                }
                continue;
            }

            final File file = new File(fileName);
            final ScriptFunction script = context.compileScript(sourceFor(fileName, file), global);
            if (script == null || errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            try {
                apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:57,代码来源:Shell.java

示例5: compileScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Compiles the given script files in the command line
 * This is called only when using the --compile-only flag
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to compile
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private static int compileScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            final FunctionNode functionNode = new Parser(env, sourceFor(fileName, new File(fileName)), errors, env._strict, 0, context.getLogger(Parser.class)).parse();

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            Compiler.forNoInstallerCompilation(
                   context,
                   functionNode.getSource(),
                   env._strict | functionNode.isStrict()).
                   compile(functionNode, CompilationPhases.COMPILE_ALL_NO_INSTALL);

            if (env._print_ast) {
                context.getErr().println(new ASTWriter(functionNode));
            }

            if (env._print_parse) {
                context.getErr().println(new PrintVisitor(functionNode));
            }

            if (errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }
        }
    } finally {
        env.getOut().flush();
        env.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:Shell.java

示例6: runScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Runs the given JavaScript files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to run
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private int runScripts(final Context context, final Global global, final List<String> files) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            if ("-".equals(fileName)) {
                final int res = readEvalPrint(context, global);
                if (res != SUCCESS) {
                    return res;
                }
                continue;
            }

            final File file = new File(fileName);
            final ScriptFunction script = context.compileScript(sourceFor(fileName, file), global);
            if (script == null || errors.getNumberOfErrors() != 0) {
                if (context.getEnv()._parse_only && !errors.hasErrors()) {
                    continue; // No error, continue to consume all files in list
                }
                return COMPILATION_ERROR;
            }

            try {
                apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:Shell.java

示例7: parseJSFile

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
private void parseJSFile(final File file, final TestFilter filter) {
    if (VERBOSE) {
        log("Begin parsing " + file.getAbsolutePath());
    }

    try {
        final char[] buffer = readFully(file);
        boolean excluded = false;
        if (filter != null) {
            final String content = new String(buffer);
            excluded = filter.exclude(file, content);
        }

        if (excluded) {
            if (VERBOSE) {
                log("Skipping " + file.getAbsolutePath());
            }
            skipped++;
            return;
        }

        final ErrorManager errors = new ErrorManager() {
            @Override
            public void error(final String msg) {
                log(msg);
            }
        };
        errors.setLimit(0);
        final Source source = sourceFor(file.getAbsolutePath(), buffer);
        new Parser(context.getEnv(), source, errors, context.getEnv()._strict, null).parse();
        if (errors.getNumberOfErrors() > 0) {
            log("Parse failed: " + file.getAbsolutePath());
            failed++;
        } else {
            passed++;
        }
    } catch (final Throwable exp) {
        exp.printStackTrace();
        log("Parse failed: " + file.getAbsolutePath() + " : " + exp);
        if (VERBOSE) {
            exp.printStackTrace(System.out);
        }
        failed++;
    }

    if (VERBOSE) {
        log("Done parsing " + file.getAbsolutePath());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:ParserTest.java

示例8: run

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    final Global oldGlobal = Context.getGlobal();
    try {
        ctxOut.setDelegatee(out);
        ctxErr.setDelegatee(err);
        final ErrorManager errors = context.getErrorManager();
        final Global global = context.createGlobal();
        Context.setGlobal(global);

        // For each file on the command line.
        for (final String fileName : args) {
            if (fileName.startsWith("-")) {
                // ignore options in shared context mode (which was initialized upfront!)
                continue;
            }
            final File file = new File(fileName);
            final ScriptFunction script = context.compileScript(sourceFor(fileName, file.toURI().toURL()), global);

            if (script == null || errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            try {
                ScriptRuntime.apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        Context.setGlobal(oldGlobal);
    }

    return SUCCESS;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:SharedContextEvaluator.java

示例9: runScripts

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
 * Runs the given JavaScript files in the command line
 *
 * @param context the nashorn context
 * @param global the global scope
 * @param files the list of script files to run
 *
 * @return error code
 * @throws IOException when any script file read results in I/O error
 */
private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }
        final ErrorManager errors = context.getErrorManager();

        // For each file on the command line.
        for (final String fileName : files) {
            if ("-".equals(fileName)) {
                final int res = readEvalPrint(context, global);
                if (res != SUCCESS) {
                    return res;
                }
                continue;
            }

            final File file = new File(fileName);
            final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);
            if (script == null || errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            try {
                apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:57,代码来源:Shell.java

示例10: parseJSFile

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
private void parseJSFile(final File file, final TestFilter filter) {
    if (VERBOSE) {
        log("Begin parsing " + file.getAbsolutePath());
    }

    try {
        final char[] buffer = Source.readFully(file);
        boolean excluded = false;
        if (filter != null) {
            final String content = new String(buffer);
            excluded = filter.exclude(file, content);
        }

        if (excluded) {
            if (VERBOSE) {
                log("Skipping " + file.getAbsolutePath());
            }
            skipped++;
            return;
        }

        final ErrorManager errors = new ErrorManager() {
            @Override
            public void error(final String msg) {
                log(msg);
            }
        };
        errors.setLimit(0);
        final Source   source   = new Source(file.getAbsolutePath(), buffer);
        new Parser(context.getEnv(), source, errors).parse();
        if (errors.getNumberOfErrors() > 0) {
            log("Parse failed: " + file.getAbsolutePath());
            failed++;
        } else {
            passed++;
        }
    } catch (final Throwable exp) {
        log("Parse failed: " + file.getAbsolutePath() + " : " + exp);
        if (VERBOSE) {
            exp.printStackTrace(System.out);
        }
        failed++;
    }

    if (VERBOSE) {
        log("Done parsing " + file.getAbsolutePath());
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:49,代码来源:ParserTest.java

示例11: run

import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    final ScriptObject oldGlobal = Context.getGlobal();
    try {
        ctxOut.setDelegatee(out);
        ctxErr.setDelegatee(err);
        final ErrorManager errors = context.getErrorManager();
        final ScriptObject global = context.createGlobal();
        Context.setGlobal(global);

        // For each file on the command line.
        for (final String fileName : args) {
            if (fileName.startsWith("-")) {
                // ignore options in shared context mode (which was initialized upfront!)
                continue;
            }
            final File file = new File(fileName);
            ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);

            if (script == null || errors.getNumberOfErrors() != 0) {
                return COMPILATION_ERROR;
            }

            try {
                ScriptRuntime.apply(script, global);
            } catch (final NashornException e) {
                errors.error(e.toString());
                if (context.getEnv()._dump_on_error) {
                    e.printStackTrace(context.getErr());
                }

                return RUNTIME_ERROR;
            }
        }
    } finally {
        context.getOut().flush();
        context.getErr().flush();
        Context.setGlobal(oldGlobal);
    }

    return SUCCESS;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:43,代码来源:SharedContextEvaluator.java


注:本文中的jdk.nashorn.internal.runtime.ErrorManager.getNumberOfErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。