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;
11 import static java.util.Objects.requireNonNull;
13 import java.util.List;
14 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
16 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
17 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
18 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
19 import org.opendaylight.mdsal.binding.model.ri.Types;
20 import org.opendaylight.yangtools.yang.binding.contract.Naming;
21 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
26 * Aggregate service for top-level {@code notification} statements for a particular module. It does not handle nested
27 * (YANG 1.1) notifications.
29 // FIXME: MDSAL-497: remove this generator
30 final class NotificationServiceGenerator extends AbstractImplicitGenerator {
31 private final List<NotificationGenerator> notifs;
33 NotificationServiceGenerator(final ModuleGenerator parent, final List<NotificationGenerator> notifs) {
35 this.notifs = requireNonNull(notifs);
39 StatementNamespace namespace() {
40 return StatementNamespace.NOTIFICATION_LISTENER;
44 String classSuffix() {
45 return Naming.NOTIFICATION_LISTENER_SUFFIX;
49 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
50 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
51 builder.addImplementsType(BindingTypes.NOTIFICATION_LISTENER)
52 .addAnnotation(DEPRECATED_ANNOTATION);
54 for (NotificationGenerator gen : notifs) {
55 final MethodSignatureBuilder notificationMethod = builder.addMethod("on" + gen.assignedName())
56 .setAccessModifier(AccessModifier.PUBLIC)
57 .addParameter(gen.getGeneratedType(builderFactory), "notification")
58 .setReturnType(Types.primitiveVoidType());
60 final NotificationEffectiveStatement stmt = gen.statement();
61 verify(stmt instanceof WithStatus, "Unexpected statement %s", stmt);
62 final WithStatus withStatus = (WithStatus) stmt;
64 annotateDeprecatedIfNecessary(withStatus, notificationMethod);
65 if (withStatus.getStatus() == Status.OBSOLETE) {
66 notificationMethod.setDefault(true);
69 // FIXME: finish this up
70 // addComment(notificationMethod, notification);
73 return builder.build();