本文整理匯總了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());
}