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


Java Snippet.source方法代码示例

本文整理汇总了Java中jdk.jshell.Snippet.source方法的典型用法代码示例。如果您正苦于以下问题:Java Snippet.source方法的具体用法?Java Snippet.source怎么用?Java Snippet.source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.jshell.Snippet的用法示例。


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

示例1: text

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

示例2: create

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

示例3: createStatementsText

import jdk.jshell.Snippet; //导入方法依赖的package包/类
/**
 * Copies all 'non-persistent' statements and expressions into
 * a method.
 */
private void createStatementsText() {
    for (Snippet s : liveSnippets) {
        
        if (s.kind().isPersistent()) {
            // exclude temporaries, the unreferenced ones should be generated
            // as expression statements.
            if (s.subKind() != SubKind.TEMP_VAR_EXPRESSION_SUBKIND) {
                continue;
            }
        }
        
        
        if (!processed.add(s)) {
            // already processed
            continue;
        }
        
        String text = s.source();
        
        if (s.subKind() == SubKind.TEMP_VAR_EXPRESSION_SUBKIND) {
            VarSnippet vs = (VarSnippet)s;
            if (!declared.contains(s)) {
                // those tmp vars not used by persistent snippets are declared locally
                executableContent.
                        append(vs.typeName()).append(" ");
            }
            executableContent.
                    append(vs.name()).
                    append(" = ");
        }
        executableContent.append(text);
        if (!text.endsWith(";") && !text.endsWith("}")) {   // NOI18N
            executableContent.append(";");  // NOI18N
        }
        executableContent.append("\n"); // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:SnippetClassGenerator.java

示例4: prepareDeclarations

import jdk.jshell.Snippet; //导入方法依赖的package包/类
private void prepareDeclarations() {
    for (Snippet s : liveSnippets) {
        if (!s.kind().isPersistent()) {
            continue;
        }
        if (s.kind() == Snippet.Kind.IMPORT) {
            continue;
        }
        if (s.subKind() == SubKind.TEMP_VAR_EXPRESSION_SUBKIND &&
            !declarationsDependsOn(s)) {
            // include ONLY if the snippet is referenced from others
            continue;
        } 
        declared.add(s);
        String text;
        if (declarativeConent.length() > 0) {
            // force some newline
            declarativeConent.append("\n"); // NOI18N
        }
        if (s.subKind() == SubKind.TEMP_VAR_EXPRESSION_SUBKIND) {
            VarSnippet vs = (VarSnippet)s;
            text = vs.typeName() + " " + vs.name(); // NOI18N
            declarativeConent.append(text);
        } else {
            text = s.source();
            declarativeConent.append(text);
            processed.add(s);
        }
        if (!text.endsWith(";") && !text.endsWith("}")) {   // NOI18N
            declarativeConent.append(";");  // NOI18N
        }
        declarativeConent.append("\n"); // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:SnippetClassGenerator.java

示例5: copyImports

import jdk.jshell.Snippet; //导入方法依赖的package包/类
private void copyImports() {
    List<ImportTree> imps = new ArrayList<>();
    for (Snippet s : shellSession.getSnippets(false, true)) {
        if (s.kind() != Snippet.Kind.IMPORT) {
            continue;
        }
        String importText = s.source();
        int ii = importText.indexOf("import");
        if (ii == -1) {
            continue;
        }
        String ident = importText.substring(ii + 6 /* length of import */).trim();
        if (ident.endsWith(";")) {
            ident = ident.substring(0, ident.length() - 1);
        }
        boolean stat = ident.startsWith("static");
        if (stat) {
            // do not import stuff from REPL classes:
            ident = ident.substring(6 /* length of static */).trim();

            if (ident.startsWith("REPL.$$")) {
                continue;
            }
        }
        ExpressionTree qi = copy.getTreeMaker().QualIdent(ident);
        imps.add(copy.getTreeMaker().Import(qi, stat));
    }
    
    CompilationUnitTree t = copy.getCompilationUnit();
    for (ImportTree i : imps) {
        t = copy.getTreeMaker().addCompUnitImport(t, i);
    }
    copy.rewrite(copy.getCompilationUnit(), t);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:SnippetClassGenerator.java

示例6: assertKeyMatch

import jdk.jshell.Snippet; //导入方法依赖的package包/类
public Snippet assertKeyMatch(String input, boolean isExecutable, SubKind expectedSubKind, STEInfo mainInfo, STEInfo... updates) {
    Snippet key = key(assertEval(input, IGNORE_VALUE, mainInfo, updates));
    String source = key.source();
    assertEquals(source, input, "Key \"" + input + "\" source mismatch, got: " + source + ", expected: " + input);
    SubKind subkind = key.subKind();
    assertEquals(subkind, expectedSubKind, "Key \"" + input + "\" subkind mismatch, got: "
            + subkind + ", expected: " + expectedSubKind);
    assertEquals(subkind.isExecutable(), isExecutable, "Key \"" + input + "\", expected isExecutable: "
            + isExecutable + ", got: " + subkind.isExecutable());
    Snippet.Kind expectedKind = getKind(key);
    assertEquals(key.kind(), expectedKind, "Checking kind: ");
    assertEquals(expectedSubKind.kind(), expectedKind, "Checking kind: ");
    return key;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:KullaTesting.java

示例7: assertKey

import jdk.jshell.Snippet; //导入方法依赖的package包/类
public void assertKey(Snippet key, Status expectedStatus, SubKind expectedSubKind) {
    String source = key.source();
    SubKind actualSubKind = key.subKind();
    assertEquals(actualSubKind, expectedSubKind,
            "Expected " + source + " to have the subkind: " + expectedSubKind + ", got: " + actualSubKind);
    Status status = getState().status(key);
    assertEquals(status, expectedStatus, "Expected " + source + " to be "
            + expectedStatus + ", but it is " + status);
    Snippet.Kind expectedKind = getKind(key);
    assertEquals(key.kind(), expectedKind, "Checking kind: ");
    assertEquals(expectedSubKind.kind(), expectedKind, "Checking kind: ");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:KullaTesting.java

示例8: rerunSnippet

import jdk.jshell.Snippet; //导入方法依赖的package包/类
private void rerunSnippet(Snippet snippet) {
    String source = snippet.source();
    cmdout.printf("%s\n", source);
    input.replaceLastHistoryEntry(source);
    processSourceCatchingReset(source);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:JShellTool.java

示例9: handleEvent

import jdk.jshell.Snippet; //导入方法依赖的package包/类
private boolean handleEvent(SnippetEvent ste) {
    Snippet sn = ste.snippet();
    if (sn == null) {
        debug("Event with null key: %s", ste);
        return false;
    }
    List<Diag> diagnostics = state.diagnostics(sn).collect(toList());
    String source = sn.source();
    if (ste.causeSnippet() == null) {
        // main event
        for (Diag d : diagnostics) {
            hardmsg(d.isError()? "jshell.msg.error" : "jshell.msg.warning");
            List<String> disp = new ArrayList<>();
            displayDiagnostics(source, d, disp);
            disp.stream()
                    .forEach(l -> hard("%s", l));
        }

        if (ste.status() != Status.REJECTED) {
            if (ste.exception() != null) {
                if (ste.exception() instanceof EvalException) {
                    printEvalException((EvalException) ste.exception());
                    return true;
                } else if (ste.exception() instanceof UnresolvedReferenceException) {
                    printUnresolvedException((UnresolvedReferenceException) ste.exception());
                } else {
                    hard("Unexpected execution exception: %s", ste.exception());
                    return true;
                }
            } else {
                new DisplayEvent(ste, false, ste.value(), diagnostics).displayDeclarationAndValue();
            }
        } else {
            if (diagnostics.isEmpty()) {
                errormsg("jshell.err.failed");
            }
            return true;
        }
    } else {
        // Update
        if (sn instanceof DeclarationSnippet) {
            List<Diag> other = errorsOnly(diagnostics);

            // display update information
            new DisplayEvent(ste, true, ste.value(), other).displayDeclarationAndValue();
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:JShellTool.java

示例10: handleEvent

import jdk.jshell.Snippet; //导入方法依赖的package包/类
private boolean handleEvent(SnippetEvent ste) {
    Snippet sn = ste.snippet();
    if (sn == null) {
        debug("Event with null key: %s", ste);
        return false;
    }
    List<Diag> diagnostics = state.diagnostics(sn).collect(toList());
    String source = sn.source();
    if (ste.causeSnippet() == null) {
        // main event
        for (Diag d : diagnostics) {
            hardmsg(d.isError()? "jshell.msg.error" : "jshell.msg.warning");
            List<String> disp = new ArrayList<>();
            displayDiagnostics(source, d, disp);
            disp.stream()
                    .forEach(l -> hard("%s", l));
        }

        if (ste.status() != Status.REJECTED) {
            if (ste.exception() != null) {
                if (ste.exception() instanceof EvalException) {
                    printEvalException((EvalException) ste.exception());
                    return true;
                } else if (ste.exception() instanceof UnresolvedReferenceException) {
                    printUnresolvedException((UnresolvedReferenceException) ste.exception());
                } else {
                    hard("Unexpected execution exception: %s", ste.exception());
                    return true;
                }
            } else {
                new DisplayEvent(ste, FormatWhen.PRIMARY, ste.value(), diagnostics)
                        .displayDeclarationAndValue();
            }
        } else {
            if (diagnostics.isEmpty()) {
                errormsg("jshell.err.failed");
            }
            return true;
        }
    } else {
        // Update
        if (sn instanceof DeclarationSnippet) {
            List<Diag> other = errorsOnly(diagnostics);

            // display update information
            new DisplayEvent(ste, FormatWhen.UPDATE, ste.value(), other)
                    .displayDeclarationAndValue();
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:JShellTool.java


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