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 org.opendaylight.mdsal.binding.model.api.GeneratedType;
11 import org.opendaylight.mdsal.binding.model.api.Type;
12 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
13 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
14 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
15 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
19 * Generator corresponding to a {@code notification} statement.
21 final class NotificationGenerator extends AbstractCompositeGenerator<NotificationEffectiveStatement> {
22 NotificationGenerator(final NotificationEffectiveStatement statement, final AbstractCompositeGenerator<?> parent) {
23 super(statement, parent);
27 void pushToInference(final SchemaInferenceStack dataTree) {
28 dataTree.enterSchemaTree(statement().getIdentifier());
32 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
33 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
35 builder.addImplementsType(BindingTypes.DATA_OBJECT);
36 builder.addImplementsType(notificationType(builder, builderFactory));
38 addAugmentable(builder);
39 addUsesInterfaces(builder, builderFactory);
41 addConcreteInterfaceMethods(builder);
42 addGetterMethods(builder, builderFactory);
44 final ModuleGenerator module = currentModule();
45 module.addQNameConstant(builder, localName());
47 addCodegenInformation(module, statement(), builder);
48 annotateDeprecatedIfNecessary(builder);
50 return builder.build();
54 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
55 // Notifications are a distinct concept
58 private Type notificationType(final GeneratedTypeBuilder builder, final TypeBuilderFactory builderFactory) {
59 final AbstractCompositeGenerator<?> parent = getParent();
60 if (parent instanceof ModuleGenerator) {
61 return BindingTypes.NOTIFICATION;
64 final Type parentType = Type.of(parent.typeName());
65 if (parent instanceof ListGenerator) {
66 final KeyGenerator keyGen = ((ListGenerator) parent).keyGenerator();
68 return BindingTypes.keyedListNotification(builder, parentType, keyGen.getGeneratedType(builderFactory));
71 return BindingTypes.instanceNotification(builder, parentType);