Warning : session_start(): open(/var/lib/php/sessions/sess_jeqtqdgrorciqppfuf8u02j92c, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
1400555
import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import java.awt.geom.*;
import static x30_pkg.x30_util.DynamicObject;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.Const;
import org.apache.bcel.generic.*;
import java.lang.reflect.Type;
import java.util.jar.*;
import java.text.*;
import java.text.NumberFormat;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
public class main {
static public class GazelleV_LeftArrowScriptParser extends SimpleLeftToRightParser {
final public GazelleV_LeftArrowScriptParser setMagicSwitch(boolean magicSwitch) {
return magicSwitch(magicSwitch);
}
public GazelleV_LeftArrowScriptParser magicSwitch(boolean magicSwitch) {
this.magicSwitch = magicSwitch;
return this;
}
final public boolean getMagicSwitch() {
return magicSwitch();
}
public boolean magicSwitch() {
return magicSwitch;
}
public boolean magicSwitch = true;
final public GazelleV_LeftArrowScriptParser setObjectScopesEnabled(boolean objectScopesEnabled) {
return objectScopesEnabled(objectScopesEnabled);
}
public GazelleV_LeftArrowScriptParser objectScopesEnabled(boolean objectScopesEnabled) {
this.objectScopesEnabled = objectScopesEnabled;
return this;
}
final public boolean getObjectScopesEnabled() {
return objectScopesEnabled();
}
public boolean objectScopesEnabled() {
return objectScopesEnabled;
}
public boolean objectScopesEnabled = true;
public ClassNameResolver classNameResolver;
public List functionContainers = new ArrayList();
final public GazelleV_LeftArrowScriptParser setLasClassLoader(ILASClassLoader lasClassLoader) {
return lasClassLoader(lasClassLoader);
}
public GazelleV_LeftArrowScriptParser lasClassLoader(ILASClassLoader lasClassLoader) {
this.lasClassLoader = lasClassLoader;
return this;
}
final public ILASClassLoader getLasClassLoader() {
return lasClassLoader();
}
public ILASClassLoader lasClassLoader() {
return lasClassLoader;
}
public ILASClassLoader lasClassLoader;
final public GazelleV_LeftArrowScriptParser setClassDefPrefix(String classDefPrefix) {
return classDefPrefix(classDefPrefix);
}
public GazelleV_LeftArrowScriptParser classDefPrefix(String classDefPrefix) {
this.classDefPrefix = classDefPrefix;
return this;
}
final public String getClassDefPrefix() {
return classDefPrefix();
}
public String classDefPrefix() {
return classDefPrefix;
}
public String classDefPrefix;
final public GazelleV_LeftArrowScriptParser setSourceInfo(Object sourceInfo) {
return sourceInfo(sourceInfo);
}
public GazelleV_LeftArrowScriptParser sourceInfo(Object sourceInfo) {
this.sourceInfo = sourceInfo;
return this;
}
final public Object getSourceInfo() {
return sourceInfo();
}
public Object sourceInfo() {
return sourceInfo;
}
public Object sourceInfo;
final public GazelleV_LeftArrowScriptParser setOptimize(boolean optimize) {
return optimize(optimize);
}
public GazelleV_LeftArrowScriptParser optimize(boolean optimize) {
this.optimize = optimize;
return this;
}
final public boolean getOptimize() {
return optimize();
}
public boolean optimize() {
return optimize;
}
public boolean optimize = true;
final public GazelleV_LeftArrowScriptParser setUseFixedVarContexts(boolean useFixedVarContexts) {
return useFixedVarContexts(useFixedVarContexts);
}
public GazelleV_LeftArrowScriptParser useFixedVarContexts(boolean useFixedVarContexts) {
this.useFixedVarContexts = useFixedVarContexts;
return this;
}
final public boolean getUseFixedVarContexts() {
return useFixedVarContexts();
}
public boolean useFixedVarContexts() {
return useFixedVarContexts;
}
public boolean useFixedVarContexts = false;
public Scope scope;
public LinkedHashMap knownVars = new LinkedHashMap();
public Set closerTokens = litset(";", "}", ")");
public BuildingScript currentReturnableScript;
public BuildingScript currentLoop;
public boolean inParens = false;
public int idCounter;
public Map classDefs = new HashMap();
final public Map getFunctionDefs() {
return functionDefs();
}
public Map functionDefs() {
return functionDefs;
}
public Map functionDefs = new HashMap();
public Set flags = ciSet();
final public GazelleV_LeftArrowScriptParser setInternStringLiterals(boolean internStringLiterals) {
return internStringLiterals(internStringLiterals);
}
public GazelleV_LeftArrowScriptParser internStringLiterals(boolean internStringLiterals) {
this.internStringLiterals = internStringLiterals;
return this;
}
final public boolean getInternStringLiterals() {
return internStringLiterals();
}
public boolean internStringLiterals() {
return internStringLiterals;
}
public boolean internStringLiterals = true;
transient public Set>> onKnownVarsSnapshot;
public GazelleV_LeftArrowScriptParser onKnownVarsSnapshot(IVF1> f) {
onKnownVarsSnapshot = createOrAddToSyncLinkedHashSet(onKnownVarsSnapshot, f);
return this;
}
public GazelleV_LeftArrowScriptParser removeKnownVarsSnapshotListener(IVF1> f) {
main.remove(onKnownVarsSnapshot, f);
return this;
}
public void knownVarsSnapshot(Map knownVars) {
if (onKnownVarsSnapshot != null)
for (var listener : onKnownVarsSnapshot) pcallF_typed(listener, knownVars);
}
transient public Set> onTypeHook;
public GazelleV_LeftArrowScriptParser onTypeHook(IVF1 f) {
onTypeHook = createOrAddToSyncLinkedHashSet(onTypeHook, f);
return this;
}
public GazelleV_LeftArrowScriptParser removeTypeHookListener(IVF1 f) {
main.remove(onTypeHook, f);
return this;
}
public void typeHook(LASValueDescriptor type) {
if (onTypeHook != null)
for (var listener : onTypeHook) pcallF_typed(listener, type);
}
static public class EvaluableWrapper implements IFieldsToList {
public GazelleV_LeftArrowScript.Evaluable expr;
public EvaluableWrapper() {
}
public EvaluableWrapper(GazelleV_LeftArrowScript.Evaluable expr) {
this.expr = expr;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + expr + ")";
}
public boolean equals(Object o) {
if (!(o instanceof EvaluableWrapper))
return false;
EvaluableWrapper __21 = (EvaluableWrapper) o;
return eq(expr, __21.expr);
}
public int hashCode() {
int h = 700525824;
h = boostHashCombine(h, _hashCode(expr));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { expr };
}
}
public class BuildingScript {
public int id = ++idCounter;
final public BuildingScript setReturnable(boolean returnable) {
return returnable(returnable);
}
public BuildingScript returnable(boolean returnable) {
this.returnable = returnable;
return this;
}
final public boolean getReturnable() {
return returnable();
}
public boolean returnable() {
return returnable;
}
public boolean returnable = false;
final public BuildingScript setIsLoopBody(boolean isLoopBody) {
return isLoopBody(isLoopBody);
}
public BuildingScript isLoopBody(boolean isLoopBody) {
this.isLoopBody = isLoopBody;
return this;
}
final public boolean getIsLoopBody() {
return isLoopBody();
}
public boolean isLoopBody() {
return isLoopBody;
}
public boolean isLoopBody = false;
public BuildingScript returnableParent, loopParent;
public GazelleV_LeftArrowScript.Script script = new GazelleV_LeftArrowScript.Script();
public List steps = new ArrayList();
public Map functionDefs = new HashMap();
public BuildingScript(boolean returnable) {
this();
this.returnable = returnable;
}
public BuildingScript(boolean returnable, boolean isLoopBody) {
this();
this.isLoopBody = isLoopBody;
this.returnable = returnable;
}
public BuildingScript() {
}
public void add(GazelleV_LeftArrowScript.Evaluable step) {
if (step != null)
steps.add(step);
}
public GazelleV_LeftArrowScript.Evaluable get() {
var lastStep = last(steps);
if (lastStep instanceof GazelleV_LeftArrowScript.ReturnFromScript)
if (((GazelleV_LeftArrowScript.ReturnFromScript) lastStep).script == script)
replaceLast(steps, ((GazelleV_LeftArrowScript.ReturnFromScript) lastStep).value);
if (!returnable && l(steps) == 1 && empty(functionDefs))
return first(steps);
if (nempty(functionDefs))
script.functionDefs = functionDefs;
script.steps = toTypedArray(GazelleV_LeftArrowScript.Evaluable.class, steps);
return script;
}
public String toStringLong() {
return pnlToLines(steps);
}
public String toString() {
return formatRecordVars("BuildingScript", "id", id, "returnable", returnable, "returnableParent", returnableParent, "script", script);
}
}
{
tokenize = text -> {
List tok = tokenize_base(text);
tok = preprocess(tok);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("=== PREPROCESSED\n" + indentx(join(tok)) + "\n===");
return tok;
};
}
public List preprocess(List tok) {
tok = tokenIndexedList3(tok);
tok_ifdef(tok, __20 -> getFlag(__20));
tok_pcall_script(tok);
tok_script_settable(tok);
jreplace(tok, "LS", "L");
jreplace(tok, ", +", ", $3 $3");
return cloneList(tok);
}
public GazelleV_LeftArrowScript.Script parse(String text) {
setText(text);
init();
GazelleV_LeftArrowScript.Script script = parse();
if (!atEnd())
throw fail("End of script expected");
return script;
}
public GazelleV_LeftArrowScript.Script parse() {
GazelleV_LeftArrowScript.Script script = parseReturnableScript();
if (optimize)
script = script.optimizeScript();
return script;
}
public GazelleV_LeftArrowScript.Script parseReturnableScript() {
return (GazelleV_LeftArrowScript.Script) parseScript(new BuildingScript().returnable(true));
}
public GazelleV_LeftArrowScript.Evaluable parseScript(BuildingScript script) {
return linkToSrc(() -> {
script.returnableParent = currentReturnableScript;
script.loopParent = currentLoop;
if (script.returnable)
currentReturnableScript = script;
if (script.isLoopBody)
currentLoop = script;
return parseBuildingScript(script);
});
}
public GazelleV_LeftArrowScript.Evaluable parseBuildingScript(BuildingScript script) {
try {
parseScript_2(script);
var builtScript = script.get();
currentReturnableScript = script.returnableParent;
currentLoop = script.loopParent;
return builtScript;
} catch (Throwable e) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Parsed so far:\n" + script);
throw rethrowAndAppendToMessage(e, squareBracketed(spaceCombine(sourceInfo, lineAndColumn(-1))));
}
}
public void parseScript_2(BuildingScript script) {
AutoCloseable __10 = tempRestoreMap(knownVars);
try {
AssureAdvance assure = new AssureAdvance();
while (assure.get()) {
knownVarsSnapshot(knownVars);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseScript_2: Next token is " + quote(token()));
if (is(";")) {
next();
continue;
}
if (isOneOf("}", ")"))
break;
GazelleV_LeftArrowScript.Evaluable instruction = linkToSrc(() -> parseInstruction(script));
if (instruction != null)
script.add(instruction);
}
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseScript_2 done");
knownVarsSnapshot(knownVars);
} finally {
_close(__10);
}
}
public GazelleV_LeftArrowScript.Evaluable parseParamDecl(BuildingScript script) {
String var = assertIdentifier(tpp());
LASValueDescriptor valueDescriptor = new LASValueDescriptor();
if (is(":")) {
var type = parseColonType();
valueDescriptor = LASValueDescriptor.nonExactCanBeNull(type);
}
knownVars.put(var, valueDescriptor);
script.script.params = putOrCreateLinkedHashMap(script.script.params, var, valueDescriptor);
return null;
}
public GazelleV_LeftArrowScript.Evaluable parseInstruction(BuildingScript script) {
if (consumeOpt("param"))
return parseParamDecl(script);
if (is("throw")) {
consume();
return new GazelleV_LeftArrowScript.Throw(parseExpr());
}
if (isOneOf("return", "ret")) {
consume();
GazelleV_LeftArrowScript.Evaluable expr;
if (atCmdEnd())
expr = _const(null);
else
expr = parseAssignmentOrExpr();
return new GazelleV_LeftArrowScript.ReturnFromScript(currentReturnableScript.script, expr);
}
if (consumeOpt("continue")) {
assertCmdEnd();
if (currentLoop == null)
throw fail("continue outside of loop");
return new GazelleV_LeftArrowScript.Continue(currentLoop.script);
}
if (is("temp")) {
consume();
GazelleV_LeftArrowScript.Evaluable tempExpr = parseAssignmentOrExpr();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("tempExpr", tempExpr);
GazelleV_LeftArrowScript.Evaluable body = parseScript(new BuildingScript());
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("body", body);
return new GazelleV_LeftArrowScript.TempBlock(tempExpr, body);
}
if (is("will") && is(1, "return")) {
consume(2);
GazelleV_LeftArrowScript.Evaluable exp = parseAssignmentOrExpr();
GazelleV_LeftArrowScript.Evaluable body = parseScript(new BuildingScript());
return new GazelleV_LeftArrowScript.WillReturn(exp, body);
}
if (is("var") && isIdentifier(token(1))) {
consume();
String varName = consumeIdentifier();
var type = parseColonTypeOpt();
if (consumeLeftArrowOpt()) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Found assignment");
GazelleV_LeftArrowScript.Evaluable rhs = parseExpr();
assertNotNull("Expression expected", rhs);
knownVars.put(varName, type == null ? or(rhs.returnType(), new LASValueDescriptor()) : LASValueDescriptor.nonExactCanBeNull(type));
return new GazelleV_LeftArrowScript.VarDeclaration(varName, typeToClass(type), rhs);
}
}
return parseAssignmentOrExpr();
}
public GazelleV_LeftArrowScript.Evaluable parseAssignmentOrExpr() {
{
var __2 = parseAssignmentOpt();
if (__2 != null)
return __2;
}
return parseExpr();
}
public GazelleV_LeftArrowScript.Evaluable parseAssignmentOpt() {
String t = token();
if (isIdentifier(t)) {
Type type = null;
var ptr = ptr();
if (is(1, ":")) {
next();
type = parseColonType();
unconsume();
}
if (is(1, "<") && is(2, "-")) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Found assignment");
next(3);
GazelleV_LeftArrowScript.Evaluable rhs = parseExpr();
assertNotNull("Expression expected", rhs);
boolean newVar = !knownVars.containsKey(t);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("newVar", newVar, "t", t, "knownVars", knownVars);
if (newVar && scope != null) {
var __3 = scope.completeAssignmentOpt(t, rhs);
if (__3 != null)
return __3;
}
knownVars.put(t, type == null ? or(rhs.returnType(), new LASValueDescriptor()) : LASValueDescriptor.nonExactCanBeNull(type));
return newVar ? new GazelleV_LeftArrowScript.VarDeclaration(t, null, rhs) : new GazelleV_LeftArrowScript.Assignment(t, rhs);
}
ptr(ptr);
}
return null;
}
public GazelleV_LeftArrowScript.Evaluable parseOptionalInnerExpression() {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("parseOptionalInnerExpression", "token", token());
if (atCmdEnd() || isOneOf("{", ",", "then"))
return null;
return parseInnerExpr();
}
public GazelleV_LeftArrowScript.Evaluable _const(Object o) {
return new GazelleV_LeftArrowScript.Const(o);
}
public GazelleV_LeftArrowScript.Evaluable parseInnerExpr() {
return parseExpr(true);
}
public GazelleV_LeftArrowScript.Evaluable parseExpr() {
if (metaGet("scaffolding") != null)
scaffoldCalled(this, "parseExpr");
return parseExpr(false);
}
public GazelleV_LeftArrowScript.Evaluable parseExpr(boolean inner) {
GazelleV_LeftArrowScript.Evaluable e = linkToSrc(() -> inner ? parseExpr_impl(true) : parseFullExpr());
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseExpr done:\n" + GazelleV_LeftArrowScript.indentedScriptStruct(e));
return e;
}
public GazelleV_LeftArrowScript.Evaluable parseFullExpr() {
return linkToSrc(() -> parseExprPlusOptionalComma());
}
public GazelleV_LeftArrowScript.CallOnTarget parseThenCall(GazelleV_LeftArrowScript.CallOnTarget expr) {
consume("then");
GazelleV_LeftArrowScript.CallOnTarget secondCall = (GazelleV_LeftArrowScript.CallOnTarget) (parseCall(null));
return new GazelleV_LeftArrowScript.Then(expr, secondCall);
}
public GazelleV_LeftArrowScript.Evaluable parseExprPlusOptionalComma() {
GazelleV_LeftArrowScript.Evaluable expr = parseExpr_impl(false);
while (consumeOpt(",")) {
expr = parseCall_noCmdEndCheck(expr);
}
return expr;
}
public GazelleV_LeftArrowScript.Evaluable parseExpr_impl(boolean inner) {
if (atEnd())
return null;
String t = token();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("parseExpr", "token", t);
if (is(";"))
return null;
if (consumeOpt("try")) {
GazelleV_LeftArrowScript.Evaluable body = parseCurlyBlock();
while (consumeOpt("catch")) {
String var = consumeIdentifierOpt();
AutoCloseable __11 = tempAddKnownVars(var);
try {
GazelleV_LeftArrowScript.Evaluable catchBlock = parseCurlyBlock();
body = new GazelleV_LeftArrowScript.TryCatch(body, var, catchBlock);
} finally {
_close(__11);
}
}
if (consumeOpt("finally")) {
GazelleV_LeftArrowScript.Evaluable finallyBlock = parseCurlyBlock();
return new GazelleV_LeftArrowScript.TryFinally(body, finallyBlock);
}
return body;
}
if (is("def")) {
var fd = parseFunctionDefinition(currentReturnableScript.functionDefs);
return _const(fd);
}
if (is("{"))
return parseCurlyBlock();
if (is("-") && empty(nextSpace()) && startsWithDigit(token(1)) || startsWithDigit(t)) {
var e = parseNumberLiteral();
return parseCall(inner, e);
}
if (isQuoted(t)) {
var e = parseStringLiteral();
return parseCall(inner, e);
}
if (startsWith(t, '\'')) {
consume();
var e = _const(first(unquote(t)));
return parseCall(inner, e);
}
if (isIdentifier(t)) {
if (consumeOpt("synchronized")) {
var target = parseExpr();
var body = parseCurlyBlock();
return new GazelleV_LeftArrowScript.Synchronized(target, body);
}
if (is("while"))
return parseWhileLoop();
if (is("do"))
return parseDoWhileLoop();
if (is("for"))
return parseForEach();
if (is("if"))
return parseIfStatement();
if (is("repeat"))
return parseRepeatStatement();
if (is("outer")) {
consume();
var a = parseAssignmentOpt();
if (!(a instanceof GazelleV_LeftArrowScript.Assignment))
throw fail("Assignment expected");
return new GazelleV_LeftArrowScript.AssignmentToOuterVar(((GazelleV_LeftArrowScript.Assignment) a).var, ((GazelleV_LeftArrowScript.Assignment) a).expression);
}
consume();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Consumed identifier " + t + ", next token: " + token() + ", inner: " + inner);
var e = parseExprStartingWithIdentifier(t, inner);
return inner ? parseCall(inner, e) : e;
}
if (eq(t, "(")) {
consume();
GazelleV_LeftArrowScript.Evaluable e = parseExpr_inParens();
consume(")");
return parseCall(inner, e);
}
if (isOneOf("&", "|") && empty(nextSpace()) && is(1, token())) {
return parseBinaryOperator();
}
throw fail("Identifier, literal, operator or opening parentheses expected (got: " + quote(t));
}
public GazelleV_LeftArrowScript.Evaluable parseExpr_inParens() {
boolean inParensOld = inParens;
inParens = true;
try {
return parseExpr();
} finally {
inParens = inParensOld;
}
}
public GazelleV_LeftArrowScript.Evaluable parseNumberLiteral() {
String t = consumeMultiTokenLiteral();
if (swic(t, "0x"))
return _const(parseHexInt(dropFirst(t, 2)));
if (swic(t, "0b"))
return _const(intFromBinary(dropFirst(t, 2)));
if (isInteger(t))
return _const(parseIntOrLong(t));
if (ewic(t, "f"))
return _const(parseFloat(t));
if (endsWith(t, "L"))
return _const(parseLong(t));
return _const(parseDouble(t));
}
public GazelleV_LeftArrowScript.Evaluable parseBinaryOperator() {
boolean and = is("&");
next(2);
GazelleV_LeftArrowScript.Evaluable a = parseInnerExpr();
GazelleV_LeftArrowScript.Evaluable b = parseInnerExpr();
return and ? new GazelleV_LeftArrowScript.BoolAnd(a, b) : new GazelleV_LeftArrowScript.BoolOr(a, b);
}
public boolean qualifiedNameContinues() {
return empty(prevSpace()) && eq(token(), ".") && empty(nextSpace()) && isIdentifier(token(1));
}
public GazelleV_LeftArrowScript.Evaluable parseNewExpr() {
String className = assertIdentifier(tpp());
parseTypeArguments(null);
LASClassDef cd = classDefs.get(className);
if (cd != null)
return new GazelleV_LeftArrowScript.NewObject_LASClass(cd.resolvable(lasClassLoader));
var type = knownVars.get(className);
if (type != null)
return new GazelleV_LeftArrowScript.NewObject_UnknownClass(new GazelleV_LeftArrowScript.GetVar(className), parseArguments());
Object o = findExternalObject(className);
if (o instanceof Class) {
Class c = (Class) o;
if (c == List.class)
c = ArrayList.class;
else if (c == Map.class)
c = HashMap.class;
else if (c == Set.class)
c = HashSet.class;
return new GazelleV_LeftArrowScript.NewObject(c, parseArguments());
}
throw new ClassNotFound(className);
}
public GazelleV_LeftArrowScript.Evaluable parseExprStartingWithIdentifier(String t, boolean inner) {
if (eq(t, "true"))
return _const(true);
if (eq(t, "false"))
return _const(false);
if (eq(t, "null"))
return _const(null);
if (eq(t, "new"))
return parseNewExpr();
if (eq(t, "class")) {
unconsume();
return new GazelleV_LeftArrowScript.ClassDef(parseClassDef().resolvable(lasClassLoader));
}
if (eq(t, "list") && is("{")) {
GazelleV_LeftArrowScript.Script block = parseReturnableCurlyBlock();
GazelleV_LeftArrowScript.Evaluable e = new GazelleV_LeftArrowScript.ListFromScript(block);
return parseCall(inner, e);
}
var type = knownVars.get(t);
if (type != null) {
var e = new GazelleV_LeftArrowScript.GetVar(t).returnType(type);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Found var acccess: " + e + ", " + (!inner ? "Checking for call" : "Returning expression"));
return parseCall(inner, e);
}
if (scope != null) {
{
var __4 = scope.parseExprStartingWithIdentifierOpt(t, inner);
if (__4 != null)
return __4;
}
}
LASClassDef cd = classDefs.get(t);
if (cd != null)
return new GazelleV_LeftArrowScript.ClassDef(cd.resolvable(lasClassLoader));
if (!inner) {
var fdef = lookupFunction(t);
if (fdef != null) {
if (is("~"))
return parseTildeCall(new GazelleV_LeftArrowScript.CallFunction(fdef, new GazelleV_LeftArrowScript.Evaluable[0]));
return new GazelleV_LeftArrowScript.CallFunction(fdef, parseArguments());
}
}
if (eq(t, "_context"))
return new GazelleV_LeftArrowScript.GetVarContext();
Object o = findExternalObject(t);
var start = ptr().minus(2);
if (o == null) {
throw new UnknownObject(t);
} else if (o instanceof EvaluableWrapper) {
return parseCall(inner, ((EvaluableWrapper) o).expr);
} else if (inner)
return linkToSrc(start, _const(o));
else if (o instanceof Class) {
return parseExprStartingWithClass(start, ((Class) o));
} else if (o instanceof MethodOnObject) {
if (inner)
throw fail("Can't call methods in arguments");
return new GazelleV_LeftArrowScript.CallMethod(_const(((MethodOnObject) o).object), ((MethodOnObject) o).method, parseArguments());
} else
return parseCall(_const(o));
}
public GazelleV_LeftArrowScript.Evaluable parseExprStartingWithClass(ListAndIndex start, Class c) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("parseExprStartingWithClass", "c", c);
if (atCmdEnd())
return linkToSrc(start, _const(c));
if (is("("))
return new GazelleV_LeftArrowScript.NewObject(c, parseArguments());
{
var __5 = parseLambdaOpt(c);
if (__5 != null)
return __5;
}
if (isIdentifier()) {
String name = tpp();
if (hasStaticMethodNamed(c, name))
return new GazelleV_LeftArrowScript.CallMethod(_const(c), name, parseArguments());
if (isInterface(c))
return parseLambdaMethodRef(c, name);
var field = getField(c, name);
if (field == null)
field = findFieldInInterfaces(c, name);
if (field != null) {
if (!isStaticField(field))
throw fail(field + " is not a static field");
if (consumeLeftArrowOpt()) {
GazelleV_LeftArrowScript.Evaluable rhs = parseExpr();
return new GazelleV_LeftArrowScript.SetStaticField(field, rhs);
}
assertCmdEnd();
return new GazelleV_LeftArrowScript.GetStaticField(field);
}
throw fail(name + " not found in " + c + " (looked for method or field)");
} else
throw fail("Method name expected: " + token());
}
public GazelleV_LeftArrowScript.Evaluable parseLambdaOpt(Class c) {
if (!isInterface(c))
return null;
var ptr = ptr();
var parameterized = parseTypeArgumentsOpt(c);
if (is("{"))
return finishLambdaDef(c, null);
if (consumeOpt("_")) {
String methodName = consumeIdentifier();
return new GazelleV_LeftArrowScript.LambdaMethodOnArgument(c, methodName, parseArguments());
}
LinkedHashMap args = new LinkedHashMap();
while (isIdentifier()) {
String name = consumeIdentifier();
args.put(name, typeToValueDescriptor(parseColonTypeOpt()));
}
if (!(is("-") && is(1, ">"))) {
ptr(ptr);
return null;
}
skip(2);
return finishLambdaDef(c, args);
}
public GazelleV_LeftArrowScript.Evaluable finishLambdaDef(Class c, LinkedHashMap args) {
AutoCloseable __12 = tempAddKnownVars(args);
try {
knownVarsSnapshot(knownVars);
GazelleV_LeftArrowScript.Evaluable body;
if (is("{"))
body = parseReturnableCurlyBlock();
else
body = parseExpr();
var lambda = new GazelleV_LeftArrowScript.LambdaDef(c, toStringArray(keys(args)), body);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("finishLambdaDef done:\n" + GazelleV_LeftArrowScript.indentedScriptStruct(lambda));
return lambda;
} finally {
_close(__12);
}
}
public GazelleV_LeftArrowScript.Evaluable parseLambdaMethodRef(Class c, String name) {
var fdef = lookupFunction(name);
if (fdef != null) {
GazelleV_LeftArrowScript.Evaluable[] curriedArguments = parseArguments();
return new GazelleV_LeftArrowScript.CurriedScriptFunctionLambda(c, fdef, curriedArguments);
}
Object function = findExternalObject(name);
if (function == null)
throw new UnknownObject(name);
if (function instanceof MethodOnObject) {
Object target = ((MethodOnObject) function).object;
String targetMethod = ((MethodOnObject) function).method;
GazelleV_LeftArrowScript.Evaluable[] curriedArguments = parseArguments();
return new GazelleV_LeftArrowScript.CurriedMethodLambda(c, target, targetMethod, curriedArguments);
} else if (function instanceof Class) {
Class c2 = (Class) function;
assertCmdEnd();
var ctors = constructorsWithNumberOfArguments(c2, 1);
if (empty(ctors))
throw fail("No single argument constructor found in " + c2);
return new GazelleV_LeftArrowScript.CurriedConstructorLambda(c, toArray(Constructor.class, ctors), null);
} else
throw fail(function + " is not an instantiable class or callable method");
}
public GazelleV_LeftArrowScript.FunctionDef lookupFunction(String name) {
var script = currentReturnableScript;
while (script != null) {
var f = script.functionDefs.get(name);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("lookupFunction", "script", script, "name", name, "f", f);
if (f != null)
return f;
script = script.returnableParent;
}
return functionDefs.get(name);
}
public GazelleV_LeftArrowScript.Evaluable[] parseArguments() {
List l = new ArrayList();
try {
while (true) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseArgumentsAsList: token is " + quote(t()));
if (is("+") && empty(nextSpace()) && isIdentifier(token(1))) {
consume();
l.add(_const(token()));
continue;
}
if (consumeOpt("<")) {
GazelleV_LeftArrowScript.Evaluable a = parseFullExpr();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseArgumentsAsList: token after expr is " + quote(t()));
if (a == null)
throw fail("expression expected");
l.add(a);
break;
}
GazelleV_LeftArrowScript.Evaluable a = parseOptionalInnerExpression();
if (a == null)
break;
l.add(a);
}
return toArrayOrNull(GazelleV_LeftArrowScript.Evaluable.class, l);
} catch (Throwable _e) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Arguments parsed so far: " + l);
throw rethrow(_e);
}
}
public String consumeMultiTokenLiteral() {
return consumeUntilSpaceOr(() -> atCmdEnd() || is(","));
}
public boolean atCmdEnd() {
return !inParens && atEndOrLineBreak() || closerTokens.contains(token());
}
public void assertCmdEnd() {
if (!atCmdEnd())
throw fail("Expected end of command, token is: " + quote(token()));
}
public GazelleV_LeftArrowScript.Evaluable parseCall(GazelleV_LeftArrowScript.Evaluable target) {
return parseCall(false, target);
}
public GazelleV_LeftArrowScript.Evaluable parseCall(boolean inner, GazelleV_LeftArrowScript.Evaluable target) {
returnTypeHook(target);
if (atCmdEnd())
return target;
if (inner) {
{
var __6 = parseTildeCall(target);
if (__6 != null)
return __6;
}
return target;
}
return parseCall_noCmdEndCheck(target);
}
public void returnTypeHook(GazelleV_LeftArrowScript.Evaluable e) {
if (e != null && e.returnType() != null)
typeHook(e.returnType());
}
public GazelleV_LeftArrowScript.Evaluable parseCall_noCmdEndCheck(GazelleV_LeftArrowScript.Evaluable target) {
var start = ptr();
returnTypeHook(target);
if (isIdentifier()) {
String name = tpp();
if (consumeLeftArrowOpt()) {
GazelleV_LeftArrowScript.Evaluable rhs = parseExpr();
return new GazelleV_LeftArrowScript.SetField(target, name, rhs);
}
boolean allowNullReference = consumeOpt("?");
var args = parseArguments();
var call = finalizeCall(start, target, name, args);
set(call, "allowNullReference", allowNullReference);
return call;
}
{
var __7 = parseTildeCall(target);
if (__7 != null)
return __7;
}
if (is("!") && is(1, "_getField_")) {
next(2);
String field = consumeIdentifier();
return new GazelleV_LeftArrowScript.GetField(target, field);
}
return target;
}
public boolean consumeLeftArrowOpt() {
if (is("<") && eq(token(1), "-")) {
next(2);
return true;
}
return false;
}
public GazelleV_LeftArrowScript.Evaluable parseTildeCall(GazelleV_LeftArrowScript.Evaluable target) {
var start = ptr();
if (consumeOpt("~")) {
if (isIdentifier()) {
String key = consumeIdentifier();
GazelleV_LeftArrowScript.CallOnTarget call = finalizeCall1(start, target, "getOpt", _const(key));
call.allowNullReference(true);
return parseCall(finalizeCall2(call));
} else {
int idx = consumeInteger();
return parseCall(finalizeCall(start, target, "listGet", _const(idx)));
}
}
return null;
}
public GazelleV_LeftArrowScript.Evaluable finalizeCall(ListAndIndex start, GazelleV_LeftArrowScript.Evaluable target, String name, GazelleV_LeftArrowScript.Evaluable... args) {
return finalizeCall2(finalizeCall1(start, target, name, args));
}
public GazelleV_LeftArrowScript.Evaluable finalizeCall2(GazelleV_LeftArrowScript.CallOnTarget call) {
while (is("then")) call = parseThenCall(call);
return call;
}
public GazelleV_LeftArrowScript.CallOnTarget finalizeCall1(ListAndIndex start, GazelleV_LeftArrowScript.Evaluable target, String name, GazelleV_LeftArrowScript.Evaluable... args) {
if (magicSwitch) {
Object ext = findExternalObject(name);
if (ext instanceof MethodOnObject) {
if (nempty(args))
return new GazelleV_LeftArrowScript.CallMethodOrGlobalFunction(target, name, ((MethodOnObject) ext), args);
else
return new GazelleV_LeftArrowScript.CallMethodOrGetFieldOrGlobalFunction(target, name, ((MethodOnObject) ext));
}
}
if (nempty(args))
return new GazelleV_LeftArrowScript.CallMethod(target, name, args);
else
return linkToSrc(start, new GazelleV_LeftArrowScript.CallMethodOrGetField(target, name));
}
public A linkToSrc(ListAndIndex start, A a) {
if (a instanceof IHasTokenRangeWithSrc)
if (((IHasTokenRangeWithSrc) a).tokenRangeWithSrc() == null)
((IHasTokenRangeWithSrc) a).setTokenRangeWithSrc(new TokenRangeWithSrc(start, ptr().plus(-1)).sourceInfo(sourceInfo()));
return a;
}
public A linkToSrc(IF0 a) {
var start = ptr();
return linkToSrc(start, a.get());
}
transient public IF1 findExternalObject;
public Object findExternalObject(String name) {
return findExternalObject != null ? findExternalObject.get(name) : findExternalObject_base(name);
}
final public Object findExternalObject_fallback(IF1 _f, String name) {
return _f != null ? _f.get(name) : findExternalObject_base(name);
}
public Object findExternalObject_base(String name) {
if (eq(name, "void"))
return void.class;
{
var __8 = parsePrimitiveType(name);
if (__8 != null)
return __8;
}
if (qualifiedNameContinues()) {
int idx = idx() - 2;
do next(2); while (qualifiedNameContinues());
String fqn = joinSubList(tok, idx, idx() - 1);
return classForName(fqn);
}
return findExternalObject2(name);
}
transient public IF1 findExternalObject2;
public Object findExternalObject2(String name) {
return findExternalObject2 != null ? findExternalObject2.get(name) : findExternalObject2_base(name);
}
final public Object findExternalObject2_fallback(IF1 _f, String name) {
return _f != null ? _f.get(name) : findExternalObject2_base(name);
}
public Object findExternalObject2_base(String name) {
String fullName = globalClassNames().get(name);
if (fullName != null)
return classForName(fullName);
{
var __9 = classForNameOpt_noCache(name);
if (__9 != null)
return __9;
}
for (var container : unnullForIteration(functionContainers)) {
if (hasMethodNamed(container, name) && !isBlockedFunctionContainerMethod(container, name)) {
var moo = new MethodOnObject(container, name);
return moo;
}
var field = getField(container, name);
if (field != null && isStaticField(field))
return new EvaluableWrapper(new GazelleV_LeftArrowScript.GetStaticField(field));
}
return null;
}
transient public IF2 isBlockedFunctionContainerMethod;
public boolean isBlockedFunctionContainerMethod(Object container, String name) {
return isBlockedFunctionContainerMethod != null ? isBlockedFunctionContainerMethod.get(container, name) : isBlockedFunctionContainerMethod_base(container, name);
}
final public boolean isBlockedFunctionContainerMethod_fallback(IF2 _f, Object container, String name) {
return _f != null ? _f.get(container, name) : isBlockedFunctionContainerMethod_base(container, name);
}
public boolean isBlockedFunctionContainerMethod_base(Object container, String name) {
return false;
}
public GazelleV_LeftArrowScriptParser allowTheWorld() {
return allowTheWorld(mc());
}
public GazelleV_LeftArrowScriptParser allowTheWorld(Object... functionContainers) {
for (Object o : unnullForIteration(reversed(functionContainers))) if (!contains(this.functionContainers, o)) {
this.functionContainers.add(0, o);
globalClassNames_cache = null;
}
return this;
}
public void printFunctionDefs(GazelleV_LeftArrowScript.Script script) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print(values(script.functionDefs));
}
public AutoCloseable tempAddKnownVars(String... vars) {
return tempAddKnownVars(nonNulls(vars));
}
public AutoCloseable tempAddKnownTypedVars(Iterable vars) {
return tempAddKnownVars(mapToMap(vars, v -> pair(v.name, v.type)));
}
public AutoCloseable tempAddKnownVars(Iterable vars) {
var newVars = mapWithSingleValue(vars, new LASValueDescriptor());
return tempAddKnownVars(newVars);
}
public AutoCloseable tempAddKnownVar(String var, LASValueDescriptor type) {
return tempAddKnownVars(litmap(var, type));
}
public AutoCloseable tempAddKnownVars(Map newVars) {
return tempMapPutAll(knownVars, newVars);
}
public String parseFunctionDefArg(Map argsOut) {
if (consumeOpt("(")) {
String result = parseFunctionDefArg(argsOut);
consume(")");
return result;
}
if (isIdentifier()) {
String arg = tpp();
var type = typeToValueDescriptor(parseColonTypeOpt());
argsOut.put(arg, type);
return arg;
}
return null;
}
public GazelleV_LeftArrowScript.FunctionDef parseFunctionDefinition(Map functionDefsToAddTo) {
var start = ptr();
consume("def");
boolean synthetic = consumeOpt("!");
if (synthetic)
consume("synthetic");
String functionName = assertIdentifier(tpp());
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("parseFunctionDefinition " + functionName);
return parseFunctionDefinition_step2(functionDefsToAddTo, start, functionName).synthetic(synthetic);
}
public GazelleV_LeftArrowScript.FunctionDef parseFunctionDefinition_step2(Map functionDefsToAddTo, ListAndIndex start, String functionName) {
LinkedHashMap args = new LinkedHashMap();
while (parseFunctionDefArg(args) != null) {
}
var returnType = parseColonTypeOpt();
var fd = new GazelleV_LeftArrowScript.FunctionDef(functionName, keysList(args), null);
fd.argTypes(valuesArray(LASValueDescriptor.class, args));
{
if (functionDefsToAddTo != null)
functionDefsToAddTo.put(functionName, fd);
}
AutoCloseable __13 = tempAddKnownVars(args);
try {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Parsing function body");
fd.body = parseReturnableCurlyBlock();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Defined function " + functionName + ", added to " + functionDefsToAddTo);
if (returnType != null)
fd.returnType(returnType);
return linkToSrc(start, fd);
} finally {
_close(__13);
}
}
public Scope currentScope() {
return scope;
}
public AutoCloseable tempScope(Scope scope) {
var oldScope = currentScope();
this.scope = scope;
return () -> {
this.scope = oldScope;
};
}
public GazelleV_LeftArrowScript.Script parseReturnableCurlyBlock() {
return (GazelleV_LeftArrowScript.Script) parseCurlyBlock(new BuildingScript().returnable(true));
}
public GazelleV_LeftArrowScript.Evaluable parseCurlyBlock() {
return parseCurlyBlock(new BuildingScript());
}
public GazelleV_LeftArrowScript.Evaluable parseCurlyBlock(BuildingScript script) {
consume("{");
boolean inParensOld = inParens;
inParens = false;
var body = parseScript(script);
consume("}");
inParens = inParensOld;
return body;
}
public GazelleV_LeftArrowScript.Evaluable parseWhileLoop() {
consume("while");
var condition = parseExpr();
var body = parseCurlyBlock(new BuildingScript().isLoopBody(true));
return new GazelleV_LeftArrowScript.While(condition, body);
}
public GazelleV_LeftArrowScript.Evaluable parseDoWhileLoop() {
consume("do");
var body = parseCurlyBlock(new BuildingScript().isLoopBody(true));
consume("while");
var condition = parseExpr();
return new GazelleV_LeftArrowScript.DoWhile(condition, body);
}
public GazelleV_LeftArrowScript.Evaluable parseForEach() {
return new ParseForEach().get();
}
public class ParseForEach {
public GazelleV_LeftArrowScript.Evaluable collection, body;
public IF0 finish;
public List vars = new ArrayList();
public TypedVar addVar(TypedVar var) {
return addAndReturn(vars, var);
}
public TypedVar consumeVar() {
String name = consumeIdentifier();
var type = parseColonTypeOpt();
return addVar(new TypedVar(name, typeToValueDescriptor(type)));
}
public void parseBody() {
AutoCloseable __14 = tempAddKnownTypedVars(vars);
try {
body = parseCurlyBlock(new BuildingScript().isLoopBody(true));
} finally {
_close(__14);
}
}
public GazelleV_LeftArrowScript.Evaluable get() {
consume("for");
if (is(1, "to")) {
TypedVar var = consumeVar();
consume("to");
GazelleV_LeftArrowScript.Evaluable endValue = parseExpr();
parseBody();
return new GazelleV_LeftArrowScript.ForIntTo(endValue, var.name, body);
}
int iIn = relativeIndexOf("in");
if (iIn < 0)
throw fail("for without in");
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("iIn", iIn);
if (iIn == 1 || is(1, ":")) {
TypedVar var = consumeVar();
finish = () -> new GazelleV_LeftArrowScript.ForEach(collection, var.name, body).varType(var.type);
} else if (iIn == 2) {
if (consumeOpt("iterator")) {
TypedVar var = consumeVar();
finish = () -> new GazelleV_LeftArrowScript.ForIterator(collection, var.name, body);
} else if (consumeOpt("nested")) {
TypedVar var = consumeVar();
finish = () -> new GazelleV_LeftArrowScript.ForNested(collection, var.name, body);
} else
throw fail("Unknown pattern for 'for' loop");
} else if (iIn == 3) {
if (isOneOf("pair", "Pair")) {
consume();
TypedVar varA = consumeVar();
TypedVar varB = consumeVar();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("varA", varA, "varB", varB);
finish = () -> new GazelleV_LeftArrowScript.ForPairs(collection, body, varA.name, varB.name);
} else {
TypedVar varA = consumeVar();
consume(",");
TypedVar varB = consumeVar();
finish = () -> new GazelleV_LeftArrowScript.ForKeyValue(collection, body, varA.name, varB.name);
}
} else if (iIn == 4) {
consume("index");
String varIndex = consumeVar().name;
consume(",");
String varElement = consumeVar().name;
finish = () -> new GazelleV_LeftArrowScript.ForIndex(collection, body, varIndex, varElement);
} else
throw fail("Unknown pattern for 'for' loop");
consume("in");
collection = parseExpr_inParens();
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("collection", collection);
parseBody();
return finish.get();
}
}
public GazelleV_LeftArrowScript.Evaluable parseIfStatement() {
consume("if");
GazelleV_LeftArrowScript.Evaluable condition, body, elseBranch = null;
{
AutoCloseable __15 = tempAdd(closerTokens, "then");
try {
condition = parseExpr();
} finally {
_close(__15);
}
}
if (consumeOpt("then")) {
AutoCloseable __16 = tempAdd(closerTokens, "else");
try {
body = parseExpr();
if (consumeOpt("else"))
elseBranch = parseExpr();
} finally {
_close(__16);
}
} else {
body = parseCurlyBlock();
if (consumeOpt("else")) {
if (is("if"))
elseBranch = parseIfStatement();
else
elseBranch = parseCurlyBlock();
}
}
return new GazelleV_LeftArrowScript.IfThen(condition, body, elseBranch);
}
public GazelleV_LeftArrowScript.Evaluable parseRepeatStatement() {
consume("repeat");
var n = parseExpr();
var body = parseCurlyBlock();
return new GazelleV_LeftArrowScript.RepeatN(n, body);
}
public void addVar(String var) {
addVar(var, new LASValueDescriptor());
}
public void addVar(String var, LASValueDescriptor type) {
knownVars.put(var, type);
}
public void addVar(String var, Class type, boolean canBeNull) {
addVar(var, typeToValueDescriptor(type, canBeNull));
}
public LASValueDescriptor typeToValueDescriptor(Type type) {
return typeToValueDescriptor(type, true);
}
public LASValueDescriptor typeToValueDescriptor(Type type, boolean canBeNull) {
return type == null ? new LASValueDescriptor() : new LASValueDescriptor.NonExact(typeToClass(type), canBeNull);
}
public Map globalClassNames_cache;
public Map globalClassNames() {
if (globalClassNames_cache == null)
globalClassNames_cache = globalClassNames_load();
return globalClassNames_cache;
}
public Map globalClassNames_load() {
var packages = mapToTreeSet(importedPackages(), pkg -> pkg + ".");
Map out = new HashMap();
for (var name : unnullForIteration(importedClasses())) out.put(shortenClassName(name), name);
for (var fc : functionContainers) if (fc instanceof Class) {
if (isAnonymousClass((Class) fc))
continue;
out.put(shortClassName((Class) fc), className((Class) fc));
}
var classContainers = classContainerPrefixes();
TreeSet classContainerSet = asTreeSet(classContainers);
for (var className : classNameResolver().allFullyQualifiedClassNames()) {
if (isAnonymousClassName(className))
continue;
if (!contains(className, '$')) {
String pkg = longestPrefixInTreeSet(className, packages);
if (pkg != null) {
String shortName = dropPrefix(pkg, className);
if (!shortName.contains(".") && !out.containsKey(shortName))
out.put(shortName, className);
}
}
String container = longestPrefixInTreeSet(className, classContainerSet);
if (container != null) {
String shortName = dropPrefix(container, className);
String existing = out.get(shortName);
if (existing != null) {
int priority = indexOf(classContainers, container);
String oldContainer = longestPrefixInTreeSet(existing, classContainerSet);
int oldPriority = smartIndexOf(classContainers, oldContainer);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("className", className, "shortName", shortName, "container", container, "priority", priority, "existing", existing, "oldPriority", oldPriority);
if (priority > oldPriority)
continue;
}
out.put(shortName, className);
}
}
for (var __23 : _entrySet(unnullForIteration(classShortcuts()))) {
var key = __23.getKey();
var val = __23.getValue();
String fullName = out.get(val);
if (fullName != null)
out.put(key, fullName);
}
return out;
}
transient public IF0> classShortcuts;
public Map classShortcuts() {
return classShortcuts != null ? classShortcuts.get() : classShortcuts_base();
}
final public Map classShortcuts_fallback(IF0> _f) {
return _f != null ? _f.get() : classShortcuts_base();
}
public Map classShortcuts_base() {
return javaxClassShortcuts();
}
transient public IF0> importedPackages;
public Collection importedPackages() {
return importedPackages != null ? importedPackages.get() : importedPackages_base();
}
final public Collection importedPackages_fallback(IF0> _f) {
return _f != null ? _f.get() : importedPackages_base();
}
public Collection importedPackages_base() {
return itemPlus("java.lang", standardImports_fullyImportedPackages());
}
transient public IF0> importedClasses;
public Collection importedClasses() {
return importedClasses != null ? importedClasses.get() : importedClasses_base();
}
final public Collection importedClasses_fallback(IF0> _f) {
return _f != null ? _f.get() : importedClasses_base();
}
public Collection importedClasses_base() {
return standardImports_singleClasses();
}
public void addClassAlias(String alias, String longName) {
String fullName = globalClassNames().get(longName);
if (fullName != null)
globalClassNames().put(alias, fullName);
}
public List classContainerPrefixes() {
return map(functionContainers, fc -> className(fc) + "$");
}
static public class UnknownObject extends RuntimeException implements IFieldsToList {
public String name;
public UnknownObject() {
}
public UnknownObject(String name) {
this.name = name;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + name + ")";
}
public Object[] _fieldsToList() {
return new Object[] { name };
}
public String getMessage() {
return "Unknown object: " + name;
}
}
static public class ClassNotFound extends UnknownObject {
public ClassNotFound(String className) {
super(className);
}
public String getMessage() {
return "Class not found: " + name;
}
}
abstract static public class Scope {
public GazelleV_LeftArrowScript.Evaluable parseExprStartingWithIdentifierOpt(String t, boolean inner) {
return null;
}
public GazelleV_LeftArrowScript.Evaluable completeAssignmentOpt(String lhs, GazelleV_LeftArrowScript.Evaluable rhs) {
return null;
}
}
public class ClassDefScope extends Scope implements IFieldsToList {
public LASClassDef classDef;
public ClassDefScope() {
}
public ClassDefScope(LASClassDef classDef) {
this.classDef = classDef;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + classDef + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ClassDefScope))
return false;
ClassDefScope __0 = (ClassDefScope) o;
return eq(classDef, __0.classDef);
}
public int hashCode() {
int h = -1760310585;
h = boostHashCombine(h, _hashCode(classDef));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { classDef };
}
public GazelleV_LeftArrowScript.Evaluable getThis() {
return new GazelleV_LeftArrowScript.GetVar("this");
}
public GazelleV_LeftArrowScript.Evaluable parseExprStartingWithIdentifierOpt(String t, boolean inner) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("ClassDefScope.parseExprStartingWithIdentifierOpt", "t", t);
return linkToSrc(() -> {
var field = classDef.fieldsByName.get(t);
if (field != null) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Found field " + field);
var e = inner ? new GazelleV_LeftArrowScript.GetField(getThis(), field.name) : new GazelleV_LeftArrowScript.CallMethodOrGetField(getThis(), field.name);
return parseCall(inner, e);
}
Class superClass = typeToClass(classDef.superClass);
var field2 = findFieldOfClass(superClass, t);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("field2", field2, "superClass", superClass, "t", t);
if (field2 != null) {
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
print("Found field " + field2);
var e = inner ? new GazelleV_LeftArrowScript.GetField(getThis(), field2.getName()) : new GazelleV_LeftArrowScript.CallMethodOrGetField(getThis(), field2.getName());
return parseCall(inner, e);
}
if (!inner && (classDef.methodsByName.containsKey(t) || classHasMethodNamed(typeToClass(classDef.superClass), t))) {
return new GazelleV_LeftArrowScript.CallMethod(getThis(), t, parseArguments());
}
return null;
});
}
public GazelleV_LeftArrowScript.Evaluable completeAssignmentOpt(String lhs, GazelleV_LeftArrowScript.Evaluable rhs) {
var field = classDef.fieldsByName.get(lhs);
if (field != null)
return new GazelleV_LeftArrowScript.SetField(getThis(), lhs, rhs);
Class superClass = typeToClass(classDef.superClass);
var field2 = findFieldOfClass(superClass, lhs);
if (field2 != null)
return new GazelleV_LeftArrowScript.SetField(getThis(), lhs, rhs);
return null;
}
}
public LASClassDef parseClassDef() {
return linkToSrc(() -> {
consume("class");
LASClassDef classDef = new LASClassDef();
classDef.verbose(scaffoldingEnabled());
if (nempty(classDefPrefix))
classDef.classDefPrefix(classDefPrefix);
String name = consumeIdentifier();
classDef.userGivenName(name);
classDefs.put(name, classDef);
AutoCloseable __17 = tempMapPut(classDefs, "selfType", classDef);
try {
if (consumeOpt("extends")) {
classDef.superClass(parseType());
}
if (consumeOpt("is"))
classDef.interfaces.add(parseType());
consume("{");
AutoCloseable __18 = tempAddKnownVar("this", new LASValueDescriptor.NonExactType(classDef.resolvable(lasClassLoader), false));
try {
AutoCloseable __19 = !objectScopesEnabled ? null : tempScope(new ClassDefScope(classDef));
try {
while (!is("}")) {
if (is(";")) {
next();
continue;
}
if (is("def")) {
GazelleV_LeftArrowScript.FunctionDef fd = parseFunctionDefinition(null);
if (GazelleV_LeftArrowScriptParser.this.scaffoldingEnabled())
printVars("knownVarsAfterFunctionDef", knownVars);
classDef.addMethod(fd);
continue;
}
var start = ptr();
if (consumeOpt("ctor")) {
var fd = parseFunctionDefinition_step2(null, start, "");
fd.returnType(void.class);
classDef.addMethod(fd);
continue;
}
if (consumeOpt("initializer")) {
classDef.initializers.add(parseCurlyBlock());
continue;
}
LASClassDef.FieldDef fd = new LASClassDef.FieldDef();
while (isOneOf("transient", "static")) {
fd.addModifier(tpp());
}
fd.name(consumeIdentifier());
var type = parseColonType();
fd.type(type);
if (consumeLeftArrowOpt())
fd.initializer(parseExpr());
classDef.addField(fd);
}
consume("}");
return classDef;
} finally {
_close(__19);
}
} finally {
_close(__18);
}
} finally {
_close(__17);
}
});
}
public Type parseColonTypeOpt() {
if (is(":"))
return parseColonType();
return null;
}
public Type parseColonType() {
consume(":");
return parseType();
}
public Type findType(String typeName) {
LASClassDef cd = classDefs.get(typeName);
if (cd != null)
return cd.resolvable(lasClassLoader);
Object o = findExternalObject(typeName);
if (o instanceof Class)
return ((Class) o);
throw new ClassNotFound(typeName);
}
public Type parseType() {
String typeName = consumeIdentifier();
Type type = findType(typeName);
return parseArrayType(parseTypeArguments(type));
}
public Type parseArrayType(Type type) {
while (is("[") && is(1, "]")) {
consume(2);
type = new GenericArrayTypeImpl(type);
}
return type;
}
final public Type parseTypeArgumentsOpt(Type type) {
return parseTypeArguments(type);
}
public Type parseTypeArguments(Type type) {
if (is("<") && empty(nextSpace()) && isIdentifier(token(1))) {
next();
List args = new ArrayList();
while (true) {
args.add(parseType());
if (is(">"))
break;
consume(",");
}
consume(">");
if (type != null)
type = new ParameterizedTypeImpl(null, type, toTypedArray(Type.class, args));
}
return type;
}
transient public IF1 classForName;
public Class classForName(String name) {
return classForName != null ? classForName.get(name) : classForName_base(name);
}
final public Class classForName_fallback(IF1 _f, String name) {
return _f != null ? _f.get(name) : classForName_base(name);
}
public Class classForName_base(String name) {
try {
return Class.forName(name);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void copyFunctionContainersFrom(GazelleV_LeftArrowScriptParser parser) {
functionContainers = cloneList(parser.functionContainers);
globalClassNames_cache = parser.globalClassNames();
isBlockedFunctionContainerMethod = parser.isBlockedFunctionContainerMethod;
}
public ClassNameResolver classNameResolver() {
if (classNameResolver == null)
classNameResolver = new ClassNameResolver().byteCodePath(assertNotNull(getBytecodePathForClass(this))).init();
return classNameResolver;
}
public GazelleV_LeftArrowScriptParser classNameResolver(ClassNameResolver classNameResolver) {
this.classNameResolver = classNameResolver;
return this;
}
public GazelleV_LeftArrowScript.Evaluable parseStringLiteral() {
String s = unquote_relaxedMLS(consume());
if (internStringLiterals)
s = intern(s);
return _const(s);
}
public void addFunctionDefs(Map map) {
putAll(functionDefs, map);
}
public GazelleV_LeftArrowScriptParser setFlag(String flag) {
flags.add(flag);
return this;
}
public boolean getFlag(String flag) {
return flags.contains(flag);
}
public void noImports() {
importedPackages = () -> null;
importedClasses = () -> null;
classShortcuts = () -> null;
}
static public class TypedVar implements IFieldsToList {
public String name;
public LASValueDescriptor type;
public TypedVar() {
}
public TypedVar(String name, LASValueDescriptor type) {
this.type = type;
this.name = name;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + name + ", " + type + ")";
}
public boolean equals(Object o) {
if (!(o instanceof TypedVar))
return false;
TypedVar __22 = (TypedVar) o;
return eq(name, __22.name) && eq(type, __22.type);
}
public int hashCode() {
int h = -611218819;
h = boostHashCombine(h, _hashCode(name));
h = boostHashCombine(h, _hashCode(type));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { name, type };
}
}
{
internIdentifiers(true);
}
}
static public Object getOpt(Object o, String field) {
return getOpt_cached(o, field);
}
static public Object getOpt(String field, Object o) {
return getOpt_cached(o, field);
}
static public Object getOpt_raw(Object o, String field) {
try {
Field f = getOpt_findField(o.getClass(), field);
if (f == null)
return null;
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object getOpt(Class c, String field) {
try {
if (c == null)
return null;
Field f = getOpt_findStaticField(c, field);
if (f == null)
return null;
makeAccessible(f);
return f.get(null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Field getOpt_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
static public A listGet(List l, int idx) {
return l != null && idx >= 0 && idx < l.size() ? l.get(idx) : null;
}
static public HashSet litset(A... items) {
return lithashset(items);
}
static public TreeSet ciSet() {
return caseInsensitiveSet();
}
static public Set createOrAddToSyncLinkedHashSet(Set set, A a) {
if (set == null)
set = syncLinkedHashSet();
set.add(a);
return set;
}
static public void remove(List l, int i) {
if (l != null && i >= 0 && i < l(l))
l.remove(i);
}
static public void remove(Collection l, A a) {
if (l != null)
l.remove(a);
}
static public B remove(Map map, Object a) {
return map == null ? null : map.remove(a);
}
static public void remove(BitSet bs, int i) {
bs.clear(i);
}
static public A pcallF_typed(F0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
static public B pcallF_typed(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
static public void pcallF_typed(VF1 f, A a) {
try {
{
if (f != null)
f.get(a);
}
} catch (Throwable __e) {
pcallFail(__e);
}
}
static public void pcallF_typed(IVF1 f, A a) {
try {
{
if (f != null)
f.get(a);
}
} catch (Throwable __e) {
pcallFail(__e);
}
}
static public void pcallF_typed(IVF2 f, A a, B b) {
try {
{
if (f != null)
f.get(a, b);
}
} catch (Throwable __e) {
pcallFail(__e);
}
}
static public Object pcallF_typed(Runnable r) {
try {
{
if (r != null)
r.run();
}
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
static public A pcallF_typed(IF0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
static public B pcallF_typed(IF1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
pcallFail(__e);
}
return null;
}
static public String shortClassName_dropNumberPrefix(Object o) {
return dropNumberPrefix(shortClassName(o));
}
static public boolean eq(Object a, Object b) {
return a == b || a != null && b != null && a.equals(b);
}
static public boolean eq(Symbol a, String b) {
return eq(str(a), b);
}
static public int boostHashCombine(int a, int b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >>> 2));
}
static public int _hashCode(Object a) {
return a == null ? 0 : a.hashCode();
}
static public A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
static public A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
static public boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
static public Object get(Object o, String field) {
try {
if (o == null)
return null;
if (o instanceof Class)
return get((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
makeAccessible(f);
return f.get(o);
}
if (o instanceof DynamicObject)
return getOptDynOnly(((DynamicObject) o), field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
static public Object get_raw(String field, Object o) {
return get_raw(o, field);
}
static public Object get_raw(Object o, String field) {
try {
if (o == null)
return null;
Field f = get_findField(o.getClass(), field);
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
makeAccessible(f);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static public Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static public Object get(String field, Object o) {
return get(o, field);
}
static public boolean get(BitSet bs, int idx) {
return bs != null && bs.get(idx);
}
static public A last(List l) {
return empty(l) ? null : l.get(l.size() - 1);
}
static public char last(String s) {
return empty(s) ? '#' : s.charAt(l(s) - 1);
}
static public byte last(byte[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public int last(int[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public long last(long[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public double last(double[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public A last(A[] a) {
return l(a) != 0 ? a[l(a) - 1] : null;
}
static public A last(Iterator it) {
A a = null;
while (it.hasNext()) {
ping();
a = it.next();
}
return a;
}
static public A last(Collection l) {
if (l == null)
return null;
if (l instanceof List)
return (A) last((List) l);
if (l instanceof SortedSet)
return (A) last((SortedSet) l);
Iterator it = iterator(l);
A a = null;
while (it.hasNext()) {
ping();
a = it.next();
}
return a;
}
static public A last(SortedSet l) {
return l == null ? null : l.last();
}
static public A last(ReverseChain l) {
return l == null ? null : l.element;
}
static public A last(CompactLinkedHashSet set) {
return set == null ? null : set.last();
}
static public void replaceLast(List l, A a) {
replaceLastElement(l, a);
}
static public int l(Object[] a) {
return a == null ? 0 : a.length;
}
static public int l(boolean[] a) {
return a == null ? 0 : a.length;
}
static public int l(byte[] a) {
return a == null ? 0 : a.length;
}
static public int l(short[] a) {
return a == null ? 0 : a.length;
}
static public int l(long[] a) {
return a == null ? 0 : a.length;
}
static public int l(int[] a) {
return a == null ? 0 : a.length;
}
static public int l(float[] a) {
return a == null ? 0 : a.length;
}
static public int l(double[] a) {
return a == null ? 0 : a.length;
}
static public int l(char[] a) {
return a == null ? 0 : a.length;
}
static public int l(Collection c) {
return c == null ? 0 : c.size();
}
static public int l(Iterator i) {
return iteratorCount_int_close(i);
}
static public int l(Map m) {
return m == null ? 0 : m.size();
}
static public int l(CharSequence s) {
return s == null ? 0 : s.length();
}
static public long l(File f) {
return f == null ? 0 : f.length();
}
static public int l(IMultiSet ms) {
return ms == null ? 0 : ms.size();
}
static public int l(IMultiMap mm) {
return mm == null ? 0 : mm.size();
}
static public int l(IntRange r) {
return r == null ? 0 : r.length();
}
static public int l(IntSize o) {
return o == null ? 0 : o.size();
}
static public boolean empty(Collection c) {
return c == null || c.isEmpty();
}
static public boolean empty(Iterable c) {
return c == null || !c.iterator().hasNext();
}
static public boolean empty(CharSequence s) {
return s == null || s.length() == 0;
}
static public boolean empty(Map map) {
return map == null || map.isEmpty();
}
static public boolean empty(Object[] o) {
return o == null || o.length == 0;
}
static public boolean empty(BitSet bs) {
return bs == null || bs.isEmpty();
}
static public boolean empty(Object o) {
if (o instanceof Collection)
return empty((Collection) o);
if (o instanceof String)
return empty((String) o);
if (o instanceof Map)
return empty((Map) o);
if (o instanceof Object[])
return empty((Object[]) o);
if (o instanceof byte[])
return empty((byte[]) o);
if (o == null)
return true;
throw fail("unknown type for 'empty': " + getType(o));
}
static public boolean empty(Iterator i) {
return i == null || !i.hasNext();
}
static public boolean empty(double[] a) {
return a == null || a.length == 0;
}
static public boolean empty(float[] a) {
return a == null || a.length == 0;
}
static public boolean empty(int[] a) {
return a == null || a.length == 0;
}
static public boolean empty(long[] a) {
return a == null || a.length == 0;
}
static public boolean empty(byte[] a) {
return a == null || a.length == 0;
}
static public boolean empty(short[] a) {
return a == null || a.length == 0;
}
static public boolean empty(MultiSet ms) {
return ms == null || ms.isEmpty();
}
static public boolean empty(IMultiMap mm) {
return mm == null || mm.size() == 0;
}
static public boolean empty(File f) {
return getFileSize(f) == 0;
}
static public boolean empty(IntRange r) {
return r == null || r.empty();
}
static public boolean empty(Rect r) {
return !(r != null && r.w != 0 && r.h != 0);
}
static public boolean empty(Chain c) {
return c == null;
}
static public boolean empty(AppendableChain c) {
return c == null;
}
static public boolean empty(IntSize l) {
return l == null || l.size() == 0;
}
static public Object first(Object list) {
return first((Iterable) list);
}
static public A first(List list) {
return empty(list) ? null : list.get(0);
}
static public A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
static public Pair first(Map map) {
return mapEntryToPair(first(entrySet(map)));
}
static public Pair first(MultiMap mm) {
if (mm == null)
return null;
var e = first(mm.data.entrySet());
if (e == null)
return null;
return pair(e.getKey(), first(e.getValue()));
}
static public A first(IterableIterator i) {
return first((Iterator ) i);
}
static public A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
static public A first(Iterable i) {
if (i == null)
return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
static public Character first(String s) {
return empty(s) ? null : s.charAt(0);
}
static public Character first(CharSequence s) {
return empty(s) ? null : s.charAt(0);
}
static public A first(Pair p) {
return p == null ? null : p.a;
}
static public A first(T3 t) {
return t == null ? null : t.a;
}
static public Byte first(byte[] l) {
return empty(l) ? null : l[0];
}
static public Double first(double[] l) {
return empty(l) ? null : l[0];
}
static public A first(A[] l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(Iterable l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(IF1 pred, Iterable l) {
return firstThat(pred, l);
}
static public A first(AppendableChain a) {
return a == null ? null : a.element;
}
static public A first(IMultiSet a) {
return a == null ? null : first(a.keySet());
}
static public boolean nempty(Collection c) {
return !empty(c);
}
static public boolean nempty(CharSequence s) {
return !empty(s);
}
static public boolean nempty(Object[] o) {
return !empty(o);
}
static public boolean nempty(byte[] o) {
return !empty(o);
}
static public boolean nempty(int[] o) {
return !empty(o);
}
static public boolean nempty(BitSet bs) {
return !empty(bs);
}
static public boolean nempty(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(IMultiMap mm) {
return mm != null && mm.size() != 0;
}
static public boolean nempty(Object o) {
return !empty(o);
}
static public boolean nempty(IntRange r) {
return !empty(r);
}
static public boolean nempty(Rect r) {
return r != null && r.w != 0 && r.h != 0;
}
static public boolean nempty(MultiSet ms) {
return ms != null && !ms.isEmpty();
}
static public boolean nempty(IntSize l) {
return l != null && l.size() != 0;
}
static public A[] toTypedArray(Class type, Iterable c) {
return toArray(c, type);
}
static public String pnlToLines(String prefix, Iterable l) {
return pnlToString(prefix, l);
}
static public String pnlToLines(Iterable l) {
return pnlToString(l);
}
static public String pnlToLines(A[] l) {
return pnlToString(l);
}
static public String pnlToLines(Map map) {
return pnlToString(map);
}
static public String pnlToLines(MultiMap map) {
return pnlToString(map);
}
static public String formatRecordVars(String recordName, Object... params) {
return renderRecordVars(recordName, params);
}
static volatile public StringBuffer local_log = new StringBuffer();
static public boolean printAlsoToSystemOut = true;
static volatile public Appendable print_log = local_log;
static volatile public int print_log_max = 1024 * 1024;
static volatile public int local_log_max = 100 * 1024;
static public boolean print_silent = false;
static public Object print_byThread_lock = new Object();
static volatile public ThreadLocal print_byThread;
static volatile public Object print_allThreads;
static volatile public Object print_preprocess;
static public void print() {
print("");
}
static public A print(String s, A o) {
print(combinePrintParameters(s, o));
return o;
}
static public A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = o + "\n";
print_noNewLine(s);
return o;
}
static public void print_noNewLine(String s) {
try {
Object f = getThreadLocal(print_byThread_dontCreate());
if (f == null)
f = print_allThreads;
if (f != null)
if (isFalse(f instanceof F1 ? ((F1) f).get(s) : callF(f, s)))
return;
} catch (Throwable e) {
System.out.println(getStackTrace(e));
}
print_raw(s);
}
static public void print_raw(String s) {
if (print_preprocess != null)
s = (String) callF(print_preprocess, s);
s = fixNewLines(s);
Appendable loc = local_log;
Appendable buf = print_log;
int loc_max = print_log_max;
if (buf != loc && buf != null) {
print_append(buf, s, print_log_max);
loc_max = local_log_max;
}
if (loc != null)
print_append(loc, s, loc_max);
if (printAlsoToSystemOut)
System.out.print(s);
vmBus_send("printed", mc(), s);
}
static public void print_autoRotate() {
}
static public String indentx(Object s) {
return indentx(strOrEmpty(s));
}
static public String indentx(String s) {
return indentx(indent_default, s);
}
static public String indentx(int n, String s) {
return dropSuffix(repeat(' ', n), indent(n, s));
}
static public String indentx(String indent, String s) {
return dropSuffix(indent, indent(indent, s));
}
public static String join(String glue, Iterable strings) {
if (strings == null)
return "";
if (strings instanceof Collection) {
if (((Collection) strings).size() == 1)
return strOrEmpty(first((Collection) strings));
}
StringBuilder buf = new StringBuilder();
Iterator i = strings.iterator();
if (i.hasNext()) {
buf.append(strOrEmpty(i.next()));
while (i.hasNext()) buf.append(glue).append(strOrEmpty(i.next()));
}
return buf.toString();
}
public static String join(String glue, String... strings) {
return join(glue, Arrays.asList(strings));
}
public static String join(String glue, Object... strings) {
return join(glue, Arrays.asList(strings));
}
static public String join(Iterable strings) {
return join("", strings);
}
static public String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
static public String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
static public TokenIndexedList3 tokenIndexedList3(List l) {
return l instanceof TokenIndexedList3 ? ((TokenIndexedList3) l) : new TokenIndexedList3(l);
}
static public void tok_ifdef(List tok, IF1 isDefined) {
jreplace_dyn(tok, "ifdef or ", (_tok, cIdx) -> {
String flag1 = tok.get(cIdx + 2), flag2 = tok.get(cIdx + 6);
boolean value = isDefined.get(flag1) || isDefined.get(flag2);
return "ifdef " + value;
});
tok_conditionals(tok, "ifdef", "endifdef", isDefined, true, false);
}
static public void tok_pcall_script(List tok) {
replaceKeywordBlock(tok, "pcall", "try {", "} catch __e { pcallFail __e }");
}
static public void tok_script_settable(List tok) {
int i;
while ((i = jfind(tok, "settable :")) >= 0) {
String id = tok.get(i + 2);
int iType = i + 6;
String type = tok_script_scanType(tok, i + 6);
String getter = "def !synthetic " + id + ": " + type + " { this !_getField_ " + id + "}";
String setter = "def !synthetic " + id + " " + id + ": " + type + " { this " + id + " <- " + id + "; this }";
replaceToken_reTok(tok, i, joinWithSpace(getter, setter));
}
}
static public String jreplace(String s, String in, String out) {
return jreplace(s, in, out, null);
}
static public String jreplace(String s, String in, String out, Object condition) {
List tok = javaTok(s);
return jreplace(tok, in, out, condition) ? join(tok) : s;
}
static public boolean jreplace(List tok, String in, String out) {
return jreplace(tok, in, out, false, true, null);
}
static public boolean jreplace(List tok, String in, String out, Object condition) {
return jreplace(tok, in, out, false, true, condition);
}
static public boolean jreplace(List tok, String in, ITokCondition condition, String out) {
return jreplace(tok, in, out, (Object) condition);
}
static public boolean jreplace(List tok, String in, String out, IF2, Integer, Boolean> condition) {
return jreplace(tok, in, out, (Object) condition);
}
static public boolean jreplace(List tok, String in, String out, boolean ignoreCase, boolean reTok, Object condition) {
String[] toks = javaTokForJFind_array(in);
int lTokin = toks.length * 2 + 1;
boolean anyChange = false;
int i = -1;
for (int n = 0; n < 10000; n++) {
i = findCodeTokens(tok, i + 1, ignoreCase, toks, condition);
if (i < 0)
return anyChange;
List subList = tok.subList(i - 1, i + lTokin - 1);
String expansion = jreplaceExpandRefs(out, subList);
int end = i + lTokin - 2;
clearAllTokens(tok, i, end);
tok.set(i, expansion);
if (reTok)
reTok(tok, i, end);
i = end;
anyChange = true;
}
throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
}
static public boolean jreplace_debug = false;
static public ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
static public ArrayList cloneList(Collection l) {
if (l == null)
return new ArrayList();
synchronized (collectionMutex(l)) {
return new ArrayList (l);
}
}
static public boolean setText_opt = true;
static public A setText(A c, Object text) {
setText((JComponent) c, text);
return c;
}
static public A setText(final A c, Object text) {
final String s = strUnnull(text);
{
swing(() -> {
c.getEditor().setItem(s);
});
}
return c;
}
static public void setText(JLabel c, Object text) {
setText((JComponent) c, text);
}
static public JButton setText(JButton c, Object text) {
setText((JComponent) c, jlabel_textAsHTML_center_ifNeeded(strUnnull(text)));
return c;
}
static public A setText(final A c, Object text) {
if (c == null)
return null;
final String s = strUnnull(text);
{
swing(() -> {
if (!setText_opt || neq(callOpt(c, "getText"), s))
call(c, "setText", s);
});
}
return c;
}
static public RuntimeException fail() {
throw new RuntimeException("fail");
}
static public RuntimeException fail(Throwable e) {
throw asRuntimeException(e);
}
static public RuntimeException fail(Object msg) {
throw new RuntimeException(String.valueOf(msg));
}
static public RuntimeException fail(Object... objects) {
throw new Fail(objects);
}
static public RuntimeException fail(String msg) {
throw new RuntimeException(msg == null ? "" : msg);
}
static public RuntimeException fail(String msg, Throwable innerException) {
throw new RuntimeException(msg, innerException);
}
static public RuntimeException rethrowAndAppendToMessage(Throwable t, String msg) {
String haveMsg = t.getMessage();
if (empty(msg) || endsWith(haveMsg, " " + msg))
throw rethrow(t);
throw new RuntimeException(joinWithSpace(t.getMessage(), msg), t);
}
static public String squareBracketed(String s) {
return "[" + s + "]";
}
static public String spaceCombine(Object... l) {
return joinNemptiesWithSpace(flattenCollections(ll(l)));
}
static public AutoCloseable tempRestoreMap(Map map) {
if (map == null)
return null;
var cloned = cloneMap(map);
return () -> copyMap(cloned, map);
}
static public String quote(Object o) {
if (o == null)
return "null";
return quote(str(o));
}
static public String quote(String s) {
if (s == null)
return "null";
StringBuilder out = new StringBuilder((int) (l(s) * 1.5 + 2));
quote_impl(s, out);
return out.toString();
}
static public void quote_impl(String s, StringBuilder out) {
out.append('"');
int l = s.length();
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"')
out.append('\\').append(c);
else if (c == '\r')
out.append("\\r");
else if (c == '\n')
out.append("\\n");
else if (c == '\t')
out.append("\\t");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
static public boolean is(String a, String b) {
return false;
}
static public void _close(AutoCloseable c) {
if (c != null)
try {
c.close();
} catch (Throwable e) {
if (c instanceof javax.imageio.stream.ImageOutputStream)
return;
else
throw rethrow(e);
}
}
static public String assertIdentifier(String s) {
return assertIsIdentifier(s);
}
static public String assertIdentifier(String msg, String s) {
return assertIsIdentifier(msg, s);
}
static public Map putOrCreateLinkedHashMap(Map map, A key, B value) {
if (map == null)
map = new LinkedHashMap();
map.put(key, value);
return map;
}
static public boolean isIdentifier(String s) {
return isJavaIdentifier(s);
}
static public A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
static public A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
static public A assertNotNull(Scorer scorer, String msg, A a) {
if (scorer == null)
return assertNotNull(msg, a);
if (a == null) {
print("BAD - " + msg + " is null: " + a);
scorer.add(false);
} else {
print("OK, " + msg + " not null: " + a);
scorer.add(true);
}
return a;
}
static public A or(A a, A b) {
return a != null ? a : b;
}
static public Class typeToClass(Type type) {
if (type == null)
return null;
if (type instanceof Class)
return ((Class) type);
if (type instanceof ParameterizedType)
return optCast(Class.class, ((ParameterizedType) type).getRawType());
if (type instanceof GenericArrayType)
return typeToClass(((GenericArrayType) type).getGenericComponentType()).arrayType();
if (type instanceof IResolvableClass)
return ((IResolvableClass) type).resolveToClass();
return null;
}
static public void printVars(Object... params) {
printVars_str(params);
}
static public Object metaGet(IMeta o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(Object o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, IMeta o) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, Object o) {
return metaMapGet(o, key);
}
static public void scaffoldCalled(Object obj, Object function, Object... args) {
printShortenedFunctionCall(200, (obj == null ? "" : shorten(20, str(obj)) + " :: ") + function, args);
}
static public boolean startsWithDigit(String s) {
return nempty(s) && isDigit(s.charAt(0));
}
static public boolean isQuoted(String s) {
if (isNormalQuoted(s))
return true;
return isMultilineQuoted(s);
}
static public boolean startsWith(String a, String b) {
return a != null && a.startsWith(unnull(b));
}
static public boolean startsWith(String a, char c) {
return nemptyString(a) && a.charAt(0) == c;
}
static public boolean startsWith(String a, String b, Matches m) {
if (!startsWith(a, b))
return false;
if (m != null)
m.m = new String[] { substring(a, strL(b)) };
return true;
}
static public boolean startsWith(List a, List b) {
if (a == null || listL(b) > listL(a))
return false;
for (int i = 0; i < listL(b); i++) if (neq(a.get(i), b.get(i)))
return false;
return true;
}
static public String unquote(String s) {
if (s == null)
return null;
if (startsWith(s, '[')) {
int i = 1;
while (i < s.length() && s.charAt(i) == '=') ++i;
if (i < s.length() && s.charAt(i) == '[') {
String m = s.substring(1, i);
if (s.endsWith("]" + m + "]"))
return s.substring(i + 1, s.length() - i - 1);
}
}
return unquoteSingleOrDoubleQuotes(s);
}
static public boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
static public boolean swic(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { substring(a, l(b)) };
return true;
}
static public int parseHexInt(String s) {
return hexToInt(s);
}
static public String[] dropFirst(int n, String[] a) {
return drop(n, a);
}
static public String[] dropFirst(String[] a) {
return drop(1, a);
}
static public Object[] dropFirst(Object[] a) {
return drop(1, a);
}
static public List dropFirst(List l) {
return dropFirst(1, l);
}
static public List dropFirst(int n, Iterable i) {
return dropFirst(n, toList(i));
}
static public List dropFirst(Iterable i) {
return dropFirst(toList(i));
}
static public List dropFirst(int n, List l) {
return n <= 0 ? l : new ArrayList(l.subList(Math.min(n, l.size()), l.size()));
}
static public List dropFirst(List l, int n) {
return dropFirst(n, l);
}
static public String dropFirst(int n, String s) {
return substring(s, n);
}
static public String dropFirst(String s, int n) {
return substring(s, n);
}
static public String dropFirst(String s) {
return substring(s, 1);
}
static public Chain dropFirst(Chain c) {
return c == null ? null : c.next;
}
static public int intFromBinary(String s) {
return Integer.parseInt(s, 2);
}
static public boolean isInteger(String s) {
int n = l(s);
if (n == 0)
return false;
int i = 0;
if (s.charAt(0) == '-')
if (++i >= n)
return false;
while (i < n) {
char c = s.charAt(i);
if (c < '0' || c > '9')
return false;
++i;
}
return true;
}
static public Number parseIntOrLong(String s) {
long l = parseLong(s);
return longIsInt(l) ? (Number) (int) l : (Number) l;
}
static public boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
static public boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
static public float parseFloat(String s) {
return Float.parseFloat(s);
}
static public boolean endsWith(String a, String b) {
return a != null && a.endsWith(b);
}
static public boolean endsWith(String a, char c) {
return nempty(a) && lastChar(a) == c;
}
static public boolean endsWith(String a, String b, Matches m) {
if (!endsWith(a, b))
return false;
m.m = new String[] { dropLast(l(b), a) };
return true;
}
static public long parseLong(String s) {
if (empty(s))
return 0;
return Long.parseLong(dropSuffix("L", s));
}
static public long parseLong(Object s) {
return Long.parseLong((String) s);
}
static public double parseDouble(String s) {
return empty(s) ? 0.0 : Double.parseDouble(s);
}
static public boolean hasStaticMethodNamed(Class c, String method) {
if (c == null)
return false;
var methods = getMethodCache(c).cache.get(method);
if (methods != null)
for (var m : methods) if (isStaticMethod(m))
return true;
return false;
}
static public boolean isInterface(Class c) {
return c != null && c.isInterface();
}
static public Field getField(Object o, String field) {
if (o == null)
return null;
return setOpt_findField(_getClass(o), field);
}
static public Object getField(Field field, Object o) {
return fieldGet(field, o);
}
static public Field findFieldInInterfaces(Class c, String field) {
if (c == null)
return null;
for (var intf : allInterfacesImplementedBy(c)) {
var __1 = getField(intf, field);
if (__1 != null)
return __1;
}
return null;
}
static public boolean isStaticField(Field f) {
return (f.getModifiers() & Modifier.STATIC) != 0;
}
static public String[] toStringArray(Collection c) {
String[] a = new String[l(c)];
Iterator it = c.iterator();
for (int i = 0; i < l(a); i++) a[i] = it.next();
return a;
}
static public String[] toStringArray(Object o) {
if (o instanceof String[])
return (String[]) o;
else if (o instanceof Collection)
return toStringArray((Collection) o);
else
throw fail("Not a collection or array: " + getClassName(o));
}
static public Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
static public Set keys(Object map) {
return keys((Map) map);
}
static public Set keys(MultiSet ms) {
return ms == null ? null : ms.keySet();
}
static public Set keys(IMultiMap mm) {
return mm == null ? null : mm.keySet();
}
static public List constructorsWithNumberOfArguments(Class c, int n) {
return filter(getDeclaredConstructors_cached(c), con -> l(con.getParameterTypes()) == n);
}
static public Object[] toArray(Collection c) {
return toObjectArray(c);
}
static public A[] toArray(Class type, Iterable c) {
return toArray(c, type);
}
static public A[] toArray(Class type, Collection c) {
return toArray(c, type);
}
static public A[] toArray(Collection c, Class type) {
A[] a = arrayOfType(l(c), type);
if (a.length == 0)
return a;
asList(c).toArray(a);
return a;
}
static public A[] toArray(Iterable c, Class type) {
var c2 = asList(c);
A[] a = arrayOfType(l(c2), type);
if (a.length == 0)
return a;
c2.toArray(a);
return a;
}
static public A[] toArray(A[] array, Collection c) {
if (array == null || c == null)
return null;
asList(c).toArray(array);
return array;
}
static public A[] toArrayOrNull(Class type, Collection c) {
if (empty(c))
return null;
return toArray(type, c);
}
static public RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static public A set(A o, String field, Object value) {
if (o == null)
return null;
if (o instanceof Class)
set((Class) o, field, value);
else
try {
Field f = set_findField(o.getClass(), field);
makeAccessible(f);
smartSet(f, o, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
static public void set(Class c, String field, Object value) {
if (c == null)
return;
try {
Field f = set_findStaticField(c, field);
makeAccessible(f);
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public Field set_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static public Field set_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static public void set(BitSet bs, int idx) {
{
if (bs != null)
bs.set(idx);
}
}
static public Map parsePrimitiveType_map = litmap("int", int.class, "char", char.class, "byte", byte.class, "short", short.class, "long", long.class, "float", float.class, "double", double.class, "bool", boolean.class);
static public Class parsePrimitiveType(String s) {
return parsePrimitiveType_map.get(s);
}
static public String joinSubList(List l, int i, int j) {
return join(subList(l, i, j));
}
static public String joinSubList(List l, int i) {
return join(subList(l, i));
}
static public String joinSubList(List l, IntRange r) {
return r == null ? null : joinSubList(l, r.start, r.end);
}
static public Map classForName_cache = synchroHashMap();
static public Class classForName(String name) {
return classForName(name, null);
}
static public Class classForName(String name, Object classFinder) {
if (classForName_cache == null || classFinder != null)
return classForName_uncached(name, classFinder);
Class c = classForName_cache.get(name);
if (c == null)
classForName_cache.put(name, c = classForName_uncached(name, null));
return c;
}
static public Class classForName_uncached(String name, Object classFinder) {
try {
if (classFinder != null)
return (Class) callF(classFinder, name);
return Class.forName(name);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Class classForNameOpt_noCache(String name) {
try {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String unnullForIteration(String s) {
return s == null ? "" : s;
}
static public Collection unnullForIteration(Collection l) {
return l == null ? immutableEmptyList() : l;
}
static public List unnullForIteration(List l) {
return l == null ? immutableEmptyList() : l;
}
static public byte[] unnullForIteration(byte[] l) {
return l == null ? emptyByteArray() : l;
}
static public int[] unnullForIteration(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnullForIteration(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnullForIteration(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public short[] unnullForIteration(short[] l) {
return l == null ? emptyShortArray() : l;
}
static public Map unnullForIteration(Map l) {
return l == null ? immutableEmptyMap() : l;
}
static public Iterable unnullForIteration(Iterable i) {
return i == null ? immutableEmptyList() : i;
}
static public A[] unnullForIteration(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnullForIteration(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnullForIteration(Pt p) {
return p == null ? new Pt() : p;
}
static public Symbol unnullForIteration(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnullForIteration(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public long unnullForIteration(Long l) {
return l == null ? 0L : l;
}
static public boolean hasMethodNamed(Object obj, String method) {
if (obj == null)
return false;
if (obj instanceof Class)
return hasMethodNamed((Class) obj, method);
return hasMethodNamed(obj.getClass(), method);
}
static public boolean hasMethodNamed(Class c, String method) {
if (c == null)
return false;
return getMethodCache(c).cache.containsKey(method);
}
static public Class mc() {
return main.class;
}
static public List reversed(Iterable l) {
return reversedList(l);
}
static public List reversed(A[] l) {
return reversedList(asList(l));
}
static public String reversed(String s) {
return reversedString(s);
}
static public boolean contains(Collection c, Object o) {
return c != null && c.contains(o);
}
static public boolean contains(Iterable it, Object a) {
if (it != null)
for (Object o : it) if (eq(a, o))
return true;
return false;
}
static public boolean contains(Object[] x, Object o) {
if (x != null)
for (Object a : x) if (eq(a, o))
return true;
return false;
}
static public boolean contains(String s, char c) {
return s != null && s.indexOf(c) >= 0;
}
static public boolean contains(String s, String b) {
return s != null && s.indexOf(b) >= 0;
}
static public boolean contains(BitSet bs, int i) {
return bs != null && bs.get(i);
}
static public boolean contains(Producer p, A a) {
if (p != null && a != null)
while (true) {
A x = p.next();
if (x == null)
break;
if (eq(x, a))
return true;
}
return false;
}
static public boolean contains(Rect r, Pt p) {
return rectContains(r, p);
}
static public Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
static public Collection values(Object map) {
return values((Map) map);
}
static public Collection values(MultiMap mm) {
return mm == null ? emptyList() : concatLists(values(mm.data));
}
static public List nonNulls(Iterable l) {
return withoutNulls(l);
}
static public List nonNulls(A[] l) {
return withoutNulls(l);
}
static public Map nonNulls(Map map) {
return withoutNulls(map);
}
static public List nonNulls(Iterable l, IF1 f) {
return mapNonNulls(l, f);
}
static public Map mapToMap(IF1> f, Iterable l) {
Map map = new HashMap();
for (A o : unnullForIteration(l)) {
Pair p = f.get(o);
map.put(p.a, p.b);
}
return map;
}
static public Map mapToMap(Iterable l, IF1 > f) {
return mapToMap(f, l);
}
static public Map mapToMap(Map m, IF2 > f) {
return mapMapToMap(f, m);
}
static public Map mapToMap(IF2> f, Map m) {
return mapMapToMap(f, m);
}
static public Pair pair(A a, B b) {
return new Pair(a, b);
}
static public Pair pair(A a) {
return new Pair(a, a);
}
static public Map mapWithSingleValue(Iterable l, B b) {
HashMap map = new HashMap();
if (l != null)
for (A a : l) map.put(a, b);
return map;
}
static public HashMap litmap(Object... x) {
HashMap map = new HashMap();
litmap_impl(map, x);
return map;
}
static public void litmap_impl(Map map, Object... x) {
if (x != null)
for (int i = 0; i < x.length - 1; i += 2) if (x[i + 1] != null)
map.put(x[i], x[i + 1]);
}
static public AutoCloseable tempMapPutAll(Map map, Map toAdd) {
if (map != null && nempty(toAdd)) {
List> toRestore = new ArrayList();
for (var __0 : _entrySet(toAdd)) {
var key = __0.getKey();
var value = __0.getValue();
if (key != null && value != null) {
B old = map.put(key, value);
if (!eq(old, value))
toRestore.add(pair(key, old));
}
}
return () -> {
for (var p : toRestore) mapPutOrRemove(map, p.a, p.b);
};
}
return null;
}
static public List keysList(Map map) {
return cloneListSynchronizingOn(keys(map), map);
}
static public List keysList(MultiSet ms) {
return ms == null ? null : keysList(ms.map);
}
static public B[] valuesArray(Class valueType, Map map) {
if (map == null)
return null;
synchronized (collectionMutex(map)) {
int n = map.size();
B[] array = newArray(valueType, n);
var it = valueIterator(map);
for (int i = 0; i < n; i++) array[i] = it.next();
return array;
}
}
static public A addAndReturn(Collection c, A a) {
if (c != null)
c.add(a);
return a;
}
static public A addAndReturn(List c, int idx, A a) {
if (c != null)
c.add(idx, a);
return a;
}
static public AutoCloseable tempAdd(Collection l, A a) {
if (l == null || l.contains(a))
return null;
l.add(a);
return new tempAdd_undo(l, a);
}
static public class tempAdd_undo implements AutoCloseable, IFieldsToList {
public Collection l;
public A a;
public tempAdd_undo() {
}
public tempAdd_undo(Collection l, A a) {
this.a = a;
this.l = l;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + l + ", " + a + ")";
}
public Object[] _fieldsToList() {
return new Object[] { l, a };
}
public void close() {
try {
l.remove(a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
static public AutoCloseable tempAdd(Container a, Component b) {
if (a == null || b == null)
return null;
{
return swing(() -> {
if (b.getParent() == a)
return null;
a.add(b);
return () -> {
swing(() -> {
if (b.getParent() == a)
removeFromParent(b);
});
};
});
}
}
static public TreeSet mapToTreeSet(Object f, Iterable l) {
TreeSet x = new TreeSet();
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
static public TreeSet mapToTreeSet(IF1 f, Iterable l) {
TreeSet x = new TreeSet();
if (l != null)
for (var o : l) x.add(f.get(o));
return x;
}
static public TreeSet mapToTreeSet(Iterable l, IF1 f) {
return mapToTreeSet(f, l);
}
static public String shortenClassName(String name) {
if (name == null)
return null;
int i = lastIndexOf(name, "$");
if (i < 0)
i = lastIndexOf(name, ".");
return i < 0 ? name : substring(name, i + 1);
}
static public boolean isAnonymousClass(Class c) {
return isAnonymousClassName(className(c));
}
static public String shortClassName(Object o) {
if (o == null)
return null;
Class c = o instanceof Class ? (Class) o : o.getClass();
String name = c.getName();
return shortenClassName(name);
}
static public String className(Object o) {
return getClassName(o);
}
static public TreeSet asTreeSet(Collection set) {
return set == null ? null : set instanceof TreeSet ? (TreeSet) set : new TreeSet(set);
}
static public boolean isAnonymousClassName(String s) {
for (int i = 0; i < l(s); i++) if (s.charAt(i) == '$' && Character.isDigit(s.charAt(i + 1)))
return true;
return false;
}
static public String longestPrefixInTreeSet(String s, TreeSet set) {
return longestPrefixInNavigableSet(s, set);
}
static public String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
static public int indexOf(List l, A a, int startIndex) {
if (l == null)
return -1;
int n = l(l);
for (int i = startIndex; i < n; i++) if (eq(l.get(i), a))
return i;
return -1;
}
static public int indexOf(List l, int startIndex, A a) {
return indexOf(l, a, startIndex);
}
static public int indexOf(List l, A a) {
if (l == null)
return -1;
return l.indexOf(a);
}
static public int indexOf(String a, String b) {
return a == null || b == null ? -1 : a.indexOf(b);
}
static public int indexOf(String a, String b, int i) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(String a, char b) {
return a == null ? -1 : a.indexOf(b);
}
static public int indexOf(String a, int i, char b) {
return indexOf(a, b, i);
}
static public int indexOf(String a, char b, int i) {
return a == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(String a, int i, String b) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(A[] x, A a) {
int n = l(x);
for (int i = 0; i < n; i++) if (eq(x[i], a))
return i;
return -1;
}
static public int indexOf(Iterable l, A a) {
if (l == null)
return -1;
int i = 0;
for (A x : l) {
if (eq(x, a))
return i;
i++;
}
return -1;
}
static public int smartIndexOf(String s, String sub, int i) {
if (s == null)
return 0;
i = s.indexOf(sub, min(i, l(s)));
return i >= 0 ? i : l(s);
}
static public int smartIndexOf(String s, int i, char c) {
return smartIndexOf(s, c, i);
}
static public int smartIndexOf(String s, char c, int i) {
if (s == null)
return 0;
i = s.indexOf(c, min(i, l(s)));
return i >= 0 ? i : l(s);
}
static public int smartIndexOf(String s, String sub) {
return smartIndexOf(s, sub, 0);
}
static public int smartIndexOf(String s, char c) {
return smartIndexOf(s, c, 0);
}
static public int smartIndexOf(List l, A sub) {
return smartIndexOf(l, sub, 0);
}
static public int smartIndexOf(List l, int start, A sub) {
return smartIndexOf(l, sub, start);
}
static public int smartIndexOf(List l, A sub, int start) {
int i = indexOf(l, sub, start);
return i < 0 ? l(l) : i;
}
static public Set> _entrySet(Map map) {
return map == null ? Collections.EMPTY_SET : map.entrySet();
}
static public Map javaxClassShortcuts_cache;
static public Map javaxClassShortcuts() {
if (javaxClassShortcuts_cache == null)
javaxClassShortcuts_cache = javaxClassShortcuts_load();
return javaxClassShortcuts_cache;
}
static public Map javaxClassShortcuts_load() {
return litmap("O", "Object", "S", "String", "L", "List", "Cl", "Collection", "Int", "Integer");
}
static public List itemPlus(A a, Collection l) {
return itemPlusList(a, l);
}
static public List standardImports_fullyImportedPackages() {
return endingWith_dropSuffix(standardImports(), ".*");
}
static public List standardImports_singleClasses() {
return notEndingWith(standardImports(), ".*");
}
static public List map(Iterable l, Object f) {
return map(f, l);
}
static public List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (Object o : l) {
ping();
x.add(callF(f, o));
}
return x;
}
static public List map(Map map, Object f) {
List x = new ArrayList();
if (map != null)
for (Object _e : map.entrySet()) {
ping();
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
static public List map(Object f, Object[] l) {
return map(f, asList(l));
}
static public List map(Object[] l, Object f) {
return map(f, l);
}
static public List map(Object f, Map map) {
return map(map, f);
}
static public List map(Iterable l, F1 f) {
return map(f, l);
}
static public List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (A o : l) {
ping();
x.add(callF(f, o));
}
return x;
}
static public List map(IF1 f, Iterable l) {
return map(l, f);
}
static public List map(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null) {
var it = l.iterator();
if (it.hasNext()) {
var pingSource = pingSource();
do {
ping(pingSource);
x.add(f.get(it.next()));
} while (it.hasNext());
}
}
return x;
}
static public List map(IF1 f, A[] l) {
return map(l, f);
}
static public List map(A[] l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) {
ping();
x.add(f.get(o));
}
return x;
}
static public List map(Map map, IF2 f) {
List x = new ArrayList();
if (map != null)
for (Map.Entry e : map.entrySet()) {
ping();
x.add(f.get(e.getKey(), e.getValue()));
}
return x;
}
static public List map(IF1 f, A data1, A... moreData) {
List x = emptyList(l(moreData) + 1);
x.add(f.get(data1));
if (moreData != null)
for (A o : moreData) {
ping();
x.add(f.get(o));
}
return x;
}
static public Field findFieldOfClass(Class c, String field) {
return c == null || field == null ? null : getOpt_getFieldMap(c).get(field);
}
static public boolean classHasMethodNamed(Class c, String method) {
if (c == null)
return false;
return getMethodCache(c).cache.containsKey(method);
}
static public boolean scaffoldingEnabled(Object o) {
return metaGet(o, "scaffolding") != null;
}
static public AutoCloseable tempMapPut(Map map, A key, B value) {
if (map != null && key != null && value != null) {
B old = map.put(key, value);
return () -> mapPutOrRemove(map, key, old);
}
return null;
}
static public File getBytecodePathForClass(Object o) {
return getBytecodePathForClass(_getClass(o));
}
static public File getBytecodePathForClass(Class c) {
try {
return c == null ? null : new File(c.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String unquote_relaxedMLS(String s) {
if (s == null)
return null;
if (startsWith(s, '[')) {
int i = 1;
while (i < s.length() && s.charAt(i) == '=') ++i;
if (i < s.length() && s.charAt(i) == '[') {
String m = s.substring(1, i);
int n = s.length();
if (s.endsWith("]" + m + "]"))
n -= i + 1;
return s.substring(i + 1, n);
}
}
return unquoteSingleOrDoubleQuotes(s);
}
static public String intern(String s) {
return fastIntern(s);
}
static public Map putAll(Map a, Map extends A, ? extends B> b) {
if (a != null && b != null)
a.putAll(b);
return a;
}
static public MultiMap putAll(MultiMap a, Map extends A, ? extends B> b) {
if (a != null)
a.putAll((Map) b);
return a;
}
static public Map putAll(Map a, Object... b) {
if (a != null)
litmap_impl(a, b);
return a;
}
static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public class getOpt_Map extends WeakHashMap {
public getOpt_Map() {
if (getOpt_special == null)
getOpt_special = new HashMap();
clear();
}
public void clear() {
super.clear();
put(Class.class, getOpt_special);
put(String.class, getOpt_special);
}
}
static final public Map> getOpt_cache = _registerDangerousWeakMap(synchroMap(new getOpt_Map()));
static public HashMap getOpt_special;
static public Map getOpt_getFieldMap(Object o) {
Class c = _getClass(o);
HashMap map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
return map;
}
static public Object getOpt_cached(Object o, String field) {
try {
if (o == null)
return null;
Map map = getOpt_getFieldMap(o);
if (map == getOpt_special) {
if (o instanceof Class)
return getOpt((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
}
Field f = map.get(field);
if (f != null)
return f.get(o);
if (o instanceof DynamicObject)
return syncMapGet2(((DynamicObject) o).fieldValues, field);
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public HashMap getOpt_makeCache(Class c) {
HashMap map;
if (isSubtypeOf(c, Map.class))
map = getOpt_special;
else {
map = new HashMap();
if (!reflection_classesNotToScan().contains(c.getName())) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) {
makeAccessible(f);
String name = f.getName();
if (!map.containsKey(name))
map.put(name, f);
}
_c = _c.getSuperclass();
} while (_c != null);
}
}
if (getOpt_cache != null)
getOpt_cache.put(c, map);
return map;
}
static public Field getOpt_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
static public Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
static public Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
static public Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
static public HashSet lithashset(A... items) {
HashSet set = new HashSet();
for (A a : items) set.add(a);
return set;
}
static public TreeSet caseInsensitiveSet() {
return caseInsensitiveSet_treeSet();
}
static public TreeSet caseInsensitiveSet(Collection c) {
return caseInsensitiveSet_treeSet(c);
}
static public Set syncLinkedHashSet() {
return synchroLinkedHashSet();
}
static public void pcallFail(Throwable e) {
pcallPolicyForThread().handlePcallFail(e);
}
static public void pcallFail(String msg) {
pcallFail(new Throwable(msg));
}
static public String dropNumberPrefix(String s) {
return dropFirst(s, indexOfNonDigit(s));
}
static public String str(Object o) {
return o == null ? "null" : o.toString();
}
static public String str(char[] c) {
return c == null ? "null" : new String(c);
}
static public String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
static public Object getOptDynOnly(DynamicObject o, String field) {
if (o == null || o.fieldValues == null)
return null;
return o.fieldValues.get(field);
}
static public RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static volatile public boolean ping_pauseAll = false;
static public int ping_sleep = 100;
static volatile public boolean ping_anyActions = false;
static public Map ping_actions = newWeakHashMap();
static public ThreadLocal ping_isCleanUpThread = new ThreadLocal();
static public boolean ping(PingSource pingSource) {
return ping();
}
static public boolean ping() {
newPing();
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
return true;
}
static public boolean ping_impl(boolean okInCleanUp) {
try {
if (ping_pauseAll && !isAWTThread()) {
do Thread.sleep(ping_sleep); while (ping_pauseAll);
return true;
}
if (ping_anyActions) {
if (!okInCleanUp && !isTrue(ping_isCleanUpThread.get()))
failIfUnlicensed();
Object action = null;
synchronized (ping_actions) {
if (!ping_actions.isEmpty()) {
action = ping_actions.get(currentThread());
if (action instanceof Runnable)
ping_actions.remove(currentThread());
if (ping_actions.isEmpty())
ping_anyActions = false;
}
}
if (action instanceof Runnable)
((Runnable) action).run();
else if (eq(action, "cancelled"))
throw fail("Thread cancelled.");
}
return false;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Iterator iterator(Iterable c) {
return c == null ? emptyIterator() : c.iterator();
}
static public void replaceLastElement(List l, A a) {
if (nempty(l))
l.set(l(l) - 1, a);
}
static public int iteratorCount_int_close(Iterator i) {
try {
int n = 0;
if (i != null)
while (i.hasNext()) {
i.next();
++n;
}
if (i instanceof AutoCloseable)
((AutoCloseable) i).close();
return n;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String getType(Object o) {
return getClassName(o);
}
static public long getFileSize(String path) {
return path == null ? 0 : new File(path).length();
}
static public long getFileSize(File f) {
return f == null ? 0 : f.length();
}
static public Pair mapEntryToPair(Map.Entry e) {
return e == null ? null : pair(e.getKey(), e.getValue());
}
static public Set> entrySet(Map map) {
return _entrySet(map);
}
static public A firstThat(Iterable l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(A[] l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(IF1 pred, Iterable l) {
return firstThat(l, pred);
}
static public A firstThat(IF1 pred, A[] l) {
return firstThat(l, pred);
}
static public String pnlToString(String prefix, Iterable l) {
return hijackPrint(new Runnable() {
public void run() {
try {
pnl(prefix, l);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pnl(prefix, l)";
}
});
}
static public String pnlToString(final Iterable l) {
return hijackPrint(new Runnable() {
public void run() {
try {
pnl(l);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pnl(l)";
}
});
}
static public String pnlToString(final A[] l) {
return hijackPrint(new Runnable() {
public void run() {
try {
pnl(l);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pnl(l)";
}
});
}
static public String pnlToString(final Map map) {
return hijackPrint(new Runnable() {
public void run() {
try {
pnl(map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pnl(map)";
}
});
}
static public String pnlToString(MultiMap map) {
return pnlToString(multiMapToMap(map));
}
static public String renderRecordVars(String recordName, Object... params) {
List l = new ArrayList();
int i = 0;
for (; i + 1 < l(params); i += 2) l.add(params[i] + "=" + params[i + 1]);
return formatFunctionCall(recordName, l);
}
static public String combinePrintParameters(String s, Object o) {
return (endsWithLetterOrDigit(s) ? s + ": " : s) + o;
}
static public void ping_okInCleanUp() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
}
static public Object getThreadLocal(Object o, String name) {
ThreadLocal t = (ThreadLocal) (getOpt(o, name));
return t != null ? t.get() : null;
}
static public A getThreadLocal(ThreadLocal tl) {
return tl == null ? null : tl.get();
}
static public A getThreadLocal(ThreadLocal tl, A defaultValue) {
return or(getThreadLocal(tl), defaultValue);
}
static public ThreadLocal print_byThread_dontCreate() {
return print_byThread;
}
static public boolean isFalse(Object o) {
return eq(false, o);
}
static public Map> callF_cache = newDangerousWeakHashMap();
static public A callF(F0 f) {
return f == null ? null : f.get();
}
static public B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
static public A callF(IF0 f) {
return f == null ? null : f.get();
}
static public B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static public B callF(A a, IF1 f) {
return f == null ? null : f.get(a);
}
static public C callF(IF2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static public void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
static public void callF(A a, IVF1 f) {
if (f != null)
f.get(a);
}
static public void callF(IVF1 f, A a) {
if (f != null)
f.get(a);
}
static public Object callF(Runnable r) {
{
if (r != null)
r.run();
}
return null;
}
static public Object callF(Object f, Object... args) {
return safeCallF(f, args);
}
static public Object safeCallF(Object f, Object... args) {
if (f instanceof Runnable) {
((Runnable) f).run();
return null;
}
if (f == null)
return null;
Class c = f.getClass();
ArrayList methods;
synchronized (callF_cache) {
methods = callF_cache.get(c);
if (methods == null)
methods = callF_makeCache(c);
}
int n = l(methods);
if (n == 0) {
if (f instanceof String)
throw fail("Legacy call: " + f);
throw fail("No get method in " + getClassName(c));
}
if (n == 1)
return invokeMethod(methods.get(0), f, args);
for (int i = 0; i < n; i++) {
Method m = methods.get(i);
if (call_checkArgs(m, args, false))
return invokeMethod(m, f, args);
}
throw fail("No matching get method in " + getClassName(c));
}
static public ArrayList callF_makeCache(Class c) {
ArrayList l = new ArrayList();
Class _c = c;
do {
for (Method m : _c.getDeclaredMethods()) if (m.getName().equals("get")) {
makeAccessible(m);
l.add(m);
}
if (!l.isEmpty())
break;
_c = _c.getSuperclass();
} while (_c != null);
callF_cache.put(c, l);
return l;
}
static public String getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
static public String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
static public String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
static public String getStackTrace(String msg) {
return getStackTrace_noRecord(new Throwable(msg));
}
static public String fixNewLines(String s) {
int i = indexOf(s, '\r');
if (i < 0)
return s;
int l = s.length();
StringBuilder out = new StringBuilder(l);
out.append(s, 0, i);
for (; i < l; i++) {
char c = s.charAt(i);
if (c != '\r')
out.append(c);
else {
out.append('\n');
if (i + 1 < l && s.charAt(i + 1) == '\n')
++i;
}
}
return out.toString();
}
static public void print_append(Appendable buf, String s, int max) {
try {
synchronized (buf) {
buf.append(s);
if (buf instanceof StringBuffer)
rotateStringBuffer(((StringBuffer) buf), max);
else if (buf instanceof StringBuilder)
rotateStringBuilder(((StringBuilder) buf), max);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll_minimalExceptionHandling(vm_busListeners_live(), msg, arg);
pcallFAll_minimalExceptionHandling(vm_busListenersByMessage_live().get(msg), msg, arg);
}
static public void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
static public String strOrEmpty(Object o) {
return o == null ? "" : str(o);
}
static public String dropSuffix(String suffix, String s) {
return nempty(suffix) && endsWith(s, suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
static public String repeat(char c, int n) {
n = Math.max(n, 0);
char[] chars = new char[n];
for (int i = 0; i < n; i++) chars[i] = c;
return new String(chars);
}
static public List repeat(A a, int n) {
n = Math.max(n, 0);
List l = new ArrayList(n);
for (int i = 0; i < n; i++) l.add(a);
return l;
}
static public List repeat(int n, A a) {
return repeat(a, n);
}
static public int indent_default = 2;
static public String indent(int indent) {
return repeat(' ', indent);
}
static public String indent(int indent, String s) {
return indent(repeat(' ', indent), s);
}
static public String indent(String indent, String s) {
return indent + replace(unnull(s), "\n", "\n" + indent);
}
static public String indent(String s) {
return indent(indent_default, s);
}
static public List indent(String indent, List lines) {
List l = new ArrayList();
if (lines != null)
for (String s : lines) l.add(indent + s);
return l;
}
static public String jreplace_dyn(String s, String in, Object out) {
return jreplace_dyn(s, in, out, null);
}
static public String jreplace_dyn(String s, String in, Object out, Object condition) {
List tok = javaTok(s);
jreplace_dyn(tok, in, out, condition);
return join(tok);
}
static public boolean jreplace_dyn(List tok, String in, Object out) {
return jreplace_dyn(tok, in, out, false, true, null);
}
static public boolean jreplace_dyn(List tok, String in, IF0 out) {
return jreplace_dyn(tok, in, if0ToIF2(out));
}
static public boolean jreplace_dyn(List tok, String in, ITokCondition cond, IF0 out) {
return jreplace_dyn(tok, in, cond, if0ToIF2(out));
}
static public boolean jreplace_dyn(List tok, String in, IF1 out) {
return jreplace_dyn(tok, in, (_tok, cIdx) -> out.get(cIdx));
}
static public boolean jreplace_dyn(List tok, String in, IF2, Integer, String> out) {
return jreplace_dyn(tok, in, (Object) out);
}
static public boolean jreplace_dyn(List tok, String in, IF2, Integer, String> out, IF2, Integer, Boolean> condition) {
return jreplace_dyn(tok, in, (Object) out, (Object) condition);
}
static public boolean jreplace_dyn(List tok, String in, Object out, Object condition) {
return jreplace_dyn(tok, in, out, false, true, condition);
}
static public boolean jreplace_dyn(List tok, String in, Object out, boolean ignoreCase, boolean reTok, Object condition) {
List tokin = javaTok(in);
jfind_preprocess(tokin);
String[] toks = toStringArray(codeTokensOnly(tokin));
boolean anyChange = false;
for (int n = 0; n < 10000; n++) {
int i = findCodeTokens(tok, 1, ignoreCase, toks, condition);
if (i < 0)
return anyChange;
String expansion = (String) (callF(out, tok, i));
int end = i + l(tokin) - 2;
clearAllTokens(tok, i, end);
tok.set(i, unnull(expansion));
if (reTok)
reTok(tok, i, end);
anyChange = true;
}
throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
}
static public int tok_conditionals(List tok, String keyword, String keywordEnd, IF1 pred, boolean reTokImmediately, boolean noReTok) {
int changes = 0;
if (tok instanceof IContentsIndexedList) {
int[] l = ((IContentsIndexedList) tok).indicesOf(keyword);
for (int j = l(l) - 1; j >= 0; j--) {
int i = l[j];
if (isIdentifier(get(tok, i + 2))) {
tok_conditionals_processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok);
++changes;
}
}
} else {
if (!tok.contains(keyword))
return changes;
int i = l(tok);
while ((i = rjfind(tok, 1, i - 1, keyword + " ")) >= 0) {
++changes;
tok_conditionals_processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok);
}
}
if (changes != 0 && !reTokImmediately && !noReTok)
reTok(tok);
return changes;
}
static public void tok_conditionals_processConditional(List tok, int i, String keyword, String keywordEnd, IF1 pred, boolean reTokImmediately) {
int j = jfind(tok, i + 4, keywordEnd);
if (j < 0)
j = l(tok) - 1;
String name = tok.get(i + 2);
boolean has = pred.get(name);
if (has) {
clearTokens_maybeReTok(tok, j, j + 1, reTokImmediately);
clearTokens_maybeReTok(tok, i, i + 3, reTokImmediately);
} else
clearTokens_maybeReTok(tok, i, j + 1, reTokImmediately);
}
static public List replaceKeywordBlock(List tok, String keyword, String beg, String end) {
return replaceKeywordBlock(tok, keyword, beg, end, false, null);
}
static public List replaceKeywordBlock(List tok, String keyword, String beg, String end, Object cond) {
return replaceKeywordBlock(tok, keyword, beg, end, false, cond);
}
static public List replaceKeywordBlock(List tok, String keyword, String beg, String end, boolean debug, Object cond) {
for (int n = 0; n < 1000; n++) {
int i = jfind(tok, keyword + " {", cond);
if (i < 0)
break;
int idx = findCodeTokens(tok, i, false, "{");
int j = findEndOfBracketPart(tok, idx);
if (debug) {
print(toUpper(keyword) + " BEFORE\n" + join(subList(tok, i, j)));
print(" THEN " + join(subList(tok, j, j + 10)));
}
List subList = subList(tok, i - 1, idx);
tok.set(j - 1, jreplaceExpandRefs(end, subList));
replaceTokens(tok, i, idx + 1, jreplaceExpandRefs(beg, subList));
reTok(tok, i, j);
if (debug)
print(toUpper(keyword) + "\n" + join(subList(tok, i, j)) + "\n");
}
return tok;
}
static public int jfind(String s, String in) {
return jfind(javaTok(s), in);
}
static public int jfind(List tok, String in) {
return jfind(tok, 1, in);
}
static public int jfind(List tok, int startIdx, String in) {
return jfind(tok, startIdx, in, (ITokCondition) null);
}
static public int jfind(List tok, String in, Object condition) {
return jfind(tok, 1, in, condition);
}
static public int jfind(List tok, String in, IIntPred condition) {
return jfind(tok, 1, in, condition);
}
static public int jfind(List tok, int startIndex, String in, IIntPred condition) {
return jfind(tok, startIndex, in, tokCondition(condition));
}
static public int jfind(List tok, String in, ITokCondition condition) {
return jfind(tok, 1, in, condition);
}
static public int jfind(List tok, int startIndex, String in, ITokCondition condition) {
return jfind(tok, startIndex, in, (Object) condition);
}
static public int jfind(List tok, int startIdx, String in, Object condition) {
return jfind(tok, startIdx, javaTokForJFind_array(in), condition);
}
static public int jfind(List tok, List tokin) {
return jfind(tok, 1, tokin);
}
static public int jfind(List tok, int startIdx, List tokin) {
return jfind(tok, startIdx, tokin, null);
}
static public int jfind(List tok, int startIdx, String[] tokinC, Object condition) {
return findCodeTokens(tok, startIdx, false, tokinC, condition);
}
static public int jfind(List tok, int startIdx, List tokin, Object condition) {
return jfind(tok, startIdx, codeTokensAsStringArray(tokin), condition);
}
static public List jfind_preprocess(List tok) {
for (String type : litlist("quoted", "id", "int")) replaceSublist(tok, ll("<", "", type, "", ">"), ll("<" + type + ">"));
replaceSublist(tok, ll("\\", "", "*"), ll("\\*"));
return tok;
}
static public String tok_script_scanType(List tok, int iTypeStart) {
int iEndOfType = tok_script_findEndOfType(tok, iTypeStart);
return joinSubList_cToC(tok, iTypeStart, iEndOfType);
}
static public void replaceToken_reTok(List tok, int i, String t) {
tokSet_withReTok(tok, i, t);
}
static public String joinWithSpace(Iterable c) {
return join(" ", c);
}
static public String joinWithSpace(Object... c) {
return join(" ", c);
}
static public int javaTok_n, javaTok_elements;
static public boolean javaTok_opt = false;
static public List javaTok(String s) {
++javaTok_n;
ArrayList tok = new ArrayList();
int l = s == null ? 0 : s.length();
int i = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !regionMatches(s, j, "*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(javaTok_substringN(s, i, j));
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
int c2 = s.charAt(j);
if (c2 == opener || c2 == '\n' && opener == '\'') {
++j;
break;
} else if (c2 == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || s.charAt(j) == '\''));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j < l && !regionMatches(s, j, "]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !regionMatches(s, j, "]=]"));
j = Math.min(j + 3, l);
} else
++j;
tok.add(javaTok_substringC(s, i, j));
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
static public List javaTok(List tok) {
return javaTokWithExisting(join(tok), tok);
}
static public Map javaTokForJFind_array_cache = synchronizedMRUCache(1000);
static public String[] javaTokForJFind_array(String s) {
String[] tok = javaTokForJFind_array_cache.get(s);
if (tok == null)
javaTokForJFind_array_cache.put(s, tok = codeTokensAsStringArray(jfind_preprocess(javaTok(s))));
return tok;
}
static public int findCodeTokens(List tok, String... tokens) {
return findCodeTokens(tok, 1, false, tokens);
}
static public int findCodeTokens(List tok, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, 1, ignoreCase, tokens);
}
static public int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, startIdx, ignoreCase, tokens, null);
}
static public HashSet findCodeTokens_specials = lithashset("*", "", "", "", "\\*");
static public int findCodeTokens_bails, findCodeTokens_nonbails;
static public interface findCodeTokens_Matcher {
public boolean get(String token);
}
static public int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String[] tokens, Object condition) {
int end = tok.size() - tokens.length * 2 + 2, nTokens = tokens.length;
int i = startIdx | 1;
findCodeTokens_Matcher[] matchers = new findCodeTokens_Matcher[nTokens];
IContentsIndexedList2 indexedList = tok instanceof IContentsIndexedList2 ? (IContentsIndexedList2) tok : null;
TreeSet indices = null;
int indicesOfs = 0;
for (int j = 0; j < nTokens; j++) {
String p = tokens[j];
findCodeTokens_Matcher matcher;
if (p.equals("*"))
matcher = t -> true;
else if (p.equals(""))
matcher = t -> isQuoted(t);
else if (p.equals("