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.model.api.stmt.NotificationEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
24 * Generator corresponding to a {@code notification} statement.
26 final class NotificationGenerator
27 extends CompositeSchemaTreeGenerator<NotificationEffectiveStatement, NotificationRuntimeType> {
28 NotificationGenerator(final NotificationEffectiveStatement statement,
29 final AbstractCompositeGenerator<?, ?> parent) {
30 super(statement, parent);
34 void pushToInference(final SchemaInferenceStack dataTree) {
35 dataTree.enterSchemaTree(statement().getIdentifier());
39 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
40 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
42 builder.addImplementsType(BindingTypes.DATA_OBJECT);
43 builder.addImplementsType(notificationType(builder, builderFactory));
45 addAugmentable(builder);
46 addUsesInterfaces(builder, builderFactory);
48 addConcreteInterfaceMethods(builder);
49 addGetterMethods(builder, builderFactory);
51 final ModuleGenerator module = currentModule();
52 module.addQNameConstant(builder, localName());
54 builderFactory.addCodegenInformation(module, statement(), builder);
55 annotateDeprecatedIfNecessary(builder);
57 return builder.build();
61 NotificationRuntimeType createRuntimeType(final GeneratedType type, final NotificationEffectiveStatement statement,
62 final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
63 return new DefaultNotificationRuntimeType(type, statement, children, augments);
67 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
68 // Notifications are a distinct concept
71 private Type notificationType(final GeneratedTypeBuilder builder, final TypeBuilderFactory builderFactory) {
72 final AbstractCompositeGenerator<?, ?> parent = getParent();
73 if (parent instanceof ModuleGenerator) {
74 return BindingTypes.notification(builder);
77 final Type parentType = Type.of(parent.typeName());
78 if (parent instanceof ListGenerator) {
79 final KeyGenerator keyGen = ((ListGenerator) parent).keyGenerator();
81 return BindingTypes.keyedListNotification(builder, parentType, keyGen.getGeneratedType(builderFactory));
84 return BindingTypes.instanceNotification(builder, parentType);