當前位置: 首頁>>代碼示例>>Java>>正文


Java DeclarationSnippet類代碼示例

本文整理匯總了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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:JShellTool.java

示例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());
        
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:SnippetHandle.java

示例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());
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:JShellTool.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ForwardReferenceTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForwardReferenceTest.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:KullaTesting.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:DropTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:DropTest.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForwardReferenceImportTest.java


注:本文中的jdk.jshell.DeclarationSnippet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。