下面列出了java.lang.StackWalker.StackFrame#getClassName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static boolean isFilteredFrame(StackFrame st) {
// skip logging/logger infrastructure
if (System.Logger.class.isAssignableFrom(st.getDeclaringClass())) {
return true;
}
// fast escape path: all the prefixes below start with 's' or 'j' and
// have more than 12 characters.
final String cname = st.getClassName();
char c = cname.length() < 12 ? 0 : cname.charAt(0);
if (c == 's') {
// skip internal machinery classes
if (cname.startsWith("sun.util.logging.")) return true;
if (cname.startsWith("sun.rmi.runtime.Log")) return true;
} else if (c == 'j') {
// Message delayed at Bootstrap: no need to go further up.
if (cname.startsWith("jdk.internal.logger.BootstrapLogger$LogEvent")) return false;
// skip public machinery classes
if (cname.startsWith("jdk.internal.logger.")) return true;
if (cname.startsWith("java.util.logging.")) return true;
if (cname.startsWith("java.lang.invoke.MethodHandle")) return true;
if (cname.startsWith("java.security.AccessController")) return true;
}
// check additional prefixes if any are specified.
if (skips.length > 0) {
for (int i=0; i<skips.length; i++) {
if (!skips[i].isEmpty() && cname.startsWith(skips[i])) {
return true;
}
}
}
return false;
}
static boolean isFilteredFrame(StackFrame st) {
// skip logging/logger infrastructure
if (System.Logger.class.isAssignableFrom(st.getDeclaringClass())) {
return true;
}
// fast escape path: all the prefixes below start with 's' or 'j' and
// have more than 12 characters.
final String cname = st.getClassName();
char c = cname.length() < 12 ? 0 : cname.charAt(0);
if (c == 's') {
// skip internal machinery classes
if (cname.startsWith("sun.util.logging.")) return true;
if (cname.startsWith("sun.rmi.runtime.Log")) return true;
} else if (c == 'j') {
// Message delayed at Bootstrap: no need to go further up.
if (cname.startsWith("jdk.internal.logger.BootstrapLogger$LogEvent")) return false;
// skip public machinery classes
if (cname.startsWith("jdk.internal.logger.")) return true;
if (cname.startsWith("java.util.logging.")) return true;
if (cname.startsWith("java.lang.invoke.MethodHandle")) return true;
if (cname.startsWith("java.security.AccessController")) return true;
}
// check additional prefixes if any are specified.
if (skips.length > 0) {
for (int i=0; i<skips.length; i++) {
if (!skips[i].isEmpty() && cname.startsWith(skips[i])) {
return true;
}
}
}
return false;
}
void checkFrame(StackFrame frame) {
String cn = frame.getClassName();
if (cn.startsWith("java.lang.reflect.") || cn.startsWith("jdk.internal.reflect.")) {
reflects.add(frame);
}
if (cn.contains("$$Lambda$")) {
lambdas.add(frame);
}
}
public String frame(StackFrame f) {
return f.getClassName() + "::" + f.getMethodName();
}
/**
* Compare the given StackFrame returned from the StackWalker to the
* recorded frame at the given index.
*
* Tests for equality, as well as functional correctness with respect to
* the StackWalker's options (e.g. throws or doesn't throw exceptions)
*/
public void compareFrame(int index, StackFrame sf) {
TestFrame tf = testFrames.get(index);
if (compareClasses) {
if (!tf.declaringClass.equals(sf.getDeclaringClass())) {
throw new RuntimeException("Expected class: " +
tf.declaringClass.toString() + ", but got: " +
sf.getDeclaringClass().toString());
}
} else {
boolean caught = false;
try {
sf.getDeclaringClass();
} catch (UnsupportedOperationException e) {
caught = true;
}
if (!caught) {
throw new RuntimeException("StackWalker did not have " +
"RETAIN_CLASS_REFERENCE Option, but did not throw " +
"UnsupportedOperationException");
}
}
if (compareClassNames && !tf.className().equals(sf.getClassName())) {
throw new RuntimeException("Expected class name: " + tf.className() +
", but got: " + sf.getClassName());
}
if (compareMethodNames && !tf.methodName.equals(sf.getMethodName())) {
throw new RuntimeException("Expected method name: " + tf.methodName +
", but got: " + sf.getMethodName());
}
if (compareSTEs) {
StackTraceElement ste = sf.toStackTraceElement();
if (!(ste.getClassName().equals(tf.className()) &&
ste.getMethodName().equals(tf.methodName)) &&
ste.getFileName().equals(tf.fileName)) {
throw new RuntimeException("Expected StackTraceElement info: " +
tf + ", but got: " + ste);
}
if (!Objects.equals(ste.getClassName(), sf.getClassName())
|| !Objects.equals(ste.getMethodName(), sf.getMethodName())
|| !Objects.equals(ste.getFileName(), sf.getFileName())
|| !Objects.equals(ste.getLineNumber(), sf.getLineNumber())
|| !Objects.equals(ste.isNativeMethod(), sf.isNativeMethod())) {
throw new RuntimeException("StackFrame and StackTraceElement differ: " +
"sf=" + sf + ", ste=" + ste);
}
}
}
public String frame(StackFrame f) {
return f.getClassName() + "::" + f.getMethodName();
}
private static boolean isExitStackFrame(StackFrame f) {
final String methodName = f.getMethodName(), className = f.getClassName();
return ("exit".equals(methodName) || "halt".equals(methodName)) &&
(SYSTEM_CLASS_NAME.equals(className) || RUNTIME_CLASS_NAME.equals(className));
}