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