List<CompletionCandidate> candidates = new ArrayList<CompletionCandidate>();
for (IRubyObject receiver : context.typeSet) {
RubyClass rubyClass = receiver.getMetaClass();
for (String name : rubyClass.getMethods(true)) {
DynamicMethod method = rubyClass.searchMethod(name);
candidates.add(new CompletionCandidate(name,
method.toString(),
method.getModule().getMethodPath(null),
CompletionCandidate.Kind.METHOD));
}
if (receiver instanceof RubyModule) {
RubyModule module = ((RubyModule) receiver);
for (String name : module.getConstants(true)) {
RubyModule directModule = module.getConstantModule(name);
IRubyObject constant = directModule.getConstant(name);
String baseName = directModule.toString();
String qname = baseName + "::" + name;
CompletionCandidate.Kind kind
= (constant instanceof RubyClass)
? CompletionCandidate.Kind.CLASS
: (constant instanceof RubyModule)
? CompletionCandidate.Kind.MODULE
: CompletionCandidate.Kind.CONSTANT;
candidates.add(new CompletionCandidate(name, qname, baseName, kind));
}
}
}
result.setCandidates(candidates);