Classfile API proposal to integrate basic print functionality directly to ClassModel and MethodModel
Adam Sotona
adam.sotona at oracle.com
Mon Jul 25 17:20:02 UTC 2022
Or maybe we could let the printer to auto-quote as needed by the actual value in the context of the actual format 😊
So yes, it can be reduced:
public sealed interface Printable {
public String key();
public sealed interface Fragment extends Printable {}
public record Value(String key, String ConstantDesc value) implements Fragment {}
public record Quoted(String key, String value) implements Fragment {}
public record Decimal(String key, int value) implements Fragment {}
public record ValueList(String key, List<String ConstantDesc> 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 {}
On 25.07.2022 19:03, "classfile-api-dev" <classfile-api-dev-retn at openjdk.org> wrote:
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220725/0325e9b7/attachment-0001.htm>
More information about the classfile-api-dev
mailing list