RFR: 7903788: preparation towards json configuration for jextract tool

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Aug 16 12:13:01 UTC 2024


On Fri, 16 Aug 2024 11:49:29 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:

> * adding json skara code into org.openjdk.jextract.json.parser package. Minor changes done - pretty printing, JSONValue is made sealed and access changes (private final fields).
> * org.openjdk.jextract.json package for JSON interface to the rest of the jextract tool. Main interface is org.openjdk.jextract.json.JSON. parse and toString methods to convert record into JSON String and vice versa.
> * Other classes are public mainly for testing purposes. build.gradle adjusted with the required --add-exports clauses so that jextract module does not have to export the new json packages.

src/main/java/org/openjdk/jextract/json/parser/JSONArray.java line 59:

> 57:     }
> 58: 
> 59:     public JSONArray set(int i, boolean value) {

Given we're not really planning to use this API directly, I think the setters are redundant. E.g. we should probably strive to build _immutable_ JSON nodes (and then map them back and forth into records). In this particular case, just copying the elements into an immutable list (`List::of`) will suffice - then we can drop all the setters. Probably similar simple changes in other classes will work too.

src/main/java/org/openjdk/jextract/json/parser/JSONNumber.java line 83:

> 81:     @Override
> 82:     public boolean equals(Object o) {
> 83:         if (this == o) {

tests like these can be written more succinctly as:

return this == o ||
           (o instanceof JSONNumber n) && value == n.value

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/257#discussion_r1719756551
PR Review Comment: https://git.openjdk.org/jextract/pull/257#discussion_r1719758121


More information about the jextract-dev mailing list