sclass ConvertLASToJava { replace Tk with GazelleV_LeftArrowScript. delegate Evaluable to Tk. O get(LASClassDef.FieldDef field) { ret field.type() + " " + field.name() + ";"; } O get(Tk.FunctionDef f) { ret "O " + f.name + "(" + joinWithComma(map(f.args, arg -> "O " + arg)) + ") {\n" + indentx(strOrNull(get(f.body))) + "}\n"; } O getInstruction(Evaluable o) { O inner = get(o); ret inner + ";"; } O get(Evaluable o) { if (o == null) null; // These are the properly implemented cases if (o cast Tk.GetVar) ret o.var; if (o cast Tk.Script) ret lines(map getInstruction(o.steps)); if (o cast Tk.ClassDef) { LASClassDef c = o.lasClass.classDef; ret "class " + c.userGivenName + " " + curly("\n" + indentx( joinNemptiesWithEmptyLines( lines_rtrim(map get(c.fields)), lines_rtrim(map get(c.methods))) )) + "\n}"; } if (o cast Tk.Assignment) ret o.var + " = " + get(o.expression); if (o cast Tk.CallMethod) ret get(o.target) + "." + FunctionCall(o.methodName, map get(o.args)); if (o cast Tk.SetField) ret get(o.target) + "." + o.name + " = " + get(o.expr); if (o cast Tk.CallMethodOrGetField) ret get(o.target) + "." + o.name; if (o cast Tk.NewObject) ret "new " + FunctionCall(c, map get(o.args)); if (o cast Tk.IfThen) ret "if (" + get(o.condition) + ")\n" + indentx(str(get(o.body))) + (o.elseBranch == null ? "" : "\nelse\n" + indentx(str(get(o.elseBranch))); warn("Can't convert to Java: " + className(o)); // Retain original script text as a default if (o cast Tk.Base) { var src = o.tokenRangeWithSrc(); if (src != null) ret src.text(); } // If that fails (it shouldn't), just return the toString warn("No source reference in script object: " + className(o)); ret str(o); } }