/* * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
void printVariable(LocalVariable lv, int index) throws Exception { if (lv == null) {
println(" Var name: null"); return;
}
String tyname = lv.typeName();
println(" Var: " + lv.name() + ", index: " + index + ", type: " + tyname + ", Signature: " + lv.type().signature()); // Sorry, there is no way to take local variable slot numbers using JDI! // It is because method LocalVariableImpl.slot() is private.
}
void compareTwoEqualVars(LocalVariable lv1, LocalVariable lv2) { if (lv1.equals(lv2)) {
println(" Success: equality of local vars detected");
} else {
failure(" Failure: equality of local vars is NOT detected");
} if (lv1.hashCode() == lv2.hashCode()) {
println(" Success: hashCode's of equal local vars are equal");
} else {
failure(" Failure: hashCode's of equal local vars differ");
} if (lv1.compareTo(lv2) == 0) {
println(" Success: compareTo() is correct for equal local vars");
} else {
failure(" Failure: compareTo() is NOT correct for equal local vars");
}
}
void compareTwoDifferentVars(LocalVariable lv1, LocalVariable lv2) { if (!lv1.equals(lv2)) {
println(" Success: difference of local vars detected");
} else {
failure(" Failure: difference of local vars is NOT detected");
} if (lv1.hashCode() != lv2.hashCode()) {
println(" Success: hashCode's of different local vars differ");
} else {
failure(" Failure: hashCode's of different local vars are equal");
} if (lv1.compareTo(lv2) != 0) {
println(" Success: compareTo() is correct for different local vars");
} else {
failure(" Failure: compareTo() is NOT correct for different local vars");
}
}
void compareAllVariables(String className, String methodName) throws Exception {
println("compareAllVariables for method: " + className + "." + methodName);
Method method = getMethod(className, methodName);
List localVars; try {
localVars = method.variables();
println("\n Success: got a list of all method variables: " + methodName);
} catch (com.sun.jdi.AbsentInformationException ex) {
failure("\n AbsentInformationException has been thrown"); return;
}
// We consider N*N combinations for set of N variables int index1 = 0; for (Iterator it1 = localVars.iterator(); it1.hasNext(); index1++) {
LocalVariable lv1 = (LocalVariable) it1.next();
int index2 = 0; for (Iterator it2 = localVars.iterator(); it2.hasNext(); index2++) {
LocalVariable lv2 = (LocalVariable) it2.next();
/* * Get to the top of main() to determine targetClass and mainThread
*/
BreakpointEvent bpe = startToMain("LocalVariableEqualTarg");
println("startToMain(LocalVariableEqualTarg)");
/* * resume until the end
*/
listenUntilVMDisconnect();
/* * deal with results of test * if anything has called failure("foo") testFailed will be true
*/ if (!testFailed) {
println("\nLocalVariableEqual: passed");
} else { thrownew Exception("\nLocalVariableEqual: FAILED");
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
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.