use of dyvil.collection.mutable.TreeSet in project Dyvil by Dyvil.
the class CompleteCommand method printCompletions.
private void printCompletions(DyvilREPL repl, String memberStart, IValue value) {
final IType type = value.getType();
final boolean statics = value.isClassAccess();
final IContext context = repl.getContext().getContext();
final Set<IField> fields = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
final Set<IProperty> properties = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
final Set<IMethod> methods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
final Set<IMethod> extensionMethods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
final Set<IMethod> conversionMethods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
final PrintStream output = repl.getOutput();
if (statics) {
output.println(I18n.get("command.complete.type", type));
findMembers(type, fields, properties, methods, memberStart, true);
findExtensions(context, type, value, extensionMethods, memberStart, true);
} else {
output.println(I18n.get("command.complete.expression", value, type));
findInstanceMembers(type, fields, properties, methods, memberStart, new IdentityHashSet<>());
findExtensions(context, type, value, extensionMethods, memberStart, false);
findConversions(context, type, value, conversionMethods);
}
boolean hasOutput = false;
if (!fields.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.fields"));
printMembers(output, fields, type);
}
if (!properties.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.properties"));
printMembers(output, properties, type);
}
if (!methods.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.methods"));
printMethods(output, methods, type);
}
if (!extensionMethods.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.extensions"));
printMethods(output, extensionMethods, type);
}
if (!conversionMethods.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.conversions"));
printMethods(output, conversionMethods, type);
}
if (!hasOutput) {
output.println(I18n.get("command.complete.none"));
}
}
use of dyvil.collection.mutable.TreeSet in project Dyvil by Dyvil.
the class CompleteCommand method printREPLMembers.
private void printREPLMembers(DyvilREPL repl, String start) {
final REPLContext replContext = repl.getContext();
final Set<IField> variables = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
final Set<IMethod> methods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
for (IField variable : replContext.getFields().values()) {
checkMember(variables, variable, start);
}
for (IMethod method : replContext.getMethods()) {
checkMember(methods, method, start);
}
final PrintStream output = repl.getOutput();
boolean hasOutput = false;
if (!variables.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.variables"));
printMembers(output, variables, null);
}
if (!methods.isEmpty()) {
hasOutput = true;
output.println(I18n.get("command.complete.methods"));
printMethods(output, methods, null);
}
if (!hasOutput) {
output.println(I18n.get("command.complete.none"));
}
}
use of dyvil.collection.mutable.TreeSet in project Dyvil by Dyvil.
the class HelpCommand method printAllCommands.
private void printAllCommands(DyvilREPL repl) {
final PrintStream output = repl.getOutput();
output.println(I18n.get("command.help.available"));
final Set<String> commands = new TreeSet<>();
for (Entry<String, ICommand> entry : DyvilREPL.getCommands()) {
commands.add(entry.getValue().getName());
}
int maxLength = 0;
for (String name : commands) {
final int length = name.length();
if (length > maxLength) {
maxLength = length;
}
}
final String format = ":%1$-" + maxLength + "s - %2$s\n";
for (String name : commands) {
output.printf(format, name, getDesc(name));
}
}
Aggregations