publicstaticvoid main(String[] args){
RedefineSubTarg sub = new RedefineSubTarg();
String where = ""; for (int i = 0; i < 5; ++i) {
where = sub.foo(where);
show(where);
}
lastly(where);
}
}
/********** test program **********/
publicclass RedefineTest extends TestScaffold {
ReferenceType targetClass; staticfinal String expected ="Boring Boring Different Boring Different "; int repetitionCount = 0; boolean beforeRedefine = true;
RedefineTest (String args[]) { super(args);
}
publicstaticvoid main(String[] args) throws Exception { new RedefineTest(args).startTests();
}
void expectNonObsolete(ThreadReference thread) throws Exception { if (isObsolete(thread)) {
failure("FAIL: Method should NOT be obsolete");
} else {
println("as it should be, not obsolete");
}
}
void expectObsolete(ThreadReference thread) throws Exception { if (isObsolete(thread)) {
println("obsolete like it should be");
} else {
failure("FAIL: Method should be obsolete");
}
}
void inspectLineNumber(LocatableEvent event, StackFrame frame) throws Exception { /* *ForeachvalueofrepetitionCount,usethebeforeRedefine *booleantodistinguishthetimebeforeandaftertheactual *redefinitiontakesplace.Linenumbersareinspectedboth *beforeandaftereachredefine.
*/ int n = -1; int expectedLine = -1; switch (repetitionCount) { case1:
expectedLine = 4; break; case2:
expectedLine = beforeRedefine ? 4:21; break; case3:
expectedLine = beforeRedefine ? 21:4; break; case4:
expectedLine = beforeRedefine ? 4:21; break; case5: /* The class won't be redefined on this iteration (look *forajava.lang.UnsupportedOperationExceptioninstead) *soexpectedlinestaysthesameaslastsuccessful *redefine.
*/
expectedLine = 21; break;
}
Method method = event.location().method(); if (frame.location().method().isObsolete()) { /* *Thenskip.Obsoletemethodsarenotinterestingto *inspect.
*/
println("inspectLineNumber skipping obsolete method " + method.name());
} else {
n = method.location().lineNumber(); int m = frame.location().lineNumber(); if ((n != expectedLine) || (n != m)) {
failure("Test Failure: line number disagreement: " +
n + " (event) versus " + m + " (frame) versus " + expectedLine + " (expected)");
} else {
println("inspectLineNumber in method " + method.name() + " at line " + n);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.