if (!f.getMethodType().equals(type)) { thrownew RuntimeException("Expected: " + type
+ " got: " + f.getMethodType());
}
// verify descriptor returned by getDescriptor() before and after // getMethodType() is called if (!descriptor.equals(f.getDescriptor())) { thrownew RuntimeException("Mismatched: " + descriptor
+ " got: " + f.getDescriptor());
}
}
}
}
staticclass ConstructorNewInstance { staticfinal StackWalker walker =
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
List<String> testFramesOrReflectionFrames; public ConstructorNewInstance() {
testFramesOrReflectionFrames = walker.walk(this::parse);
} public List<String> collectedFrames() { return testFramesOrReflectionFrames;
} publicboolean accept(StackFrame f) { // Frames whose class names don't contain "." // are our own test frames. These are the ones // we expect. // Frames whose class names contain ".reflect." // are reflection frames. None should be present, // since they are supposed to be filtered by // by StackWalker. If we find any, we want to fail. if (!f.getClassName().contains(".")
|| f.getClassName().contains(".reflect.")) {
System.out.println(" " + f); returntrue;
} // Filter out all other frames (in particular // those from the test framework) in order to // have predictable results. returnfalse;
} public String frame(StackFrame f) { return f.getClassName() + "::" + f.getMethodName();
}
List<String> parse(Stream<StackFrame> s) { return s.filter(this::accept)
.map(this::frame)
.collect(Collectors.toList());
} publicstatic ConstructorNewInstance create() throws Exception { return ConstructorNewInstance.class.getConstructor().newInstance();
}
}
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.