mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
8345773: Class-File API debug printing capability
Reviewed-by: liach, mcimadamore
This commit is contained in:
parent
e88e793cfd
commit
f88c1c6ff8
2 changed files with 15 additions and 4 deletions
|
@ -34,6 +34,8 @@ import java.util.function.Consumer;
|
|||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import jdk.internal.classfile.components.ClassPrinter;
|
||||
|
||||
/**
|
||||
* A {@link ClassFileElement} that has complex structure defined in terms of
|
||||
* other classfile elements, such as a method, field, method body, or entire
|
||||
|
@ -92,4 +94,14 @@ public sealed interface CompoundElement<E extends ClassFileElement>
|
|||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a text representation of the compound element and its contents for debugging purposes}
|
||||
*
|
||||
* The format, structure and exact contents of the returned string are not specified and may change at any time in the future.
|
||||
*/
|
||||
default String toDebugString() {
|
||||
StringBuilder text = new StringBuilder();
|
||||
ClassPrinter.toYaml(this, ClassPrinter.Verbosity.TRACE_ALL, text::append);
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8335927
|
||||
* @bug 8335927 8345773
|
||||
* @summary Testing ClassFile ClassPrinter.
|
||||
* @run junit ClassPrinterTest
|
||||
*/
|
||||
|
@ -122,8 +122,7 @@ class ClassPrinterTest {
|
|||
|
||||
@Test
|
||||
void testPrintYamlTraceAll() throws IOException {
|
||||
var out = new StringBuilder();
|
||||
ClassPrinter.toYaml(getClassModel(), ClassPrinter.Verbosity.TRACE_ALL, out::append);
|
||||
var out = getClassModel().toDebugString();
|
||||
assertOut(out,
|
||||
"""
|
||||
- class name: Foo
|
||||
|
@ -904,7 +903,7 @@ class ClassPrinterTest {
|
|||
assertEquals(node.walk().count(), 42);
|
||||
}
|
||||
|
||||
private static void assertOut(StringBuilder out, String expected) {
|
||||
private static void assertOut(CharSequence out, String expected) {
|
||||
// System.out.println("-----------------");
|
||||
// System.out.println(out.toString());
|
||||
// System.out.println("-----------------");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue