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.mdsal.binding.spec.naming.BindingMapping;
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: eventually 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 String classSuffix() {
40 return BindingMapping.NOTIFICATION_LISTENER_SUFFIX;
44 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
45 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
46 // FIXME: MDSAL-496: mark this interface as deprecated
47 builder.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
49 for (NotificationGenerator gen : notifs) {
50 final MethodSignatureBuilder notificationMethod = builder.addMethod("on" + gen.assignedName())
51 .setAccessModifier(AccessModifier.PUBLIC)
52 .addParameter(gen.getGeneratedType(builderFactory), "notification")
53 .setReturnType(Types.primitiveVoidType());
55 final NotificationEffectiveStatement stmt = gen.statement();
56 verify(stmt instanceof WithStatus, "Unexpected statement %s", stmt);
57 final WithStatus withStatus = (WithStatus) stmt;
59 annotateDeprecatedIfNecessary(withStatus, notificationMethod);
60 if (withStatus.getStatus() == Status.OBSOLETE) {
61 notificationMethod.setDefault(true);
64 // FIXME: finish this up
65 // addComment(notificationMethod, notification);
68 return builder.build();