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


Java TypeDeclSnippet類代碼示例

本文整理匯總了Java中jdk.jshell.TypeDeclSnippet的典型用法代碼示例。如果您正苦於以下問題:Java TypeDeclSnippet類的具體用法?Java TypeDeclSnippet怎麽用?Java TypeDeclSnippet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeDeclSnippet類屬於jdk.jshell包,在下文中一共展示了TypeDeclSnippet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import jdk.jshell.TypeDeclSnippet; //導入依賴的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

示例2: testReplaceClassToClass

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testReplaceClassToClass() {
    TypeDeclSnippet a = classKey(assertEval("class A {}"));
    assertTypeDeclSnippet(a, "A", VALID, CLASS_SUBKIND, 0, 0);
    TypeDeclSnippet b = classKey(assertEval("class B extends A {}"));
    TypeDeclSnippet c = classKey(assertEval("class C extends B {}"));
    TypeDeclSnippet d = classKey(assertEval("class D extends C {}"));
    assertEval("class A { int x; public String toString() { return \"NEW\"; } }",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
            ste(b, VALID, VALID, true, MAIN_SNIPPET),
            ste(c, VALID, VALID, true, b),
            ste(d, VALID, VALID, true, c));
    assertTypeDeclSnippet(b, "B", VALID, CLASS_SUBKIND, 0, 0);
    assertTypeDeclSnippet(c, "C", VALID, CLASS_SUBKIND, 0, 0);
    assertTypeDeclSnippet(d, "D", VALID, CLASS_SUBKIND, 0, 0);
    assertEval("new D();", "NEW");
    assertActiveKeys();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ReplaceTest.java

示例3: testVarValue1

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testVarValue1() {
    VarSnippet v1 = varKey(assertEval("und1 a;", added(RECOVERABLE_NOT_DEFINED)));
    badVarValue(v1);
    VarSnippet v2 = varKey(assertEval("und2 a;",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(v1, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    badVarValue(v2);
    TypeDeclSnippet und = classKey(assertEval("class und2 {}",
            added(VALID),
            ste(v2, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET)));
    assertVarValue(v2, "null");
    assertDrop(und,
            DiagCheck.DIAG_OK,
            DiagCheck.DIAG_ERROR,
            ste(und, VALID, DROPPED, true, null),
            ste(v2, VALID, RECOVERABLE_NOT_DEFINED, true, und));
    badVarValue(v1);
    badVarValue(v2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:VariablesTest.java

示例4: testSignature1

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testSignature1() {
    VarSnippet v1 = varKey(assertEval("und1 a;", added(RECOVERABLE_NOT_DEFINED)));
    assertVariableDeclSnippet(v1, "a", "und1", RECOVERABLE_NOT_DEFINED, VAR_DECLARATION_SUBKIND, 1, 0);
    VarSnippet v2 = varKey(assertEval("und2 a;",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(v1, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertVariableDeclSnippet(v2, "a", "und2", RECOVERABLE_NOT_DEFINED, VAR_DECLARATION_SUBKIND, 1, 0);
    TypeDeclSnippet und = classKey(assertEval("class und2 {}",
            added(VALID),
            ste(v2, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET)));
    assertVariableDeclSnippet(v2, "a", "und2", VALID, VAR_DECLARATION_SUBKIND, 0, 0);
    assertDrop(und,
            DiagCheck.DIAG_OK,
            DiagCheck.DIAG_ERROR,
            ste(und, VALID, DROPPED, true, null),
            ste(v2, VALID, RECOVERABLE_NOT_DEFINED, true, und));
    assertVariableDeclSnippet(v2, "a", "und2", RECOVERABLE_NOT_DEFINED, VAR_DECLARATION_SUBKIND, 1, 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:VariablesTest.java

示例5: testSignature1

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testSignature1() {
    TypeDeclSnippet c1 = classKey(assertEval("class A extends B {}", added(RECOVERABLE_NOT_DEFINED)));
    assertTypeDeclSnippet(c1, "A", RECOVERABLE_NOT_DEFINED, CLASS_SUBKIND, 1, 0);
    TypeDeclSnippet c2 = classKey(assertEval("@interface A { Class<B> f() default B.class; }",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(c1, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertTypeDeclSnippet(c2, "A", RECOVERABLE_NOT_DEFINED, ANNOTATION_TYPE_SUBKIND, 1, 0);
    TypeDeclSnippet c3 = classKey(assertEval("enum A {; private A(B b) {} }",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(c2, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertTypeDeclSnippet(c3, "A", RECOVERABLE_NOT_DEFINED, ENUM_SUBKIND, 1, 0);
    TypeDeclSnippet c4 = classKey(assertEval("interface A extends B {}",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(c3, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertTypeDeclSnippet(c4, "A", RECOVERABLE_NOT_DEFINED, INTERFACE_SUBKIND, 1, 0);
    TypeDeclSnippet c5 = classKey(assertEval("class A { void f(B b) {} }",
            ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, null),
            ste(c4, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertTypeDeclSnippet(c5, "A", RECOVERABLE_NOT_DEFINED, CLASS_SUBKIND, 1, 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ClassesTest.java

示例6: testReplaceMethodToClass

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testReplaceMethodToClass() {
    Snippet x = methodKey(assertEval("int x() { return 0; }"));
    Snippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
    assertEval("x() == 0;", "true");
    assertEval("new A().a == 0.0;", "true");
    assertEval("double x() { return 2.5; }",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
    assertEval("x();", "2.5");
    Collection<TypeDeclSnippet> classes = getState().types();
    assertEquals(classes.size(), 1);
    assertTrue(c == classes.iterator().next(), "Identity must not change");
    assertEval("x() == 2.5;", "true");
    assertEval("new A().a == 10.0;", "true");
    assertActiveKeys();
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:17,代碼來源:ReplaceTest.java

示例7: testReplaceVarToClass

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testReplaceVarToClass() {
    Snippet x = varKey(assertEval("int x;"));
    TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x; }"));
    assertEval("x == 0;", "true");
    assertEval("new A().a == 0.0;", "true");
    assertEval("double x = 2.5;",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
    identityMatch(getState().types(), c);
    assertEval("x == 2.5;", "true");
    assertEval("new A().a == 10.0;", "true");
    assertActiveKeys();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ReplaceTest.java

示例8: testReplaceMethodToClass

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testReplaceMethodToClass() {
    Snippet x = methodKey(assertEval("int x() { return 0; }"));
    TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
    assertEval("x() == 0;", "true");
    assertEval("new A().a == 0.0;", "true");
    assertEval("double x() { return 2.5; }",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
    assertEval("x();", "2.5");
    identityMatch(getState().types(), c);
    assertEval("x() == 2.5;", "true");
    assertEval("new A().a == 10.0;", "true");
    assertActiveKeys();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ReplaceTest.java

示例9: testTwoSnippetEventListeners

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testTwoSnippetEventListeners() {
    SnippetListener listener1 = new SnippetListener();
    SnippetListener listener2 = new SnippetListener();

    Subscription subscription1 = getState().onSnippetEvent(listener1);
    getState().onSnippetEvent(listener2);

    TypeDeclSnippet a = classKey(assertEval("class A {}"));
    assertEval("interface A {}",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(a, VALID, OVERWRITTEN, false, null));
    DeclarationSnippet f = (DeclarationSnippet) assertDeclareFail("double f() { }", "compiler.err.missing.ret.stmt");
    assertEvalException("throw new RuntimeException();");
    assertEval("int a = 0;");

    List<SnippetEvent> events1 = Collections.unmodifiableList(listener1.getEvents());
    assertEquals(events1, listener2.getEvents(), "Checking got events");
    getState().unsubscribe(subscription1);

    assertDrop(f, DiagCheck.DIAG_IGNORE, DiagCheck.DIAG_IGNORE, ste(f, REJECTED, DROPPED, false, null));
    assertEval("void f() { }", added(VALID));
    assertEvalException("throw new RuntimeException();");
    assertEquals(listener1.getEvents(), events1, "Checking that unsubscribed listener does not get events");

    List<SnippetEvent> events2 = new ArrayList<>(listener2.getEvents());
    events2.removeAll(events1);

    assertEquals(events2.size(), 3, "The second listener got events");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:SnippetStatusListenerTest.java

示例10: testSnippets

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testSnippets() {
    VarSnippet sx = varKey(assertEval("int x = 5;"));
    VarSnippet sfoo = varKey(assertEval("String foo;"));
    MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
    MethodSnippet svv = methodKey(assertEval("void vv() { }"));
    TypeDeclSnippet sc = classKey(assertEval("class C { }"));
    TypeDeclSnippet si = classKey(assertEval("interface I { }"));
    ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
    getState().close();
    assertStreamMatch(getState().snippets(), sx, sfoo, smm, svv, sc, si, simp);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:JShellStateClosedTest.java

示例11: testSignature2

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testSignature2() {
    TypeDeclSnippet c1 = (TypeDeclSnippet) assertDeclareFail("class A { void f() { return g(); } }", "compiler.err.prob.found.req");
    assertTypeDeclSnippet(c1, "A", REJECTED, CLASS_SUBKIND, 0, 2);
    TypeDeclSnippet c2 = classKey(assertEval("class A { int f() { return g(); } }",
            ste(c1, NONEXISTENT, RECOVERABLE_DEFINED, true, null)));
    assertTypeDeclSnippet(c2, "A", RECOVERABLE_DEFINED, CLASS_SUBKIND, 1, 0);
    assertDrop(c2,
            ste(c2, RECOVERABLE_DEFINED, DROPPED, true, null));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ClassesTest.java

示例12: testSnippets

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testSnippets() {
    assertStreamMatch(getState().snippets());
    VarSnippet sx = varKey(assertEval("int x = 5;"));
    VarSnippet sfoo = varKey(assertEval("String foo;"));
    MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
    MethodSnippet svv = methodKey(assertEval("void vv() { }"));
    assertStreamMatch(getState().snippets(), sx, sfoo, smm, svv);
    TypeDeclSnippet sc = classKey(assertEval("class C { }"));
    TypeDeclSnippet si = classKey(assertEval("interface I { }"));
    ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
    assertStreamMatch(getState().snippets(), sx, sfoo, smm, svv, sc, si, simp);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:JShellQueryTest.java

示例13: testVars

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testVars() {
    assertStreamMatch(getState().variables());
    VarSnippet sx = varKey(assertEval("int x = 5;"));
    VarSnippet sfoo = varKey(assertEval("String foo;"));
    MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
    MethodSnippet svv = methodKey(assertEval("void vv() { }"));
    assertStreamMatch(getState().variables(), sx, sfoo);
    TypeDeclSnippet sc = classKey(assertEval("class C { }"));
    TypeDeclSnippet si = classKey(assertEval("interface I { }"));
    ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
    assertStreamMatch(getState().variables(), sx, sfoo);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:JShellQueryTest.java

示例14: testMethods

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testMethods() {
    assertStreamMatch(getState().methods());
    VarSnippet sx = varKey(assertEval("int x = 5;"));
    VarSnippet sfoo = varKey(assertEval("String foo;"));
    MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
    MethodSnippet svv = methodKey(assertEval("void vv() { }"));
    TypeDeclSnippet sc = classKey(assertEval("class C { }"));
    TypeDeclSnippet si = classKey(assertEval("interface I { }"));
    ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
    assertStreamMatch(getState().methods(), smm, svv);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:JShellQueryTest.java

示例15: testTypes

import jdk.jshell.TypeDeclSnippet; //導入依賴的package包/類
public void testTypes() {
    assertStreamMatch(getState().types());
    VarSnippet sx = varKey(assertEval("int x = 5;"));
    VarSnippet sfoo = varKey(assertEval("String foo;"));
    MethodSnippet smm = methodKey(assertEval("int mm() { return 6; }"));
    MethodSnippet svv = methodKey(assertEval("void vv() { }"));
    TypeDeclSnippet sc = classKey(assertEval("class C { }"));
    TypeDeclSnippet si = classKey(assertEval("interface I { }"));
    ImportSnippet simp = importKey(assertEval("import java.lang.reflect.*;"));
    assertStreamMatch(getState().types(), sc, si);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:JShellQueryTest.java


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