[MDSAL-745] Fix bits mapping string/getDefaultInstance mapping Created: 11/Apr/22  Updated: 30/Jan/24

Status: In Review
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 14.0.0, 13.0.1

Type: Bug Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Unresolved Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Blocks
is blocked by MDSAL-743 Add BitsTypeObject Resolved
Epic Link: Evolve bits mapping

 Description   

Bits type mapping is completely nonsensical where String mapping is concerned. On the one hand we have:

    @Override
    public String toString() {
        final var helper = MoreObjects.toStringHelper(Foo.class);
        CodeHelpers.appendValue(helper, "_one", _one);
        CodeHelpers.appendValue(helper, "_bar", _bar);
        return helper.toString();
    }

and on the other hand we only have:

    public static Foo getDefaultInstance(final String defaultValue) {
        List<String> properties = Lists.newArrayList("bar",
        "one"
        );
        if (!properties.contains(defaultValue)) {
            throw new IllegalArgumentException("invalid default parameter");
        }
        int i = 0;
        return new Foo(
        properties.get(i++).equals(defaultValue) ? Boolean.TRUE : null,
        properties.get(i++).equals(defaultValue) ? Boolean.TRUE : null
        );
    }

i.e. there is method producing the output 'getDefaultInstance' expects. Furthermore the only it works is single-bits – otherwise 'defaultValue' is just not included in the List and there is just now way to specify more than one bit that would get accepted by getDefaultInstance().

Replace 'getDefaultInstance(String)' with a valueOf(String) method which will accept a comma-separated list of Strings identifying individual bits. This is guaranteed to be okay because of how bit argument is defined which in turn goes to identifier, which in turn goes into ABNF, which does not allow for commas.

Also define a counterpart stringValue() matching the formatting, which is part of (the proposed) BitsTypeObjectContract. The contract here is that the output of stringValue() is accepted by ofValue(String).

Both of these methods need to be specified by BitsTypeObject.


Generated at Wed Feb 07 20:10:50 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.