本文整理汇总了Java中jdk.jshell.SourceCodeAnalysis.QualifiedNames类的典型用法代码示例。如果您正苦于以下问题:Java QualifiedNames类的具体用法?Java QualifiedNames怎么用?Java QualifiedNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QualifiedNames类属于jdk.jshell.SourceCodeAnalysis包,在下文中一共展示了QualifiedNames类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertInferredFQNs
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; //导入依赖的package包/类
public void assertInferredFQNs(String code, int simpleNameLen, boolean resolvable, String... fqns) {
waitIndexingFinished();
QualifiedNames candidates = getAnalysis().listQualifiedNames(code, code.length());
assertEquals(candidates.getNames(), Arrays.asList(fqns), "Input: " + code + ", candidates=" + candidates.getNames());
assertEquals(candidates.getSimpleNameLength(), simpleNameLen, "Input: " + code + ", simpleNameLen=" + candidates.getSimpleNameLength());
assertEquals(candidates.isResolvable(), resolvable, "Input: " + code + ", resolvable=" + candidates.isResolvable());
}
示例2: compute
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; //导入依赖的package包/类
@Override
public FixResult compute(JShellTool repl, String code, int cursor) {
QualifiedNames res = repl.analysis.listQualifiedNames(code, cursor);
List<Fix> fixes = new ArrayList<>();
for (String fqn : res.getNames()) {
fixes.add(new Fix() {
@Override
public String displayName() {
return "import: " + fqn;
}
@Override
public void perform(ConsoleReader in) throws IOException {
repl.state.eval("import " + fqn + ";");
in.println("Imported: " + fqn);
in.redrawLine();
}
});
}
if (res.isResolvable()) {
return new FixResult(Collections.emptyList(),
repl.messageFormat("jshell.console.resolvable"));
} else {
String error = "";
if (fixes.isEmpty()) {
error = repl.messageFormat("jshell.console.no.candidate");
}
if (!res.isUpToDate()) {
error += repl.messageFormat("jshell.console.incomplete");
}
return new FixResult(fixes, error);
}
}
示例3: compute
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; //导入依赖的package包/类
@Override
public FixResult compute(TryJShellTool repl, String code, int cursor) {
QualifiedNames res = repl.analysis.listQualifiedNames(code, cursor);
List<Fix> fixes = new ArrayList<>();
for (String fqn : res.getNames()) {
fixes.add(new Fix() {
@Override
public String displayName() {
return "import: " + fqn;
}
@Override
public void perform(ConsoleReader in) throws IOException {
repl.state.eval("import " + fqn + ";");
in.println("Imported: " + fqn);
in.redrawLine();
}
});
}
if (res.isResolvable()) {
return new FixResult(Collections.emptyList(),
"\nThe identifier is resolvable in this context.");
} else {
String error = "";
if (fixes.isEmpty()) {
error = "\nNo candidate fully qualified names found to import.";
}
if (!res.isUpToDate()) {
error += "\nResults may be incomplete; try again later for complete results.";
}
return new FixResult(fixes, error);
}
}
示例4: testSuspendIndexing
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; //导入依赖的package包/类
@Test(enabled = false) //JDK-8150860
public void testSuspendIndexing() throws Exception {
compiler.compile(outDir, "package test; public class FQNTest { }");
String jarName = "test.jar";
compiler.jar(outDir, jarName, "test/FQNTest.class");
Path continueMarkFile = outDir.resolve("continuemark").toAbsolutePath();
Files.createDirectories(continueMarkFile.getParent());
try (Writer w = Files.newBufferedWriter(continueMarkFile)) {}
Path runMarkFile = outDir.resolve("runmark").toAbsolutePath();
Files.deleteIfExists(runMarkFile);
getState().sourceCodeAnalysis();
new Thread() {
@Override public void run() {
assertEval("{new java.io.FileOutputStream(\"" + runMarkFile.toAbsolutePath().toString() + "\").close();" +
" while (java.nio.file.Files.exists(java.nio.file.Paths.get(\"" + continueMarkFile.toString() + "\"))) Thread.sleep(100); }");
}
}.start();
while (!Files.exists(runMarkFile))
Thread.sleep(100);
addToClasspath(compiler.getPath(outDir).resolve(jarName));
String code = "FQNTest";
QualifiedNames candidates = getAnalysis().listQualifiedNames(code, code.length());
assertEquals(candidates.getNames(), Arrays.asList(), "Input: " + code + ", candidates=" + candidates.getNames());
assertEquals(candidates.isUpToDate(), false, "Input: " + code + ", up-to-date=" + candidates.isUpToDate());
Files.delete(continueMarkFile);
waitIndexingFinished();
candidates = getAnalysis().listQualifiedNames(code, code.length());
assertEquals(candidates.getNames(), Arrays.asList("test.FQNTest"), "Input: " + code + ", candidates=" + candidates.getNames());
assertEquals(true, candidates.isUpToDate(), "Input: " + code + ", up-to-date=" + candidates.isUpToDate());
}