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 java.util.List;
11 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultNotificationRuntimeType;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.Type;
14 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
15 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
16 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
17 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.NotificationRuntimeType;
19 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
20 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
21 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
25 * Generator corresponding to a {@code notification} statement.
27 final class NotificationGenerator
28 extends CompositeSchemaTreeGenerator<NotificationEffectiveStatement, NotificationRuntimeType> {
29 NotificationGenerator(final NotificationEffectiveStatement statement,
30 final AbstractCompositeGenerator<?, ?> parent) {
31 super(statement, parent);
35 StatementNamespace namespace() {
36 return StatementNamespace.NOTIFICATION;
40 void pushToInference(final SchemaInferenceStack dataTree) {
41 dataTree.enterSchemaTree(statement().argument());
45 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
46 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
48 builder.addImplementsType(BindingTypes.DATA_OBJECT);
49 builder.addImplementsType(notificationType(builder, builderFactory));
51 addAugmentable(builder);
52 addUsesInterfaces(builder, builderFactory);
54 addConcreteInterfaceMethods(builder);
55 addGetterMethods(builder, builderFactory);
57 final ModuleGenerator module = currentModule();
58 module.addQNameConstant(builder, localName());
60 builderFactory.addCodegenInformation(module, statement(), builder);
61 annotateDeprecatedIfNecessary(builder);
63 return builder.build();
67 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
68 // Notifications are a distinct concept
72 CompositeRuntimeTypeBuilder<NotificationEffectiveStatement, NotificationRuntimeType> createBuilder(
73 final NotificationEffectiveStatement statement) {
74 return new CompositeRuntimeTypeBuilder<>(statement) {
76 NotificationRuntimeType build(final GeneratedType type, final NotificationEffectiveStatement statement,
77 final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
78 return new DefaultNotificationRuntimeType(type, statement, children, augments);
83 private Type notificationType(final GeneratedTypeBuilder builder, final TypeBuilderFactory builderFactory) {
84 final AbstractCompositeGenerator<?, ?> parent = getParent();
85 if (parent instanceof ModuleGenerator) {
86 return BindingTypes.notification(builder);
89 final Type parentType = Type.of(parent.typeName());
90 if (parent instanceof ListGenerator listGen) {
91 final KeyGenerator keyGen = listGen.keyGenerator();
93 return BindingTypes.keyedListNotification(builder, parentType, keyGen.getGeneratedType(builderFactory));
96 return BindingTypes.instanceNotification(builder, parentType);