本文整理汇总了Java中jdk.jshell.Snippet类的典型用法代码示例。如果您正苦于以下问题:Java Snippet类的具体用法?Java Snippet怎么用?Java Snippet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Snippet类属于jdk.jshell包,在下文中一共展示了Snippet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testForwardSingleImportMethodToClass1
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardSingleImportMethodToClass1() {
Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
added(RECOVERABLE_DEFINED)));
assertEvalUnresolvedException("new A();", "A", 1, 0);
assertEval("import static java.lang.String.format;",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, null));
assertEval("new A().s;", "\"10\"");
Snippet format = methodKey(assertEval("void format(String s, int d) { }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET)));
assertEvalUnresolvedException("new A();", "A", 0, 1);
assertActiveKeys();
assertDrop(format,
ste(format, VALID, DROPPED, true, null),
ste(a, RECOVERABLE_DEFINED, VALID, false, format));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ForwardReferenceImportTest.java
示例2: argsToSnippets
import jdk.jshell.Snippet; //导入依赖的package包/类
/**
* Convert user arguments to a Stream of snippets referenced by those
* arguments.
*
* @param snippetSupplier the base list of possible snippets
* @param args the user's argument to the command, maybe be the empty list
* @return a Stream of referenced snippets or null if no matches to specific
* arg
*/
private <T extends Snippet> Stream<T> argsToSnippets(Supplier<Stream<T>> snippetSupplier,
List<String> args) {
Stream<T> result = null;
for (String arg : args) {
// Find the best match
Stream<T> st = layeredSnippetSearch(snippetSupplier, arg);
if (st == null) {
Stream<Snippet> est = layeredSnippetSearch(state::snippets, arg);
if (est == null) {
errormsg("jshell.err.no.such.snippets", arg);
} else {
errormsg("jshell.err.the.snippet.cannot.be.used.with.this.command",
arg, est.findFirst().get().source());
}
return null;
}
if (result == null) {
result = st;
} else {
result = Stream.concat(result, st);
}
}
return result;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:JShellTool.java
示例3: testForwardImportOnDemandMethodToClass2
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardImportOnDemandMethodToClass2() {
Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
added(RECOVERABLE_DEFINED)));
assertEvalUnresolvedException("new A();", "A", 1, 0);
assertEval("import static java.lang.String.*;",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, null));
assertEval("new A().s();", "\"10\"");
Snippet format = methodKey(assertEval("void format(String s, int d) { }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
assertEvalUnresolvedException("new A();", "A", 0, 1);
assertActiveKeys();
assertDrop(format,
ste(format, VALID, DROPPED, true, null),
ste(a, RECOVERABLE_DEFINED, VALID, false, format));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ForwardReferenceImportTest.java
示例4: testForwardImportOnDemandClassToClass1
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardImportOnDemandClassToClass1() {
Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
added(RECOVERABLE_NOT_DEFINED)));
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
assertEval("import java.util.*;",
added(VALID),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
Snippet list = classKey(assertEval("class List {}",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.cant.resolve.location");
assertActiveKeys();
assertDrop(list,
ste(list, VALID, DROPPED, true, null),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ForwardReferenceImportTest.java
示例5: accept
import jdk.jshell.Snippet; //导入依赖的package包/类
@Override
public void accept(SnippetEvent t) {
Snippet snip = t.snippet();
Snippet.Status stat = t.status();
if (session == null) {
return;
}
if (stat == Snippet.Status.DROPPED ||
stat == Snippet.Status.OVERWRITTEN) {
SnippetHandle h = session.getSnippetRegistry().getHandle(snip);
if (h != null) {
N n = factory.findNode(h);
if (n != null) {
n.fireDisplayNameChange();
}
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SnippetNodes.java
示例6: testForwardSingleImportClassToClass1
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardSingleImportClassToClass1() {
Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
added(RECOVERABLE_NOT_DEFINED)));
assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
assertEval("import java.util.List;",
added(VALID),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
assertEval("import java.util.Arrays;", added(VALID));
assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
Snippet list = classKey(assertEval("class List {}",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
assertActiveKeys();
assertDrop(list,
ste(list, VALID, DROPPED, true, null),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ForwardReferenceImportTest.java
示例7: snippetChange
import jdk.jshell.Snippet; //导入依赖的package包/类
@Override
public void snippetChange(SnippetEvent ev) {
Snippet snip = ev.snippet();
Status stat = ev.status();
Rng snipRange = getInputRange();
switch (stat) {
case VALID:
case RECOVERABLE_DEFINED:
case RECOVERABLE_NOT_DEFINED: {
SnippetData data = new SnippetData(snip);
data.setRange(snipRange);
snippetData.put(snip, data);
break;
}
case DROPPED:
case OVERWRITTEN:
// rejected, but still may be a part of the parsing, unless replaced
case REJECTED:
break;
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SnippetCollector.java
示例8: testForwardImportOnDemandFieldToClass2
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardImportOnDemandFieldToClass2() {
Snippet a = classKey(assertEval("class A { static double pi = PI; }",
added(RECOVERABLE_DEFINED)));
assertEvalUnresolvedException("new A();", "A", 1, 0);
assertEval("import static java.lang.Math.*;",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, true, null));
assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
Snippet list = varKey(assertEval("String PI;",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
assertEvalUnresolvedException("new A();", "A", 0, 1);
assertActiveKeys();
assertDrop(list,
ste(list, VALID, DROPPED, true, null),
ste(a, RECOVERABLE_DEFINED, VALID, true, list));
assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ForwardReferenceImportTest.java
示例9: testMethods
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testMethods() {
assertEval("interface Interface {" +
"default int defaultMethod() { return 0; }" +
"static int staticMethod() { return 0; }" +
"}");
Snippet clazz = classKey(assertEval("class Clazz {" +
"static int staticMethod() { return 0; }" +
"int method() { return 0; }" +
"}"));
assertCompletion("Interface.staticMeth|", "staticMethod()");
assertCompletion("Clazz.staticMeth|", "staticMethod()");
assertCompletion("new Interface() {}.defaultMe||", "defaultMethod()");
assertCompletion("new Clazz().staticMeth|");
assertCompletion("new Clazz().meth|", "method()");
assertEval("class Clazz implements Interface {}",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertCompletion("Clazz.staticMeth|");
assertCompletion("new Clazz() {}.defaultM|", "defaultMethod()");
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:CompletionSuggestionTest.java
示例10: create
import jdk.jshell.Snippet; //导入依赖的package包/类
public static Key create(Snippet snip) {
switch (snip.kind()) {
case IMPORT:
ImportSnippet imp = ((ImportSnippet)snip);
return new Key("I_" + imp.fullname() + (imp.isStatic() ? "*" : ""));
case TYPE_DECL:
TypeDeclSnippet tdecl = ((TypeDeclSnippet)snip);
return new Key("T_" + tdecl.name());
case METHOD:
MethodSnippet method = ((MethodSnippet)snip);
return new Key("M_" + method.name() + ":" + method.signature());
case VAR:
VarSnippet var = (VarSnippet)snip;
return new Key("V_" + var.name() + ":" + var.typeName());
case EXPRESSION:
ExpressionSnippet expr = (ExpressionSnippet)snip;
return new Key("E_" + (expr.name()) + ":" + (expr.typeName()));
case STATEMENT:
case ERRONEOUS:
return new Key("C_" + snip.source());
default:
throw new AssertionError(snip.kind().name());
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SnippetRegistry.java
示例11: testForwardClassToClass3
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardClassToClass3() {
Snippet a = classKey(assertEval("interface A extends B { static int f() { return 10; } }", added(RECOVERABLE_NOT_DEFINED)));
assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
Snippet b = classKey(assertEval("interface B { }",
added(VALID),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
assertEval("A.f();", "10");
assertEval("class B { }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ForwardReferenceTest.java
示例12: testForwardClassToClass1
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardClassToClass1() {
Snippet a = classKey(assertEval("class A { B b = new B(); }", added(RECOVERABLE_NOT_DEFINED)));
assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
added(VALID),
ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
assertEval("new A().b;", "B");
assertEval("interface B { }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(a, VALID, RECOVERABLE_DEFINED, true, MAIN_SNIPPET));
assertEvalUnresolvedException("new A().b;", "A", 0, 1);
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ForwardReferenceTest.java
示例13: classesCyclic1
import jdk.jshell.Snippet; //导入依赖的package包/类
public void classesCyclic1() {
Snippet b = classKey(assertEval("class B extends A { }",
added(RECOVERABLE_NOT_DEFINED)));
Snippet a = classKey(assertEval("class A extends B { }", DiagCheck.DIAG_IGNORE, DiagCheck.DIAG_IGNORE,
added(REJECTED)));
/***
assertDeclareFail("class A extends B { }", "****",
added(REJECTED),
ste(b, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, MAIN_SNIPPET));
***/
// It is random which one it shows up in, but cyclic error should be there
List<Diag> diagsA = getState().diagnostics(a).collect(toList());
List<Diag> diagsB = getState().diagnostics(b).collect(toList());
List<Diag> diags;
if (diagsA.isEmpty()) {
diags = diagsB;
} else {
diags = diagsA;
assertTrue(diagsB.isEmpty());
}
assertEquals(diags.size(), 1, "Expected one error");
assertEquals(diags.get(0).getCode(), "compiler.err.cyclic.inheritance", "Expected cyclic inheritance error");
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ClassesTest.java
示例14: testForwardMethodToMethod
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardMethodToMethod() {
Snippet t = methodKey(assertEval("int t() { return f(); }", added(RECOVERABLE_DEFINED)));
Snippet f = methodKey(assertEval("int f() { return g(); }",
added(RECOVERABLE_DEFINED),
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
assertEvalUnresolvedException("t();", "f", 1, 0);
Snippet g = methodKey(assertEval("int g() { return 55; }",
added(VALID),
ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("t();", "55");
assertEval("double g() { return 3.14159; }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
DeclarationSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
assertTrue(exsn == f, "Identity must not change");
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ForwardReferenceTest.java
示例15: testForwardVarToClassGeneric
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardVarToClassGeneric() {
DeclarationSnippet a = classKey(assertEval("class A<T> { final T x; A(T v) { this.x = v; } ; T get() { return x; } int core() { return g; } }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
List<SnippetEvent> events = assertEval("A<String> as = new A<>(\"hi\");", null,
UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
SnippetEvent ste = events.get(0);
Snippet assn = ste.snippet();
DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
assertEquals(unsn.name(), "A", "Wrong with unresolved");
assertEquals(getState().unresolvedDependencies(unsn).count(), 1, "Wrong size unresolved");
assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
Snippet g = varKey(assertEval("int g = 10;", "10",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
assertEval("A<String> as = new A<>(\"low\");",
ste(MAIN_SNIPPET, VALID, VALID, false, null),
ste(assn, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertEval("as.get();", "\"low\"");
assertUnresolvedDependencies(a, 0);
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ForwardReferenceTest.java
示例16: testForwardVarToEnum
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testForwardVarToEnum() {
DeclarationSnippet a = classKey(assertEval("enum E { Q, W, E; float ff() { return fff; } }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable fff");
Snippet g = varKey(assertEval("float fff = 4.5f;", "4.5",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("E.Q.ff();", "4.5");
assertEval("double fff = 3.3;", "3.3", null,
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
assertUnresolvedDependencies(a, 0);
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ForwardReferenceTest.java
示例17: methodsRedeclaration2
import jdk.jshell.Snippet; //导入依赖的package包/类
public void methodsRedeclaration2() {
assertEval("int a() { return 1; }");
assertMethods(method("()int", "a"));
assertActiveKeys();
Snippet b = methodKey(assertEval("Integer b() { return a(); }"));
assertMethods(method("()int", "a"), method("()Integer", "b"));
assertActiveKeys();
Snippet c = methodKey(assertEval("double c() { return b(); }"));
assertMethods(method("()int", "a"), method("()Integer", "b"), method("()double", "c"));
assertActiveKeys();
assertEval("double b() { return 3.14159; }",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertMethods(method("()int", "a"), method("()double", "b"), method("()double", "c"));
assertEval("c();", "3.14159");
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:MethodsTest.java
示例18: testMethod
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testMethod() {
String src = "void glib() { System.out.println(\"hello\"); }";
List<SnippetWrapper> swl = getState().sourceCodeAnalysis().wrappers(src);
assertEquals(swl.size(), 1, "unexpected list length");
assertWrapperHas(swl.get(0), src, Kind.METHOD, "void", "glib", "println");
assertPosition(swl.get(0), src, 0, 4);
assertPosition(swl.get(0), src, 5, 4);
assertPosition(swl.get(0), src, 15, 6);
Snippet g = methodKey(assertEval(src, added(VALID)));
SnippetWrapper swg = getState().sourceCodeAnalysis().wrapper(g);
assertWrapperHas(swg, src, Kind.METHOD, "void", "glib", "println");
assertPosition(swg, src, 0, 4);
assertPosition(swg, src, 5, 4);
assertPosition(swg, src, 15, 6);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:WrapperTest.java
示例19: bad
import jdk.jshell.Snippet; //导入依赖的package包/类
private String bad(String input, Kind kind, String prevId) {
List<SnippetEvent> events = assertEvalFail(input);
assertEquals(events.size(), 1, "Expected one event, got: " + events.size());
SnippetEvent e = events.get(0);
List<Diag> diagnostics = getState().diagnostics(e.snippet()).collect(toList());
assertTrue(diagnostics.size() > 0, "Expected diagnostics, got none");
assertEquals(e.exception(), null, "Expected exception to be null.");
assertEquals(e.value(), null, "Expected value to be null.");
Snippet key = e.snippet();
assertTrue(key != null, "key must be non-null, but was null.");
assertEquals(key.kind(), kind, "Expected kind: " + kind + ", got: " + key.kind());
SubKind expectedSubKind = kind == Kind.ERRONEOUS ? SubKind.UNKNOWN_SUBKIND : SubKind.METHOD_SUBKIND;
assertEquals(key.subKind(), expectedSubKind, "SubKind: ");
assertTrue(key.id().compareTo(prevId) > 0, "Current id: " + key.id() + ", previous: " + prevId);
assertEquals(getState().diagnostics(key).collect(toList()), diagnostics, "Expected retrieved diagnostics to match, but didn't.");
assertEquals(key.source(), input, "Expected retrieved source: " +
key.source() + " to match input: " + input);
assertEquals(getState().status(key), Status.REJECTED, "Expected status of REJECTED, got: " + getState().status(key));
return key.id();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:RejectedFailedTest.java
示例20: testKeyId3
import jdk.jshell.Snippet; //导入依赖的package包/类
public void testKeyId3() {
Snippet g = methodKey(assertEval("void g() { f(); }", added(RECOVERABLE_DEFINED)));
Snippet f = methodKey(assertEval("void f() { }",
added(VALID),
ste(g, RECOVERABLE_DEFINED, VALID, false, null)));
assertDeclareFail("qqqq;", "compiler.err.cant.resolve.location");
assertEval("interface A { }");
assertKeys(method("()void", "g"), method("()void", "f"),
clazz(KullaTesting.ClassType.INTERFACE, "A"));
assertActiveKeys();
assertEval("double f() { return 0.0; }",
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
assertKeys(method("()void", "g"), clazz(KullaTesting.ClassType.INTERFACE, "A"),
method("()double", "f"));
assertActiveKeys();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:SnippetTest.java
注:本文中的jdk.jshell.Snippet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论