If you don't need to turn on/off assertions, you can easily insert by
insertAfter("if (expr) throw new AssertionError();")
This is equivalent to:
If you want to turn on/off by the -ea option, you have to also insert
the code for checking whether or not the assertion is effective
throw new AssertionError();
Thanks you very much !
One more thing.
Calling Foo.class.desiredAssertionStatus() would take time.
The bytecode generated by javac calls this method in a
static initializer and the result is cached in a private static