use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class JavaNameBuilder method exitFieldDeclaration.
@Override
public void exitFieldDeclaration(FieldDeclarationContext ctx) {
String type = null;
TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
if (ty != null) {
ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
if (t != null) {
type = t.getText();
} else {
PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
if (pt != null)
type = pt.getText();
}
}
List<VariableDeclaratorsContext> vars = ctx.getRuleContexts(VariableDeclaratorsContext.class);
VariableDeclaratorContext v;
for (VariableDeclaratorsContext vc : vars) {
v = vc.getRuleContext(VariableDeclaratorContext.class, 0);
if (v != null) {
VariableDeclaratorIdContext vi = v.getRuleContext(VariableDeclaratorIdContext.class, 0);
if (vi.getChildCount() > 0) {
// System.out.println("VAR "+vi.getChild(0).getText()+" of type "+type);
AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, vi.getChild(0).getText());
registry.addCandidate(c);
if (type != null) {
classUtils.defineVariable(vi.getChild(0).getText(), type);
}
}
}
}
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class JavaNameBuilder method exitLocalVariableDeclaration.
@Override
public void exitLocalVariableDeclaration(LocalVariableDeclarationContext ctx) {
String type = null;
TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
if (ty != null) {
ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
if (t != null) {
type = t.getText();
} else {
PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
if (pt != null)
type = pt.getText();
}
}
List<VariableDeclaratorsContext> vars = ctx.getRuleContexts(VariableDeclaratorsContext.class);
for (VariableDeclaratorsContext vc : vars) {
List<VariableDeclaratorContext> v = vc.getRuleContexts(VariableDeclaratorContext.class);
if (v != null) {
for (VariableDeclaratorContext v2 : v) {
VariableDeclaratorIdContext vi = v2.getRuleContext(VariableDeclaratorIdContext.class, 0);
if (vi.getChildCount() > 0) {
// System.out.println("VAR "+vi.getChild(0).getText()+" of type "+type);
AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, vi.getChild(0).getText());
registry.addCandidate(c);
if (type != null) {
classUtils.defineVariable(vi.getChild(0).getText(), type);
}
}
}
}
}
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class JavaNameBuilder method exitMethodDeclaration.
@Override
public void exitMethodDeclaration(MethodDeclarationContext ctx) {
if (ctx.getChildCount() >= 3 && ctx.getChild(1) instanceof TerminalNodeImpl) {
String type = null;
TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
if (ty != null) {
ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
if (t != null) {
type = t.getText();
} else {
PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
if (pt != null)
type = pt.getText();
}
}
AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, ctx.getChild(1).getText());
registry.addCandidate(c);
if (type != null) {
classUtils.defineVariable(ctx.getChild(1).getText(), type);
}
}
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class AutocompleteRegistryFactory method createRegistry.
public static AutocompleteRegistry createRegistry(GroovyClasspathScanner cps) {
AutocompleteRegistry registry = AutocompleteRegistryFactory.create(GroovyCompletionTypes.NUM_TYPES);
for (String pkg : cps.getPackages()) {
String[] pkgv = pkg.split("\\.");
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, pkgv);
registry.addCandidate(c);
List<String> cls = cps.getClasses(pkg);
if (cls != null && !cls.isEmpty()) {
c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, pkgv);
AutocompleteCandidate l = c;
while (l.hasChildren()) {
l = l.getChildrens().get(0);
}
for (String cl : cls) {
l.addChildren(new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, cl));
}
registry.addCandidate(c);
}
}
return registry;
}
use of com.twosigma.beakerx.autocomplete.AutocompleteCandidate in project beakerx by twosigma.
the class AutocompleteRegistryFactory method addDefaultImports.
public static void addDefaultImports(ClassUtils cu, AutocompleteRegistry registry, List<String> imports, GroovyClasspathScanner cps) {
for (String imp : imports) {
// this imports using '*'
if (imp.endsWith(".*")) {
String st = imp.substring(0, imp.length() - 2);
String[] txtv = st.split("\\.");
AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv);
registry.addCandidate(c);
List<String> cls = cps.getClasses(st);
if (cls != null) {
c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
AutocompleteCandidate l = c.findLeaf();
for (String s : cls) {
l.addChildren(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
registry.addCandidate(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
cu.defineClassShortName(s, st + "." + s);
}
registry.addCandidate(c);
}
} else {
createImportAutocompleteCandidate(cu, registry, imp);
}
}
}
Aggregations