2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.generator.impl.reactor;
10 import static com.google.common.base.Verify.verify;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
14 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
15 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
19 * Generator corresponding to a {@code case} statement.
21 final class CaseGenerator extends CompositeSchemaTreeGenerator<CaseEffectiveStatement, CaseGenerator> {
22 CaseGenerator(final CaseEffectiveStatement statement, final AbstractCompositeGenerator<?> parent) {
23 super(statement, parent);
27 void pushToInference(final SchemaInferenceStack dataTree) {
32 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
33 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
34 builder.addImplementsType(BindingTypes.DATA_OBJECT);
36 // We also are implementing target choice's type. This is tricky, as we need to cover two distinct cases:
37 // - being a child of a choice (i.e. normal definition)
38 // - being a child of an augment (i.e. augmented into a choice)
39 final AbstractCompositeGenerator<?> parent = getParent();
40 final ChoiceGenerator choice;
41 if (parent instanceof AbstractAugmentGenerator) {
42 final AbstractCompositeGenerator<?> target = ((AbstractAugmentGenerator) parent).targetGenerator();
43 verify(target instanceof ChoiceGenerator, "Unexpected parent augment %s target %s", parent, target);
44 choice = (ChoiceGenerator) target;
46 verify(parent instanceof ChoiceGenerator, "Unexpected parent %s", parent);
47 choice = (ChoiceGenerator) parent;
50 // Most generators have a parent->child dependency due to parent methods' return types and therefore children
51 // must not request parent's type. That is not true for choice->case relationship and hence we do not need to
52 // go through DefaultType here.
53 builder.addImplementsType(choice.getGeneratedType(builderFactory));
54 addAugmentable(builder);
55 addUsesInterfaces(builder, builderFactory);
56 addConcreteInterfaceMethods(builder);
58 final ModuleGenerator module = currentModule();
59 module.addQNameConstant(builder, localName());
61 addGetterMethods(builder, builderFactory);
63 annotateDeprecatedIfNecessary(builder);
64 builderFactory.addCodegenInformation(module, statement(), builder);
65 builder.setModuleName(module.statement().argument().getLocalName());
67 return builder.build();