[MDSAL-198] Augmentable's Builder addAugmentation variant without first class argument Created: 16/Sep/16  Updated: 19/Jul/20  Resolved: 21/Apr/20

Status: Resolved
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 6.0.0

Type: Improvement Priority: Lowest
Reporter: Michael Vorburger Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All
URL: https://git.opendaylight.org/gerrit/#/c/45742/


Issue Links:
Issue split
split to MDSAL-575 Remove compatibility Builder.addAugme... Resolved

 Description   

It would be "nice" (this is an Enhancement, not a Bug) if an Augmentable DataObject would have an alternative sugar shortcut new addAugmentation method variant which does not require the first (java.lang.Class<? extends Augmentation<...>> augmentationType but only the second Augmentation<...> augmentation argument.

This would just shorten the typical and often found code which IMHO is a little a silly, where the interface of an augmentation has to be specified together with creating ("can't it figure this out by itself??" - kind of thing).



 Comments   
Comment by Michael Vorburger [ 16/Sep/16 ]

If only Augmentation had a getImplementedInterface() method just like DataContainer does, then it would seem totally feasible to generate convenience shortcut methods like this in *Builder classes:

public *Builder addAugmentation(Augmentation<...> augmentation) {
this.addAugmentation(augmentation.getImplementedInterface(), augmentation);

but of course Augmentation does not have getImplementedInterface() - yet. I could see following possible solutions:

1. In reality, one can see that all gen. YANG augmentations interfaces always extend both DataObject and Augmentation. So initially I was tempted to propose that Augmentation simply extend DataObject or DataContainer .. but rovarga when asked on IRC if it "would it be conceivable to make Augmentation extend DataContainer" on IRC clarified that "not sure, probably that's not what we want to do... pretty sure it's not – due to InstanceIdentifier type safety – cannot start with an Augmentation".

2. We could attempt to factor out the getImplementedInterface() method currently declared on DataContainer into some new interface, and have both DataContainer and Augmentation extend that. I've tried that, and it lead to a frightening encounter with Java Generics Hell, so unless someone smarter sees a way of doing this that I missed, I don't think this is feasible (because getImplementedInterface() in DataContainer returns, rightfully Class<? extends DataContainer>, and Augmentation's getImplementedInterface() would have to return Class<? extends Augmentation> but that will, correctly, lead to type conflict on YANG augmentations interfaces always extend both DataObject and Augmentation.

3. Just let Augmentation have its own getImplementedAugmentationInterface() method, LIKE DataContainer, but without any code sharing and inheritance (that's probably never needed; because the "clients" using this always know whether they're dealing with an Augmentation or a DataContainer)

Comment by Michael Vorburger [ 16/Sep/16 ]

https://git.opendaylight.org/gerrit/#/c/45742/ proposes implementation of approach 3.

Comment by Martin Ciglan [ 17/Oct/16 ]

Hi

is this still in progress? Please update. Many thanks.

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