[External] : Re: Classfile API proposal to integrate basic print functionality directly to ClassModel and MethodModel

Michael van Acken michael.van.acken at gmail.com
Wed Jul 27 19:22:32 UTC 2022


Am Mi., 27. Juli 2022 um 16:00 Uhr schrieb Michael van Acken <
michael.van.acken at gmail.com>:

> Am Mi., 27. Juli 2022 um 12:04 Uhr schrieb Adam Sotona <
> adam.sotona at oracle.com>:
>
>> Unfortunately, “Prettyprinting” can be reduced to indentation and new
>> lines only for XML and JSON, however YAML offers much more dynamic
>> formatting.
>>
>
> I have to admit that I never used YAML syntax in any form.  Looking at the
> Wikipedia page, it seems like YAML's optional "inline-style" corresponds
> to the "single-line formatting" style of the prettyprinter approach, and
> its
> indented multi-line blocks to multi-line formatting.  In this case, the
> width
> information passed up the tree would represent the "inline-style" width.
>
> I would not rule out that it can be made to work.  I agree with you that it
> would entail more than just moving strings around, because printing
> of lists and maps would have two distinct output modes.  But it may
> be possible to move the decision which mode to use out of the data
> model.
>

Curiosity got the better of me and I tried to put together a proof of
concept.
I used sample.json as input and generated two attempts at YAML, one
formatted to a page width of 80 and another one to a width of 40.
The diff between sample.yaml and output_pp80.yaml is attached, not sure
if it is still a valid representation with its three indented inline maps.

Someone who understands YAML should be able to do a better job
than this.  I'm not sure I got the interaction between list, map, and
map entry entirely correct.

The code is on github at https://github.com/mva/eval-pp

-- mva



--- sample.yaml 2022-07-27 20:43:42.795748163 +0200
+++ output_pp80.yaml 2022-07-27 21:04:23.923566743 +0200
@@ -37,11 +37,13 @@
             max locals: 3
             attributes: [StackMapTable]
             stack map frames:
-                '@6': {locals: [Foo, int, java/lang/Throwable], stack: []}
-            //stack map frame @0: {locals: [Foo, int,
java/lang/Throwable], stack: []}
+                {'@6': {locals: [Foo, int, java/lang/Throwable], stack:
[]}}
+            //stack map frame @0:
+                {locals: [Foo, int, java/lang/Throwable], stack: []}
             0: [ILOAD_1, {slot: 1}]
             1: [IFEQ, {target: 6}]
             4: [ALOAD_2, {slot: 2}]
             5: [ATHROW]
-            //stack map frame @6: {locals: [Foo, int,
java/lang/Throwable], stack: []}
+            //stack map frame @6:
+                {locals: [Foo, int, java/lang/Throwable], stack: []}
             6: [RETURN]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220727/1c9b20f0/attachment.htm>


More information about the classfile-api-dev mailing list