8345773: Class-File API debug printing capability

Reviewed-by: liach, mcimadamore
This commit is contained in:
Adam Sotona 2024-12-11 07:58:26 +00:00
parent e88e793cfd
commit f88c1c6ff8
2 changed files with 15 additions and 4 deletions

View file

@ -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();
}
}