use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class AutocompleteRegistryFactory method createImportAutocompleteCandidate.
public static void createImportAutocompleteCandidate(ClassUtils cu, AutocompleteRegistry registry, String imp) {
String[] txtv = imp.split("\\.");
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv, txtv.length - 1);
registry.addCandidate(c);
c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
registry.addCandidate(c);
c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, txtv[txtv.length - 1]);
registry.addCandidate(c);
cu.defineClassShortName(txtv[txtv.length - 1], imp);
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class GroovyNodeCompletion method exitPathExpression.
@Override
public void exitPathExpression(PathExpressionContext ctx) {
if (ctx.getStart().getStartIndex() < cursor && ctx.getStop().getStopIndex() + 1 >= cursor) {
// it might be import
if (ctx.getParent().getChild(0).equals(ctx) && ctx.getParent().getParent() != null && ctx.getParent().getParent() instanceof StatementContext && ctx.getParent().getParent().getChild(0).equals(ctx.getParent())) {
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, ctx.getText());
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
}
// // try to expand this as a path expression
if (ctx.getText().contains(".")) {
addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_NON_STATIC), AutocompleteGroovyResult.getStartIndex(ctx));
// complete with standard groovy extension functions
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, ctx.getText().substring(ctx.getText().lastIndexOf(".") + 1));
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
} else {
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getText());
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, ctx.getText());
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
}
}
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class GroovyNodeCompletion method exitCompilationUnit.
// @Override
// public void visitErrorNode(ErrorNode arg0) {
// if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) {
// //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText());
// ParseTree cuc = arg0.getParent();
// if (cuc.getChild(0).equals(arg0)) {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.INITIAL, arg0.getText());
// addQuery(c, 0);
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, arg0.getText());
// addQuery(c, 0);
// }
// if (cuc instanceof GroovyParser.StatementContext && ((GroovyParser.StatementContext) cuc).getStop().getStopIndex() + 1 == cursor) {
// if (cuc.getText().contains(".")) {
// addQuery(classUtils.expandExpression(cuc.getText(), registry, classUtils.DO_ALL), cursor);
// // complete with standard groovy extension functions
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, cuc.getText().substring(cuc.getText().lastIndexOf(".") + 1));
// addQuery(c, cursor);
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, cuc.getText());
// addQuery(c, 0);
// c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, cuc.getText());
// addQuery(c, 0);
// }
// }
// }
// }
//
//
// private RuleContext findParentNode(RuleContext ctx, Class<?> classtype) {
// RuleContext p = ctx.getParent();
// while (p != null) {
// if (p.getClass().equals(classtype)) {
// return p;
// }
// p = p.getParent();
// }
// return null;
// }
//
// private ParseTree findLeftSibling(RuleContext ctx) {
// RuleContext p = ctx.getParent();
// if (p != null) {
// for (int i = 0; i < p.getChildCount(); i++) {
// if (p.getChild(i).equals(ctx)) {
// if (i > 0)
// return p.getChild(i - 1);
// break;
// }
// }
// }
// return null;
// }
@Override
public void exitCompilationUnit(CompilationUnitContext ctx) {
if (ctx.getStop() != null && ctx.getStop().getStopIndex() + 1 == cursor) {
// if (ctx.getChildCount() > 0) {
// String t = ctx.getChild(ctx.getChildCount() - 2).getText();
// if (t.endsWith("\n")) {
// String txt = ctx.getChild(ctx.getChildCount() - 1).getText();
// if (txt.contains(".")) {
// addQuery(classUtils.expandExpression(txt, registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, txt);
// addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
// c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, txt);
// addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
// }
// } else {
// for (int i = ctx.getChildCount() - 1; i >= 0; i--) {
// if (!ctx.getChild(i).getText().isEmpty() && !ctx.getChild(i).getText().equals("<EOF>")) {
// String txt = ctx.getChild(i).getText();
// if (txt.contains(".")) {
// addQuery(classUtils.expandExpression(txt, registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, txt);
// addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
// }
// break;
// }
// }
// }
// }
String t = removeEOF(ctx.getText());
addQuery(classUtils.expandExpression(t, registry, classUtils.DO_ALL), calculateStartIndex(t, ctx));
String[] txtv = splitByDot(t);
AutocompleteCandidate c2 = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
addQuery(c2, calculateStartIndex(t, ctx));
}
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class GroovyNodeCompletion method exitClassNameExpression.
@Override
public void exitClassNameExpression(ClassNameExpressionContext ctx) {
if (ctx.getStart().getStartIndex() < cursor && ctx.getStop().getStopIndex() + 1 >= cursor) {
if (ctx.getText().contains(".")) {
addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_STATIC), AutocompleteGroovyResult.getStartIndex(ctx));
// complete with standard groovy extension functions
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, ctx.getText().substring(ctx.getText().lastIndexOf(".") + 1));
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
completeClassFromPath(ctx);
} else {
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getText());
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, ctx.getText());
addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
}
}
}
Aggregations