< prev index next >
test/jdk/jshell/KullaTesting.java
Print this page
*** 22,31 ****
--- 22,32 ----
*/
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;
import java.util.Collection;
import java.util.Collections;
*** 59,68 ****
--- 60,70 ----
import jdk.jshell.VarSnippet;
import jdk.jshell.SnippetEvent;
import jdk.jshell.SourceCodeAnalysis;
import jdk.jshell.SourceCodeAnalysis.CompletionInfo;
import jdk.jshell.SourceCodeAnalysis.Completeness;
+ import jdk.jshell.SourceCodeAnalysis.IndexResult;
import jdk.jshell.SourceCodeAnalysis.Suggestion;
import jdk.jshell.UnresolvedReferenceException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
*** 860,869 ****
--- 862,873 ----
assertTrue(completions.containsAll(expected), String.valueOf(completions));
assertTrue(Collections.disjoint(completions, notExpected), String.valueOf(completions));
}
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);
List<Suggestion> completions =
getAnalysis().completionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now
*** 872,881 ****
--- 876,910 ----
.map(s -> s.continuation)
.distinct()
.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) {
+ waitIndexingFinished();
+
+ IndexResult candidates = getAnalysis().getDeclaredSymbols(code, code.length());
+
+ assertEquals(candidates.getFqns(), Arrays.asList(fqns), "Input: " + code + ", " + candidates.getFqns());
+ }
+
+ 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("|", "");
assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
String documentation = getAnalysis().documentation(code, cursor);
< prev index next >