--- a/langtools/test/jdk/jshell/KullaTesting.java Thu Feb 25 11:28:25 2016 -0800
+++ b/langtools/test/jdk/jshell/KullaTesting.java Mon Feb 29 11:54:06 2016 +0100
@@ -24,6 +24,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringWriter;
+import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
@@ -61,6 +62,7 @@
import jdk.jshell.SourceCodeAnalysis;
import jdk.jshell.SourceCodeAnalysis.CompletionInfo;
import jdk.jshell.SourceCodeAnalysis.Completeness;
+import jdk.jshell.SourceCodeAnalysis.QualifiedNames;
import jdk.jshell.SourceCodeAnalysis.Suggestion;
import jdk.jshell.UnresolvedReferenceException;
import org.testng.annotations.AfterMethod;
@@ -862,6 +864,8 @@
}
private List<String> computeCompletions(String code, Boolean isSmart) {
+ waitIndexingFinished();
+
int cursor = code.indexOf('|');
code = code.replace("|", "");
assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
@@ -874,6 +878,37 @@
.collect(Collectors.toList());
}
+ public void assertInferredType(String code, String expectedType) {
+ String inferredType = getAnalysis().analyzeType(code, code.length());
+
+ assertEquals(inferredType, expectedType, "Input: " + code + ", " + inferredType);
+ }
+
+ public void assertInferredFQNs(String code, String... fqns) {
+ assertInferredFQNs(code, code.length(), false, fqns);
+ }
+
+ 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());
+ }
+
+ protected void waitIndexingFinished() {
+ try {
+ Method waitBackgroundTaskFinished = getAnalysis().getClass().getDeclaredMethod("waitBackgroundTaskFinished");
+
+ waitBackgroundTaskFinished.setAccessible(true);
+ waitBackgroundTaskFinished.invoke(getAnalysis());
+ } catch (Exception ex) {
+ throw new AssertionError("Cannot wait for indexing end.", ex);
+ }
+ }
+
public void assertDocumentation(String code, String... expected) {
int cursor = code.indexOf('|');
code = code.replace("|", "");