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 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 javax.imageio.*;
import java.math.*;
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.text.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.NumberFormat;
import java.awt.datatransfer.StringSelection;
class main {
static class Bla {
String ok() { return "jaOK"; }
int yo(int x) { return x+5; }
String yo(String x) { return "ja" + x; }
String testMe(int x) { return "int"; }
}
static class DaStatic {
static String sOK() { return "sJaOK"; }
static int yo(int x) { return x+5; }
static String yo(String x) { return "ja" + x; }
}
public static void main(final String[] args) throws Exception { pExperiment();
for (int __twice = 0; __twice < 2; __twice++) {
assertEqualsVerbose("jaOK", call_cached(new Bla(), "ok"));
assertException(new Runnable() { public void run() { try { call_cached(new Bla(), "sOK") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(new Bla, \"sOK\")"; }});
assertEqualsVerbose(15, call_cached(new Bla(), "yo", 10));
assertEqualsVerbose("jaX", call_cached(new Bla(), "yo", "X"));
assertException(new Runnable() { public void run() { try { call_cached(new Bla(), "yoyo") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(new Bla, \"yoyo\")"; }});
assertException(new Runnable() { public void run() { try { call_cached(new Bla(), "yo", 5.0) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(new Bla, \"yo\", 5.0)"; }});
assertException(new Runnable() { public void run() { try { call_cached(Bla.class, "ok") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(Bla, \"ok\")"; }}); // non-static method
assertException(new Runnable() { public void run() { try { call_cached(new Bla(), "testMe", "test") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(new Bla, \"testMe\", \"test\")"; }});
assertException(new Runnable() { public void run() { try { call_cached(DaStatic.class, "ok") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(DaStatic, \"ok\")"; }});
assertEqualsVerbose("sJaOK", call_cached(DaStatic.class, "sOK"));
assertEqualsVerbose(15, call_cached(DaStatic.class, "yo", 10));
assertEqualsVerbose("jaX", call_cached(DaStatic.class, "yo", "X"));
assertException(new Runnable() { public void run() { try { call_cached(DaStatic.class, "yoyo") ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(DaStatic, \"yoyo\")"; }});
assertException(new Runnable() { public void run() { try { call_cached(DaStatic.class, "yo", 5.0) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "call_cached(DaStatic, \"yo\", 5.0)"; }});
}
}
static void pExperiment() {
if (!isMain()) return;
//substance();
autoRestart(5);
experimentIcon();
centerHigherConsole();
tt();
}
static A assertEqualsVerbose(Object x, A y) {
assertEqualsVerbose((String) null, x, y);
return y;
}
static A assertEqualsVerbose(String msg, Object x, A y) {
if (!eq(x, y)) {
throw fail((msg != null ? msg + ": " : "") + /*sfu*/(y) + " != " + /*sfu*/(x));
} else
print("OK: " + /*sfu*/(x));
return y;
}
static Object call_cached(Object o, String method, Object... args) { try {
if (o == null) return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
// TODO: (super-rare) case where method exists static and non-static
// with different args
Method me = cache.findMethod(method, args);
if (me == null)
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
if ((me.getModifiers() & Modifier.STATIC) == 0)
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not static");
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me == null)
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
return invokeMethod(me, o, args);
}
} catch (Exception __e) { throw rethrow(__e); } }
static void assertException(Runnable r) {
assertFail(r);
}
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static final Map callOpt_cache = newDangerousWeakHashMap();
static Object callOpt_cached(Object o, String methodName, Object... args) { try {
if (o == null) return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
// TODO: (super-rare) case where method exists static and non-static
// with different args
Method me = cache.findMethod(methodName, args);
if (me == null || (me.getModifiers() & Modifier.STATIC) == 0) return null;
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null) return null;
return invokeMethod(me, o, args);
}
} catch (Exception __e) { throw rethrow(__e); } }
static _MethodCache callOpt_getCache(Class c) {
synchronized(callOpt_cache) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
}
static boolean isMain() {
return isMainProgram();
}
static double autoRestart_interval = 10;
static boolean autoRestart_on, autoRestart_debug, autoRestart_simulate;
static java.util.Timer autoRestart_timer;
static void autoRestart(double interval) {
autoRestart_interval = interval;
autoRestart();
}
static void autoRestart() {
if (!isMain() || autoRestart_on) return;
autoRestart_on = true;
autoRestart_schedule();
preloadProgramTitle();
}
static void autoRestart_off() {
if (!autoRestart_on) return;
stopTimer(autoRestart_timer);
autoRestart_timer = null;
}
static void autoRestart_schedule() {
autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), "autoRestart_check");
}
static void autoRestart_check() {
try {
String newMD5;
try {
newMD5 = serverAutoRestartMD5(programID());
} catch (Throwable e) {
return;
}
if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); return; }
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
String localMD5 = autoRestart_localMD5();
if (neq(localMD5, newMD5)) {
if (autoRestart_simulate)
print("Would upgrade now. " + localMD5 + " -> " + newMD5);
else {
infoBox("Upgrading " + programTitle());
restartWithDelay(500);
sleep();
}
}
} finally {
if (autoRestart_debug) print("autoRestart: Done");
autoRestart_schedule();
}
}
static void experimentIcon() {
consoleAndDefaultFrameIcon("#1101173" /*#1101171*/);
}
static void centerHigherConsole() {
if (headless()) return;
setConsoleHeight(600);
centerConsole();
}
static void tt() {
typeWriterConsole();
}
static String tt(Object contents, Object... params) {
return tag("tt", contents, params);
}
static boolean eq(Object a, Object b) {
return a == null ? b == null : a == b || a.equals(b);
}
static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); }
static RuntimeException fail(String msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(String msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
//static int print_maxLineLength = 0; // 0 = unset
static boolean print_silent; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal