use of com.twosigma.beakerx.autocomplete.AutocompleteResult in project beakerx by twosigma.
the class JavaEvaluatorAutocompleteClassNameExpressionTest method autocompleteToIntegerClassWithPackage.
@Test
public void autocompleteToIntegerClassWithPackage() throws Exception {
String code = "Integer f = new java.lang.Inte";
// when
AutocompleteResult autocomplete = evaluator().autocomplete(code, code.length());
// then
assertThat(autocomplete.getMatches()).isNotEmpty();
assertThat(autocomplete.getStartIndex()).isEqualTo(code.length() - 4);
}
use of com.twosigma.beakerx.autocomplete.AutocompleteResult in project beakerx by twosigma.
the class JavaEvaluatorAutocompleteClassNameExpressionTest method autocompleteCreateNewIntegerWithPackage.
@Test
public void autocompleteCreateNewIntegerWithPackage() throws Exception {
String code = "new java.lang.Inte";
// when
AutocompleteResult autocomplete = evaluator().autocomplete(code, code.length());
// then
assertThat(autocomplete.getMatches()).isNotEmpty();
assertThat(autocomplete.getStartIndex()).isEqualTo(code.length() - 4);
}
use of com.twosigma.beakerx.autocomplete.AutocompleteResult in project beakerx by twosigma.
the class ScalaAutocompleteTest method autocomplete_internalDeclarationsAreVisible.
@Test
public void autocomplete_internalDeclarationsAreVisible() {
final String lines = "val xyzzy = 32\nxyz";
// when
AutocompleteResult autocomplete = scalaEvaluator.autocomplete(lines, lines.length());
// then
Assertions.assertThat(autocomplete.getMatches()).isNotEmpty();
}
use of com.twosigma.beakerx.autocomplete.AutocompleteResult in project beakerx by twosigma.
the class JavaAutocomplete method findAutocompleteResult.
private AutocompleteResult findAutocompleteResult(String txt, int cur, ClassUtils cu) {
List<AutocompleteCandidate> q = new ArrayList<>();
List<String> ret = new ArrayList<>();
int startIndex = 0;
for (int i = cur - 1; i >= 0; i--) {
if (i < txt.length() && Character.isWhitespace(txt.charAt(i))) {
String tx = txt.substring(i + 1, cur).trim();
if (!txt.isEmpty()) {
if (tx.contains(".")) {
q.add(cu.expandExpression(tx, registry, cu.DO_ALL));
} else {
q.add(new AutocompleteCandidate(JavaCompletionTypes.NAME, tx));
}
ret = registry.searchCandidates(q);
startIndex = txt.indexOf(tx) + tx.length();
}
break;
}
}
return new AutocompleteResult(ret, startIndex);
}
use of com.twosigma.beakerx.autocomplete.AutocompleteResult in project beakerx by twosigma.
the class JavaAutocomplete method find.
private AutocompleteResult find(String txt, int cur, ClassLoader l, Imports imports) {
registry = AutocompleteRegistryFactory.createRegistry(cps);
ClassUtils cu = createClassUtils(l);
setup(cu, registry);
AutocompleteRegistryFactory.addDefaultImports(cu, registry, imports.toListOfStrings(), cps);
Lexer lexer = new JavaLexer(new ANTLRInputStream(txt));
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Create a parser that reads from the scanner
JavaParser parser = new JavaParser(tokens);
parser.removeErrorListeners();
// start parsing at the compilationUnit rule
ParserRuleContext t = parser.compilationUnit();
ParseTreeWalker walker = new ParseTreeWalker();
List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();
JavaImportDeclarationCompletion extractor = new JavaImportDeclarationCompletion(txt, cur, registry, cps, cu);
JavaNameBuilder extractor2 = new JavaNameBuilder(registry, cu);
JavaNodeCompletion extractor3 = new JavaNodeCompletion(txt, cur, registry, cu);
walker.walk(extractor, t);
if (extractor.getQuery() != null)
q.addAll(extractor.getQuery());
walker.walk(extractor2, t);
walker.walk(extractor3, t);
if (extractor3.getQuery() != null)
q.addAll(extractor3.getQuery());
List<String> ret = registry.searchCandidates(q);
if (!ret.isEmpty()) {
return new AutocompleteResult(ret, getStartIndex(extractor, extractor2, extractor3));
}
return findAutocompleteResult(txt, cur, cu);
}
Aggregations