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 java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultChoiceRuntimeType;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
16 import org.opendaylight.mdsal.binding.model.api.Type;
17 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
18 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
19 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
20 import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
21 import org.opendaylight.mdsal.binding.runtime.api.ChoiceRuntimeType;
22 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
28 * Generator corresponding to a {@code choice} statement.
30 final class ChoiceGenerator extends CompositeSchemaTreeGenerator<ChoiceEffectiveStatement, ChoiceRuntimeType> {
31 static final class ChoiceBuilder extends CompositeRuntimeTypeBuilder<ChoiceEffectiveStatement, ChoiceRuntimeType> {
32 private final List<CaseRuntimeType> augmentedCases = new ArrayList<>();
34 ChoiceBuilder(final ChoiceEffectiveStatement statement) {
39 void processAugment(final AugmentResolver resolver, final AbstractAugmentGenerator augment) {
40 augment.fillRuntimeCasesIn(resolver, statement(), augmentedCases);
44 boolean isAugmentedChild(final QName qname) {
45 for (var augmented : augmentedCases) {
46 if (qname.equals(augmented.statement().argument())) {
54 ChoiceRuntimeType build(final GeneratedType type, final ChoiceEffectiveStatement statement,
55 final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
56 verify(augments.isEmpty(), "Unexpected augments %s", augments);
57 children.addAll(augmentedCases);
58 return new DefaultChoiceRuntimeType(type, statement, children);
62 ChoiceGenerator(final ChoiceEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
63 super(statement, parent);
67 StatementNamespace namespace() {
68 return StatementNamespace.CHOICE;
72 void pushToInference(final SchemaInferenceStack dataTree) {
77 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
78 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
79 builder.addImplementsType(BindingTypes.choiceIn(Type.of(getParent().typeName())));
81 final ModuleGenerator module = currentModule();
82 module.addQNameConstant(builder, localName());
84 annotateDeprecatedIfNecessary(builder);
85 builderFactory.addCodegenInformation(module, statement(), builder);
86 // newType.setSchemaPath(schemaNode.getPath());
87 builder.setModuleName(module.statement().argument().getLocalName());
89 return builder.build();
93 ChoiceBuilder createBuilder(final ChoiceEffectiveStatement statement) {
94 return new ChoiceBuilder(statement);