Search in sources :

Example 6 with IField

use of dyvilx.tools.compiler.ast.field.IField 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"));
    }
}
Also used : PrintStream(java.io.PrintStream) IContext(dyvilx.tools.compiler.ast.context.IContext) IProperty(dyvilx.tools.compiler.ast.field.IProperty) TreeSet(dyvil.collection.mutable.TreeSet) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField) IType(dyvilx.tools.compiler.ast.type.IType)

Example 7 with IField

use of dyvilx.tools.compiler.ast.field.IField 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"));
    }
}
Also used : PrintStream(java.io.PrintStream) TreeSet(dyvil.collection.mutable.TreeSet) REPLContext(dyvilx.tools.repl.context.REPLContext) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField)

Example 8 with IField

use of dyvilx.tools.compiler.ast.field.IField in project Dyvil by Dyvil.

the class REPLContext method getMethodMatches.

@Override
public void getMethodMatches(MatchList<IMethod> list, IValue receiver, Name name, ArgumentList arguments) {
    for (IMethod method : this.methods) {
        method.checkMatch(list, receiver, name, arguments);
    }
    if (name == null) {
        return;
    }
    final Name removeEq = Util.removeEq(name);
    IProperty property = this.properties.get(removeEq);
    if (property != null) {
        property.checkMatch(list, receiver, name, arguments);
    }
    final IField field = this.fields.get(removeEq);
    if (field != null) {
        property = field.getProperty();
        if (property != null) {
            property.checkMatch(list, receiver, name, arguments);
        }
    }
}
Also used : IProperty(dyvilx.tools.compiler.ast.field.IProperty) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField) Name(dyvil.lang.Name)

Example 9 with IField

use of dyvilx.tools.compiler.ast.field.IField in project Dyvil by Dyvil.

the class RenameCommand method execute.

@Override
public void execute(DyvilREPL repl, String argument) {
    final String[] split;
    if (argument == null || (split = argument.split(" ", 2)).length < 2) {
        repl.getErrorOutput().println(I18n.get("command.argument_list.invalid", this.getUsage()));
        return;
    }
    final Name memberName = Name.from(split[0]);
    final Name newName = Name.from(split[1]);
    final Map<Name, IField> fields = repl.getContext().getFields();
    final IField field = fields.remap(memberName, newName);
    if (field != null) {
        field.setName(newName);
        repl.getOutput().println(I18n.get("command.rename.success", memberName, newName));
    } else {
        repl.getOutput().println(I18n.get("command.rename.not_found", memberName));
    }
}
Also used : IField(dyvilx.tools.compiler.ast.field.IField) Name(dyvil.lang.Name)

Aggregations

IField (dyvilx.tools.compiler.ast.field.IField)9 IProperty (dyvilx.tools.compiler.ast.field.IProperty)4 IMethod (dyvilx.tools.compiler.ast.method.IMethod)4 Name (dyvil.lang.Name)3 TreeSet (dyvil.collection.mutable.TreeSet)2 PrintStream (java.io.PrintStream)2 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 EnumConstant (dyvilx.tools.compiler.ast.field.EnumConstant)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 IType (dyvilx.tools.compiler.ast.type.IType)1 REPLContext (dyvilx.tools.repl.context.REPLContext)1