当前位置: 首页>>代码示例>>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;未经允许,请勿转载。