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


Java Options类代码示例

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


Options类属于jdk.nashorn.internal.runtime.options包,在下文中一共展示了Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evalTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@Test
public void evalTest() {
    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 {
        String code = "22 + 10";
        assertTrue(32.0 == ((Number)(eval(cx, "<evalTest>", code))).doubleValue());

        code = "obj = { js: 'nashorn' }; obj.js";
        assertEquals(eval(cx, "<evalTest2>", code), "nashorn");
    } finally {
        Context.setGlobal(oldGlobal);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ContextTest.java

示例2: compileErrorTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的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

示例3: setupTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    final Options options = new Options("nashorn");
    options.set("compile.only", true);
    options.set("print.ast", true);
    options.set("print.parse", true);
    options.set("scripting", true);
    options.set("const.as.var", true);
    options.set("verify.code", true);

    final ErrorManager errors = new ErrorManager() {
        @Override
        public void error(final String msg) {
            log(msg);
        }
    };

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    this.context = new Context(options, errors, pw, pw, Thread.currentThread().getContextClassLoader());
    this.global = context.createGlobal();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:CompilerTest.java

示例4: makeContext

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
private static Context makeContext(InputStream in, OutputStream out, OutputStream err, String[] args) {

        PrintStream pout = out instanceof PrintStream?(PrintStream)out:new PrintStream(out);
        PrintStream perr = err instanceof PrintStream?(PrintStream)err:new PrintStream(err);
        PrintWriter wout = new PrintWriter(pout, true);
        PrintWriter werr = new PrintWriter(perr, true);
        ErrorManager errors = new ErrorManager(werr);
        Options options = new Options("nashorn", werr);
        if(args != null) {
            try {
                options.process(args);
            } catch (IllegalArgumentException var27) {
                werr.println(bundle.getString("shell.usage"));
                options.displayHelp(var27);
                return null;
            }
        }
        return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader());
    }
 
开发者ID:StallionCMS,项目名称:stallion-core,代码行数:20,代码来源:JavascriptShell.java

示例5: setupTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    final Options options = new Options("nashorn");
    options.set("anon.functions", true);
    options.set("compile.only", true);
    options.set("print.ast", true);
    options.set("print.parse", true);
    options.set("scripting", true);
    options.set("const.as.var", true);
    options.set("verify.code", true);

    final ErrorManager errors = new ErrorManager() {
        @Override
        public void error(final String msg) {
            log(msg);
        }
    };

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    this.context = new Context(options, errors, pw, pw, Thread.currentThread().getContextClassLoader());
    this.global = context.createGlobal();
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:24,代码来源:CompilerTest.java

示例6: createAstSerializerExecutorService

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
/**
 * Creates the AST serializer executor service used for in-memory serialization of split functions' ASTs.
 * It is created with an unbounded queue (so it can queue any number of pending tasks). Its core and max
 * threads is the same, but they are all allowed to time out so when there's no work, they can all go
 * away. The threads will be daemons, and they will time out if idle for a minute. Their priority is also
 * slightly lower than normal priority as we'd prefer the CPU to keep running the program; serializing
 * split function is a memory conservation measure (it allows us to release the AST), it can wait a bit.
 * @return an executor service with above described characteristics.
 */
private static ExecutorService createAstSerializerExecutorService() {
    final int threads = Math.max(1, Options.getIntProperty("nashorn.serialize.threads", Runtime.getRuntime().availableProcessors() / 2));
    final ThreadPoolExecutor service = new ThreadPoolExecutor(threads, threads, 1L, TimeUnit.MINUTES, new LinkedBlockingDeque<Runnable>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(final Runnable r) {
                    final Thread t = new Thread(r, "Nashorn AST Serializer");
                    t.setDaemon(true);
                    t.setPriority(Thread.NORM_PRIORITY - 1);
                    return t;
                }
            });
    service.allowCoreThreadTimeOut(true);
    return service;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:25,代码来源:RecompilableScriptFunctionData.java

示例7: NashornAdapter

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @throws LanguageAdapterException
 *         In case of an initialization error
 */
public NashornAdapter() throws LanguageAdapterException
{
	super( "Nashorn", Version.version(), "JavaScript", new NashornScriptEngineFactory().getLanguageVersion(), Arrays.asList( "js", "javascript", "nashorn" ), "js", Arrays.asList( "javascript", "js", "nashorn" ),
		"nashorn" );

	try
	{
		System.setProperty( "nashorn.persistent.code.cache", getCacheDir().getCanonicalPath() );
	}
	catch( IOException x )
	{
		throw new LanguageAdapterException( NashornAdapter.class, "Could not access cache directory: " + getCacheDir(), x );
	}

	PrintWriter out = new PrintWriter( new ExecutionContextWriter(), true );
	PrintWriter err = new PrintWriter( new ExecutionContextErrorWriter(), true );

	// See: jdk.nashorn.internal.runtime.ScriptEnvironment
	Options options = new Options( "nashorn", err );
	options.set( "print.no.newline", true );
	options.set( "persistent.code.cache", true );
	ErrorManager errors = new ErrorManager( err );

	context = new Context( options, errors, out, err, getClass().getClassLoader() );
}
 
开发者ID:tliron,项目名称:scripturian,代码行数:32,代码来源:NashornAdapter.java

示例8: evalTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@Test
public void evalTest() {
    final Options options = new Options("");
    final ErrorManager errors = new ErrorManager();
    final Context cx = new Context(options, errors, Thread.currentThread().getContextClassLoader());
    final ScriptObject oldGlobal = Context.getGlobal();
    Context.setGlobal(cx.createGlobal());
    try {
        String code = "22 + 10";
        assertTrue(32.0 == ((Number)(eval(cx, "<evalTest>", code))).doubleValue());

        code = "obj = { js: 'nashorn' }; obj.js";
        assertEquals(eval(cx, "<evalTest2>", code), "nashorn");
    } finally {
        Context.setGlobal(oldGlobal);
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:18,代码来源:ContextTest.java

示例9: setupTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    final Options options = new Options("nashorn");
    options.set("anon.functions", true);
    options.set("compile.only", true);
    options.set("print.ast", true);
    options.set("print.parse", true);
    options.set("scripting", true);

    final ErrorManager errors = new ErrorManager() {
        @Override
        public void error(final String msg) {
            log(msg);
        }
    };

    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    this.context = new Context(options, errors, pw, pw, Thread.currentThread().getContextClassLoader());
    this.global = context.createGlobal();
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:22,代码来源:CompilerTest.java

示例10: createBaseCacheDir

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
private static File createBaseCacheDir() {
    if(MAX_FILES == 0 || Options.getBooleanProperty("nashorn.typeInfo.disabled")) {
        return null;
    }
    try {
        return createBaseCacheDirPrivileged();
    } catch(final Exception e) {
        reportError("Failed to create cache dir", e);
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:OptimisticTypesPersistence.java

示例11: getMaxFiles

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
private static int getMaxFiles() {
    final String str = Options.getStringProperty("nashorn.typeInfo.maxFiles", null);
    if (str == null) {
        return DEFAULT_MAX_FILES;
    } else if ("unlimited".equals(str)) {
        return UNLIMITED_FILES;
    }
    return Math.max(0, Integer.parseInt(str));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:OptimisticTypesPersistence.java

示例12: ParserImpl

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
ParserImpl(final String... args) throws IllegalArgumentException {
    Objects.requireNonNull(args);

    // handle the parser specific "--es6-module" option
    boolean seenModuleOption = false;
    for (int idx = 0; idx < args.length; idx++) {
        final String opt = args[idx];
        if (opt.equals("--es6-module")) {
            seenModuleOption = true;
            /*
             * Nashorn parser does not understand parser API specific
             * option. This option implies --language=es6. So, we change
             * the option to --language=es6. Note that if user specified
             * --language=es6 explicitly, that is okay. Nashorn tolerates
             * repeated options!
             */
            args[idx] = "--language=es6";
            break;
        }
    }
    this.moduleMode = seenModuleOption;

    // append "--parse-only to signal to the Nashorn that it
    // is being used in "parse only" mode.
    final String[] newArgs = Arrays.copyOf(args, args.length + 1, String[].class);
    newArgs[args.length] = "--parse-only";
    final Options options = new Options("nashorn");
    options.process(newArgs);
    this.env = new ScriptEnvironment(options,
            new PrintWriter(System.out), new PrintWriter(System.err));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:ParserImpl.java

示例13: createAstSerializerExecutorService

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
/**
 * Creates the AST serializer executor service used for in-memory serialization of split functions' ASTs.
 * It is created with an unbounded queue (so it can queue any number of pending tasks). Its core and max
 * threads is the same, but they are all allowed to time out so when there's no work, they can all go
 * away. The threads will be daemons, and they will time out if idle for a minute. Their priority is also
 * slightly lower than normal priority as we'd prefer the CPU to keep running the program; serializing
 * split function is a memory conservation measure (it allows us to release the AST), it can wait a bit.
 * @return an executor service with above described characteristics.
 */
private static ExecutorService createAstSerializerExecutorService() {
    final int threads = Math.max(1, Options.getIntProperty("nashorn.serialize.threads", Runtime.getRuntime().availableProcessors() / 2));
    final ThreadPoolExecutor service = new ThreadPoolExecutor(threads, threads, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(),
        (r) -> {
            final Thread t = new Thread(r, "Nashorn AST Serializer");
            t.setDaemon(true);
            t.setPriority(Thread.NORM_PRIORITY - 1);
            return t;
        });
    service.allowCoreThreadTimeOut(true);
    return service;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:RecompilableScriptFunctionData.java

示例14: setupTest

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@BeforeClass
public void setupTest() {
    final Options options = new Options("nashorn");
    options.set("parse.only", true);
    options.set("scripting", true);
    options.set("const.as.var", true);

    final ErrorManager errors = new ErrorManager();
    this.context = new Context(options, errors, Thread.currentThread().getContextClassLoader());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ParserTest.java

示例15: beforeClass

import jdk.nashorn.internal.runtime.options.Options; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
    // We must have a Context for the DynamicLinker that Bootstrap.getLinkerServices() will use
    oldGlobal = Context.getGlobal();
    cx = new Context(new Options(""), new ErrorManager(), null);
    Context.setGlobal(cx.createGlobal());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:JDK_8078414_Test.java


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