本文整理汇总了Java中jdk.jshell.JShell.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java JShell.Builder方法的具体用法?Java JShell.Builder怎么用?Java JShell.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.jshell.JShell
的用法示例。
在下文中一共展示了JShell.Builder方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJShellInstance
import jdk.jshell.JShell; //导入方法依赖的package包/类
@Override
protected JShell createJShellInstance() {
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(Lookup.getDefault().lookup(ClassLoader.class));
JShell.Builder b = makeBuilder();
if (execGen != null) {
b.executionEngine(new CaptureExecControl(execGen), Collections.emptyMap());
}
String s = System.getProperty("jshell.logging.properties");
if (s != null) {
b = b.remoteVMOptions(quote("-Djava.util.logging.config.file=" + s));
}
JShell ret = b.build();
return ret;
} finally {
Thread.currentThread().setContextClassLoader(ctxLoader);
}
}
示例2: customizeJShell
import jdk.jshell.JShell; //导入方法依赖的package包/类
public JShell.Builder customizeJShell(JShell.Builder b) {
if (ShellProjectUtils.isModularProject(project)) {
if (requiredModules != null) {
b.compilerOptions("--add-modules", String.join(",", requiredModules)); // NOI18N
}
// extra options to include the modules:
List<String> opts = ShellProjectUtils.launchVMOptions(project);
b.remoteVMOptions(opts.toArray(new String[opts.size()]));
String modPath = addRoots("", ShellProjectUtils.projectRuntimeModulePath(project));
if (!modPath.isEmpty()) {
b.remoteVMOptions("--module-path", modPath);
}
}
return b;
}
示例3: testTempNameGenerator
import jdk.jshell.JShell; //导入方法依赖的package包/类
public void testTempNameGenerator() {
JShell.Builder builder = getBuilder().tempVariableNameGenerator(new Supplier<String>() {
int count = 0;
@Override
public String get() {
return "temp" + ++count;
}
});
try (JShell jShell = builder.build()) {
for (int i = 0; i < 3; ++i) {
VarSnippet v = (VarSnippet) jShell.eval("2 + " + (i + 1)).get(0).snippet();
assertEquals("temp" + (i + 1), v.name(), "Custom id: ");
}
}
}
示例4: build
import jdk.jshell.JShell; //导入方法依赖的package包/类
public CodeEvaluator build() {
JShell.Builder builder = JShell.builder();
if (this.out != null) builder.out(this.out);
if (this.err != null) builder.err(this.err);
JShell shell = builder
.remoteVMOptions(this.vmOpts.toArray(new String[this.vmOpts.size()]))
.compilerOptions(this.compilerOpts.toArray(new String[this.compilerOpts.size()]))
.build();
for (String cp : this.classpath)
shell.addToClasspath(cp);
if (timeout > 0L) {
return new CodeEvaluatorWithTimeout(shell, this.startupScripts, this.timeout, this.timeoutUnit);
} else {
return new CodeEvaluator(shell, this.startupScripts);
}
}
示例5: customizeJShell
import jdk.jshell.JShell; //导入方法依赖的package包/类
@Override
public JShell.Builder customizeJShell(JShell.Builder b) {
b = super.customizeJShell(b);
JavaPlatform pl = ShellProjectUtils.findPlatform(getProject());
if (!ShellProjectUtils.isModularJDK(pl)) {
return b;
}
List<String> addReads = new ArrayList<>();
addReads.add("--add-reads:java.jshell=ALL-UNNAMED");
return b.remoteVMOptions(addReads.toArray(new String[addReads.size()]));
}
示例6: makeBuilder
import jdk.jshell.JShell; //导入方法依赖的package包/类
protected JShell.Builder makeBuilder() {
return JShell.builder()
.in(userin)
.out(userout)
.err(usererr)
.tempVariableNameGenerator(()-> "$" + currentNameSpace.tidNext())
.idGenerator((sn, i) -> (currentNameSpace == startNamespace || state.status(sn).isActive())
? currentNameSpace.tid(sn)
: errorNamespace.tid(sn))
.remoteVMOptions(remoteVMOptions.stream().toArray(String[]::new))
.compilerOptions(compilerOptions.stream().toArray(String[]::new));
}
示例7: getBuilder
import jdk.jshell.JShell; //导入方法依赖的package包/类
public JShell.Builder getBuilder() {
TestingInputStream inStream = new TestingInputStream();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayOutputStream errStream = new ByteArrayOutputStream();
return JShell.builder()
.in(inStream)
.out(new PrintStream(outStream))
.err(new PrintStream(errStream));
}
示例8: testResetTempNameGenerator
import jdk.jshell.JShell; //导入方法依赖的package包/类
public void testResetTempNameGenerator() {
JShell.Builder builder = getBuilder().tempVariableNameGenerator(() -> {
throw new AssertionError("Should not be called");
});
try (JShell jShell = builder.tempVariableNameGenerator(null).build()) {
jShell.eval("2 + 2");
}
}
示例9: testIdGenerator
import jdk.jshell.JShell; //导入方法依赖的package包/类
public void testIdGenerator() {
JShell.Builder builder = getBuilder().idGenerator(((snippet, id) -> "custom" + id));
try (JShell jShell = builder.build()) {
List<SnippetEvent> eval = jShell.eval("int a, b;");
checkIds(eval);
checkIds(jShell.drop(eval.get(0).snippet()));
}
}
示例10: testResetIdGenerator
import jdk.jshell.JShell; //导入方法依赖的package包/类
public void testResetIdGenerator() {
JShell.Builder builder = getBuilder().idGenerator((sn, id) -> {
throw new AssertionError("Should not be called");
});
try (JShell jShell = builder.idGenerator(null).build()) {
jShell.eval("2 + 2");
}
}
示例11: testIdGenerator
import jdk.jshell.JShell; //导入方法依赖的package包/类
public void testIdGenerator() {
JShell.Builder builder = getBuilder().idGenerator(((snippet, id) -> "custom" + id));
try (JShell jShell = builder.build()) {
List<SnippetEvent> eval = jShell.eval("int a, b;");
checkIds(eval);
checkIds(jShell.drop((PersistentSnippet) eval.get(0).snippet()));
}
}
示例12: makeBuilder
import jdk.jshell.JShell; //导入方法依赖的package包/类
@Override
protected JShell.Builder makeBuilder() {
return customizeBuilder(super.makeBuilder());
}
示例13: customizeBuilder
import jdk.jshell.JShell; //导入方法依赖的package包/类
private JShell.Builder customizeBuilder(JShell.Builder b) {
SpecificationVersion v = findSourceVersion();
if (v != null) {
b.compilerOptions("-source", v.toString()); // NOI18N
}
v = findTargetVersion();
if (v != null) {
b.compilerOptions("-target", v.toString()); // NOI18N
}
b.remoteVMOptions("-classpath", quote(createClasspathString())); // NOI18N
ClasspathInfo cpI = getClasspathInfo();
if (LOG.isLoggable(Level.FINEST)) {
StringBuilder sb = new StringBuilder("Starting jshell with ClasspathInfo:");
for (PathKind kind : PathKind.values()) {
if (kind == PathKind.OUTPUT) {
continue;
}
sb.append(kind);
sb.append(": ");
ClassPath cp;
try {
cp = cpI.getClassPath(kind);
} catch (IllegalArgumentException ex) {
sb.append("<not supported>\n");
continue;
}
if (cp == null) {
sb.append("<null>\n");
continue;
}
sb.append("\n");
for (ClassPath.Entry e : cp.entries()) {
sb.append("\t");
sb.append(e.getURL());
sb.append("\n");
}
sb.append("---------------\n");
LOG.log(Level.FINEST, sb.toString());
}
}
customizeBuilderOnJDK9(b);
b.fileManager((Function)this::createJShellFileManager);
return getEnv().customizeJShell(b);
}
示例14: resetState
import jdk.jshell.JShell; //导入方法依赖的package包/类
private void resetState() {
closeState();
// Initialize tool id mapping
mainNamespace = new NameSpace("main", "");
startNamespace = new NameSpace("start", "s");
errorNamespace = new NameSpace("error", "e");
mapSnippet = new LinkedHashMap<>();
currentNameSpace = startNamespace;
// Reset the replayable history, saving the old for restore
replayableHistoryPrevious = replayableHistory;
replayableHistory = ReplayableHistory.emptyHistory();
JShell.Builder builder =
JShell.builder()
.in(userin)
.out(userout)
.err(usererr)
.tempVariableNameGenerator(() -> "$" + currentNameSpace.tidNext())
.idGenerator((sn, i) -> (currentNameSpace == startNamespace || state.status(sn).isActive())
? currentNameSpace.tid(sn)
: errorNamespace.tid(sn))
.remoteVMOptions(options.remoteVmOptions())
.compilerOptions(options.compilerOptions());
if (executionControlSpec != null) {
builder.executionEngine(executionControlSpec);
}
state = builder.build();
shutdownSubscription = state.onShutdown((JShell deadState) -> {
if (deadState == state) {
hardmsg("jshell.msg.terminated");
live = false;
}
});
analysis = state.sourceCodeAnalysis();
live = true;
// Run the start-up script.
// Avoid an infinite loop running start-up while running start-up.
// This could, otherwise, occur when /env /reset or /reload commands are
// in the start-up script.
if (!isCurrentlyRunningStartup) {
try {
isCurrentlyRunningStartup = true;
startUpRun(startup.toString());
} finally {
isCurrentlyRunningStartup = false;
}
}
// Record subsequent snippets in the main namespace.
currentNameSpace = mainNamespace;
}