X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fgenerator%2Fimpl%2Freactor%2FChoiceGenerator.java;h=1a6ac7fe5bc4146853c54ec5b0d8bebdf0e0b55f;hb=ecdcdb340457ded6898193197e88ea33c84d58ae;hp=c45a09985725ff61e8ca9da4f20ac7adc09e4e44;hpb=60039d4d027e172f6e1d644fb1c2fa60688c06c0;p=mdsal.git diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/ChoiceGenerator.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/ChoiceGenerator.java index c45a099857..1a6ac7fe5b 100644 --- a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/ChoiceGenerator.java +++ b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/ChoiceGenerator.java @@ -7,18 +7,27 @@ */ package org.opendaylight.mdsal.binding.generator.impl.reactor; +import com.google.common.collect.Iterables; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.mdsal.binding.generator.impl.rt.DerivedChoiceRuntimeType; +import org.opendaylight.mdsal.binding.generator.impl.rt.OriginalChoiceRuntimeType; import org.opendaylight.mdsal.binding.model.api.GeneratedType; import org.opendaylight.mdsal.binding.model.api.Type; import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.mdsal.binding.model.ri.BindingTypes; +import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType; +import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType; +import org.opendaylight.mdsal.binding.runtime.api.ChoiceRuntimeType; +import org.opendaylight.mdsal.binding.runtime.api.RuntimeType; import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; /** * Generator corresponding to a {@code choice} statement. */ -final class ChoiceGenerator extends CompositeSchemaTreeGenerator { - ChoiceGenerator(final ChoiceEffectiveStatement statement, final AbstractCompositeGenerator parent) { +final class ChoiceGenerator extends CompositeSchemaTreeGenerator { + ChoiceGenerator(final ChoiceEffectiveStatement statement, final AbstractCompositeGenerator parent) { super(statement, parent); } @@ -42,4 +51,40 @@ final class ChoiceGenerator extends CompositeSchemaTreeGenerator children, final List augments) { + final var original = getOriginal(); + if (!statement.equals(original.statement())) { + return new DerivedChoiceRuntimeType(type, statement, children, augments, + original.runtimeType().orElseThrow()); + } + + // Pick up any case statements added by augments which are not reflected in our children. This can happen when + // a choice is added via uses into two different places and then augmented. Since groupings are reused, validity + // of such use is not guarded by compile-time checks. + // + // Furthermore such case statements can be freely propagated via copy builders and thus can occur in unexpected + // places. If that happens, though, the two case statements can be equivalent, e.g. by having the exact same + // shape -- in which case Binding -> DOM translation needs to correct this mishap and play pretend the correct + // case was used. + final var augmentedCases = new ArrayList(); + for (var augment : original.augments()) { + for (var gen : augment) { + if (gen instanceof CaseGenerator) { + ((CaseGenerator) gen).runtimeType().ifPresent(augmented -> { + for (var child : Iterables.concat(children, augmentedCases)) { + if (child instanceof CaseRuntimeType && child.javaType().equals(augmented.javaType())) { + return; + } + } + augmentedCases.add(augmented); + }); + } + } + } + + return new OriginalChoiceRuntimeType(type, statement, children, augments, augmentedCases); + } }