当前位置: 首页>>代码示例>>Java>>正文


Java MethodSnippet类代码示例

本文整理汇总了Java中jdk.jshell.MethodSnippet的典型用法代码示例。如果您正苦于以下问题:Java MethodSnippet类的具体用法?Java MethodSnippet怎么用?Java MethodSnippet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodSnippet类属于jdk.jshell包,在下文中一共展示了MethodSnippet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import jdk.jshell.MethodSnippet; //导入依赖的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: cmdMethods

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
private boolean cmdMethods(String arg) {
    Stream<MethodSnippet> stream = argsOptionsToSnippets(this::allMethodSnippets,
            this::isActive, arg, "/methods");
    if (stream == null) {
        return false;
    }
    stream.forEachOrdered(meth -> {
        String sig = meth.signature();
        int i = sig.lastIndexOf(")") + 1;
        if (i <= 0) {
            hard("  %s", meth.name());
        } else {
            hard("  %s %s%s", sig.substring(i), meth.name(), sig.substring(0, i));
        }
        printSnippetStatus(meth, true);
    });
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:JShellTool.java

示例3: testOverwriteNoUpdate

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testOverwriteNoUpdate() {
    String xsi = "int x = 5;";
    String xsd = "double x = 3.14159;";
    VarSnippet xi = varKey(assertEval(xsi, added(VALID)));
    String ms1 = "double m(Integer i) { return i + x; }";
    String ms2 = "double m(java.lang.Integer i) { return i + x; }";
    MethodSnippet k1 = methodKey(assertEval(ms1, added(VALID)));
    VarSnippet xd = varKey(assertEval(xsd,
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(xi, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
    MethodSnippet k2 = methodKey(assertEval(ms2,
            ste(MAIN_SNIPPET, VALID, VALID, true, null), //TODO: technically, should be false
            ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
    VarSnippet xi2 = varKey(assertEval(xsi,
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(xd, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
    varKey(assertEval(xsd,
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(xi2, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ReplaceTest.java

示例4: getMemberInfo

import jdk.jshell.MethodSnippet; //导入依赖的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

示例5: testBooleanSnippetQueries

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testBooleanSnippetQueries() {
    Snippet nd = varKey(assertEval("blort x;", added(RECOVERABLE_NOT_DEFINED)));
    assertTrue(nd.kind().isPersistent(), "nd.isPersistent");
    Status ndstat = getState().status(nd);
    assertTrue(ndstat.isActive(), "nd.isActive");
    assertFalse(ndstat.isDefined(), "nd.isDefined");
    MethodSnippet g = methodKey(assertEval("void g() { f(); }", added(RECOVERABLE_DEFINED)));
    assertTrue(g.kind().isPersistent(), "g.isPersistent");
    Status gstat = getState().status(g);
    assertTrue(gstat.isActive(), "g.isActive");
    assertTrue(gstat.isDefined(), "g.isDefined");
    getState().drop(g);
    assertTrue(g.kind().isPersistent(), "drop isPersistent");
    gstat = getState().status(g);
    assertFalse(gstat.isActive(), "drop isActive");
    assertFalse(gstat.isDefined(), "drop isDefined");
    Snippet stmt = key(assertEval("if (true) {}", added(VALID)));
    assertFalse(stmt.kind().isPersistent(), "stmt isPersistent");
    Status stmtstat = getState().status(stmt);
    assertTrue(stmtstat.isActive(), "stmt isActive");
    assertTrue(stmtstat.isDefined(), "stmt isDefined");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SnippetTest.java

示例6: cmdMethods

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
private boolean cmdMethods(String arg) {
    Stream<MethodSnippet> stream = argsOptionsToSnippets(this::allMethodSnippets,
            this::isActive, arg, "/methods");
    if (stream == null) {
        return false;
    }
    stream.forEachOrdered(mk
            -> hard("  %s %s", mk.name(), mk.signature())
    );
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:JShellTool.java

示例7: testMethodModifierAnnotation

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testMethodModifierAnnotation() {
    assertEval("@interface A { int value() default 0; }");
    MethodSnippet m4 = (MethodSnippet) assertDeclareWarn1("@A static void m4() {}", "jdk.eval.warn.illegal.modifiers");
    assertMethodDeclSnippet(m4, "m4", "()void", VALID, 0, 1);
    MethodSnippet m5 = (MethodSnippet) assertDeclareWarn1("@A(value=66)final void m5() {}", "jdk.eval.warn.illegal.modifiers");
    assertMethodDeclSnippet(m5, "m5", "()void", VALID, 0, 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:IgnoreTest.java

示例8: testReplaceVarToMethod

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testReplaceVarToMethod() {
    Snippet x = varKey(assertEval("int x;"));
    MethodSnippet musn = methodKey(assertEval("double mu() { return x * 4; }"));
    assertEval("x == 0;", "true");
    assertEval("mu() == 0.0;", "true");
    assertEval("double x = 2.5;",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
    identityMatch(getState().methods(), musn);
    assertEval("x == 2.5;", "true");
    assertEval("mu() == 10.0;", "true");  // Auto redefine
    assertActiveKeys();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ReplaceTest.java

示例9: testOverwriteReplaceMethod

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testOverwriteReplaceMethod() {
    MethodSnippet k1 = methodKey(assertEval("String m(Integer i) { return i.toString(); }"));
    MethodSnippet k2 = methodKey(assertEval("String m(java.lang.Integer i) { return \"java.lang.\" + i.toString(); }",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
    assertMethodDeclSnippet(k1, "m", "(Integer)String", OVERWRITTEN, 0, 0);
    assertEval("m(6);", "\"java.lang.6\"");
    assertEval("String m(Integer i) { return i.toString(); }",
            ste(MAIN_SNIPPET, VALID, VALID, true, null),
            ste(k2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
    assertMethodDeclSnippet(k2, "m", "(java.lang.Integer)String", OVERWRITTEN, 0, 0);
    assertEval("m(6);", "\"6\"");
    assertActiveKeys();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ReplaceTest.java

示例10: testOverwriteMethodForwardReferenceClass

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testOverwriteMethodForwardReferenceClass() {
    Snippet k1 = methodKey(assertEval("int q(Boo b) { return b.x; }",
            added(RECOVERABLE_NOT_DEFINED)));
    assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
    assertEval("class Boo { int x = 55; }",
            added(VALID),
            ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
    assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
    assertEval("q(new Boo());", "55");
    assertActiveKeys();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ForwardReferenceTest.java

示例11: testOverwriteMethodForwardReferenceClassImport

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void testOverwriteMethodForwardReferenceClassImport() {
    MethodSnippet k1 = methodKey(assertEval("int ff(List lis) { return lis.size(); }",
            added(RECOVERABLE_NOT_DEFINED)));
    assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
    assertEval("import java.util.*;",
            added(VALID),
            ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
    assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
    assertEval("ff(new ArrayList());", "0");
    assertActiveKeys();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ForwardReferenceTest.java

示例12: testSnippets

import jdk.jshell.MethodSnippet; //导入依赖的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

示例13: assertMethodDeclSnippet

import jdk.jshell.MethodSnippet; //导入依赖的package包/类
public void assertMethodDeclSnippet(MethodSnippet method,
        String expectedName, String expectedSignature,
        Status expectedStatus, int unressz, int othersz) {
    assertDeclarationSnippet(method, expectedName, expectedStatus,
            METHOD_SUBKIND, unressz, othersz);
    String signature = method.signature();
    assertEquals(signature, expectedSignature,
            "Expected " + method.source() + " to have the name: " +
                    expectedSignature + ", got: " + signature);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:KullaTesting.java

示例14: testSnippets

import jdk.jshell.MethodSnippet; //导入依赖的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

示例15: testVars

import jdk.jshell.MethodSnippet; //导入依赖的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


注:本文中的jdk.jshell.MethodSnippet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。