本文整理汇总了Java中jdk.jshell.DeclarationSnippet类的典型用法代码示例。如果您正苦于以下问题:Java DeclarationSnippet类的具体用法?Java DeclarationSnippet怎么用?Java DeclarationSnippet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeclarationSnippet类属于jdk.jshell包,在下文中一共展示了DeclarationSnippet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unresolved
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
private String unresolved(DeclarationSnippet key) {
List<String> unr = state.unresolvedDependencies(key).collect(toList());
StringBuilder sb = new StringBuilder();
int fromLast = unr.size();
if (fromLast > 0) {
sb.append(" ");
}
for (String u : unr) {
--fromLast;
sb.append(u);
switch (fromLast) {
// No suffix
case 0:
break;
case 1:
sb.append(", and ");
break;
default:
sb.append(", ");
break;
}
}
return sb.toString();
}
示例2: text
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public String text() {
Snippet sn = wrapping.getSnippet();
if (sn == null) {
return null;
}
switch (getKind()) {
case IMPORT:
return ((ImportSnippet)sn).fullname();
case METHOD:
case TYPE_DECL:
case VAR:
return ((DeclarationSnippet)sn).name();
case EXPRESSION:
case STATEMENT:
return sn.source();
case ERRONEOUS:
return null;
default:
throw new AssertionError(getKind().name());
}
}
示例3: snippetCompletion
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
private CompletionProvider snippetCompletion(Supplier<Stream<? extends Snippet>> snippetsSupplier) {
return (prefix, cursor, anchor) -> {
anchor[0] = 0;
int space = prefix.lastIndexOf(' ');
Set<String> prior = new HashSet<>(Arrays.asList(prefix.split(" ")));
if (prior.contains("-all") || prior.contains("-history")) {
return Collections.emptyList();
}
String argPrefix = prefix.substring(space + 1);
return snippetsSupplier.get()
.filter(k -> !prior.contains(String.valueOf(k.id()))
&& (!(k instanceof DeclarationSnippet)
|| !prior.contains(((DeclarationSnippet) k).name())))
.flatMap(k -> (k instanceof DeclarationSnippet)
? Stream.of(String.valueOf(k.id()) + " ", ((DeclarationSnippet) k).name() + " ")
: Stream.of(String.valueOf(k.id()) + " "))
.filter(k -> k.startsWith(argPrefix))
.map(ArgSuggestion::new)
.collect(Collectors.toList());
};
}
示例4: testForwardVarToMethod
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardVarToMethod() {
DeclarationSnippet t = methodKey(assertEval("int t() { return x; }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
assertEvalUnresolvedException("t();", "t", 1, 0);
Snippet x = varKey(assertEval("int x = 33;", "33",
added(VALID),
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("t();", "33");
assertEval("double x = 0.88;",
"0.88", null,
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
assertEvalUnresolvedException("t();", "t", 0, 1);
assertActiveKeys();
}
示例5: testForwardMethodToMethod
import jdk.jshell.DeclarationSnippet; //导入依赖的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();
}
示例6: testForwardClassToMethod
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardClassToMethod() {
DeclarationSnippet t = methodKey(assertEval("int t() { return new A().f(); }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
assertEvalUnresolvedException("t();", "t", 1, 0);
Snippet a = classKey(assertEval(
"class A {\n" +
" int f() { return 10; }\n" +
"}",
added(VALID),
ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("t();", "10");
assertEval(
"class A {\n" +
" double f() { return 88.0; }\n" +
"}",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(MAIN_SNIPPET, VALID, VALID, true, null),
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
assertEvalUnresolvedException("t();", "t", 0, 1);
assertActiveKeys();
}
示例7: testForwardVarToClass
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardVarToClass() {
DeclarationSnippet a = classKey(assertEval("class A { int f() { return g; } }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
Snippet g = varKey(assertEval("int g = 10;", "10",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("new A().f();", "10");
assertEval("double g = 10;", "10.0", 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();
}
示例8: testForwardVarToClassGeneric
import jdk.jshell.DeclarationSnippet; //导入依赖的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();
}
示例9: testForwardVarToClassExtendsImplements
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardVarToClassExtendsImplements() {
DeclarationSnippet ik = classKey(assertEval("interface I { default int ii() { return 1; } }", added(VALID)));
DeclarationSnippet jk = classKey(assertEval("interface J { default int jj() { return 2; } }", added(VALID)));
DeclarationSnippet ck = classKey(assertEval("class C { int cc() { return 3; } }", added(VALID)));
DeclarationSnippet dk = classKey(assertEval("class D extends C implements I,J { int dd() { return g; } }", added(RECOVERABLE_DEFINED)));
DeclarationSnippet ek = classKey(assertEval("class E extends D { int ee() { return 5; } }", added(VALID)));
assertUnresolvedDependencies1(dk, RECOVERABLE_DEFINED, "variable g");
assertEvalUnresolvedException("new D();", "D", 1, 0);
assertEvalUnresolvedException("new E();", "D", 1, 0);
VarSnippet g = varKey(assertEval("int g = 10;", "10",
added(VALID),
ste(dk, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
assertEval("E e = new E();");
assertDrop(g,
ste(g, VALID, DROPPED, true, null),
ste(dk, VALID, RECOVERABLE_DEFINED, false, g));
assertEvalUnresolvedException("new D();", "D", 1, 0);
assertEvalUnresolvedException("new E();", "D", 1, 0);
assertEval("e.ee();", "5");
assertEvalUnresolvedException("e.dd();", "D", 1, 0);
assertEval("e.cc();", "3");
assertEval("e.jj();", "2");
assertEval("e.ii();", "1");
assertActiveKeys();
}
示例10: testForwardVarToEnum
import jdk.jshell.DeclarationSnippet; //导入依赖的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();
}
示例11: testForwardMethodToClass
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardMethodToClass() {
DeclarationSnippet a = classKey(assertEval("class A { int f() { return g(); } }", added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method g()");
assertEval("A foo() { return null; }");
assertEvalUnresolvedException("new A();", "A", 1, 0);
Snippet g = methodKey(assertEval("int g() { return 10; }",
added(VALID),
ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
assertEval("new A().f();", "10");
assertEval("double g() { return 10; }",
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();
}
示例12: getMemberInfo
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public MemberInfo getMemberInfo(Snippet key) {
SubKind subkind = key.subKind();
switch (subkind) {
case CLASS_SUBKIND:
case INTERFACE_SUBKIND:
case ENUM_SUBKIND:
case ANNOTATION_TYPE_SUBKIND:
return new MemberInfo(subkind.name(), ((DeclarationSnippet) key).name());
case METHOD_SUBKIND:
MethodSnippet method = (MethodSnippet) key;
return new MemberInfo(method.signature(), method.name());
case VAR_DECLARATION_SUBKIND:
case VAR_DECLARATION_WITH_INITIALIZER_SUBKIND:
case TEMP_VAR_EXPRESSION_SUBKIND:
VarSnippet var = (VarSnippet) key;
return new MemberInfo(var.typeName(), var.name());
default:
throw new AssertionError("Unknown snippet : " + key.kind() + " in expression " + key.toString());
}
}
示例13: testDropVarToMethod
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testDropVarToMethod() {
Snippet x = varKey(assertEval("int x;"));
DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }"));
assertEval("x == 0;", "true");
assertEval("mu() == 0.0;", "true");
assertDrop(x,
ste(x, VALID, DROPPED, true, null),
ste(method, VALID, RECOVERABLE_DEFINED, false, x));
assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x");
assertEvalUnresolvedException("mu();", "mu", 1, 0);
assertVariables();
assertMethods();
assertActiveKeys();
}
示例14: testDropClassToClass
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testDropClassToClass() {
Snippet a = classKey(assertEval("class A {}"));
Snippet b = classKey(assertEval("class B extends A {}"));
Snippet c = classKey(assertEval("class C extends B {}"));
Snippet d = classKey(assertEval("class D extends C {}"));
assertDrop(a,
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(a, VALID, DROPPED, true, null),
ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a),
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b),
ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c));
assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A");
assertDrop(c,
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null));
assertEval("interface A {}", null, null,
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID));
assertClasses();
assertActiveKeys();
}
示例15: testForwardSingleImportMethodToMethod
import jdk.jshell.DeclarationSnippet; //导入依赖的package包/类
public void testForwardSingleImportMethodToMethod() {
DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
added(RECOVERABLE_DEFINED)));
assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
assertEvalUnresolvedException("string();", "string", 1, 0);
assertEval("import static java.lang.String.format;",
added(VALID),
ste(string, RECOVERABLE_DEFINED, VALID, false, null));
assertEval("string();", "\"string\"");
assertEval("double format(String s) { return 0; }",
DiagCheck.DIAG_OK,
DiagCheck.DIAG_ERROR,
added(VALID),
ste(string, VALID, RECOVERABLE_DEFINED, false, null));
assertEvalUnresolvedException("string();", "string", 0, 1);
assertActiveKeys();
}