Classfile API proposal to integrate basic print functionality directly to ClassModel and MethodModel

Adam Sotona adam.sotona at oracle.com
Mon Jul 25 17:03:12 UTC 2022


Unfortunately it is format-specific.
We can unify it down to “all-quoted” however the visual benefits will be lost.


On 25.07.2022 19:00, "Brian Goetz" <brian.goetz at oracle.com> wrote:

This seems like nice progress.  I wonder if we can boil it down further?  Can we, for example, get rid of Quoted by Plain(key, "\"value\""), and such?


On 7/25/2022 12:40 PM, Adam Sotona wrote:
During the experiments I found generic map-of-maps is too loose and missing any formatting information.
The API below has been derived from the requirements of the actual ClassPrinter and made as a minimal set of formatting features unified for producing JSON, YAML and XML.
The API also tries to avoid problematic combinations (for example list of lists is not possible, but list of maps of lists works perfectly).
Each Classfile API model can provide its printable form in the future.
Printers implementations are generic and very simple (~80 lines of code each, mainly one big switch expression) and custom printers can be implemented.

Please let me know your comments before I start rewriting the ClassPrinter into this intermediate form.

Thanks,
Adam


Here is an example of small API to specify printable fragments:

 public sealed interface Printable {

    public String key();

    public sealed interface Fragment extends Printable {}

    public record Plain(String key, String value) implements Fragment {}

    public record Quoted(String key, String value) implements Fragment {}

    public record Decimal(String key, int value) implements Fragment {}

    public record PlainList(String key, List<String> values) implements Fragment {}

    public record QuotedList(String key, List<String> values) implements Fragment {}

    public record Mapping(String key, List<Fragment> fragments) implements Printable {}

    public record BlockMapping(String key,  List<Printable> printables) implements Printable {}

    public record BlockList(String key,  List<BlockMapping> blockMappings) implements Printable {}

    public record Comment(String key) implements Printable {}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220725/b4188e2b/attachment-0001.htm>


More information about the classfile-api-dev mailing list