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.DefaultActionRuntimeType;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
14 import org.opendaylight.mdsal.binding.model.api.Type;
15 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
16 import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
17 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
21 * Generator corresponding to a {@code action} statement.
23 final class ActionGenerator extends AbstractInvokableGenerator<ActionEffectiveStatement, ActionRuntimeType> {
24 ActionGenerator(final ActionEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
25 super(statement, parent);
29 StatementNamespace namespace() {
30 return StatementNamespace.ACTION;
34 ClassPlacement classPlacement() {
35 // We do not generate Actions for groupings as they are inexact, and do not capture an actual instantiation --
36 // therefore they do not have an InstanceIdentifier. We still need to allocate a package name for the purposes
37 // of generating shared classes for input/output
38 return getParent() instanceof GroupingGenerator ? ClassPlacement.PHANTOM : ClassPlacement.TOP_LEVEL;
42 ParameterizedType implementedType(final TypeBuilderFactory builderFactory, final GeneratedType input,
43 final GeneratedType output) {
44 final var parent = getParent();
45 final var parentType = Type.of(parent.typeName());
46 if (parent instanceof ListGenerator list) {
47 final var keyGen = list.keyGenerator();
49 return BindingTypes.keyedListAction(parentType, keyGen.getGeneratedType(builderFactory), input, output);
52 return BindingTypes.action(parentType, input, output);
56 CompositeRuntimeTypeBuilder<ActionEffectiveStatement, ActionRuntimeType> createBuilder(
57 final ActionEffectiveStatement statement) {
58 return new InvokableRuntimeTypeBuilder<>(statement) {
60 ActionRuntimeType build(final GeneratedType generatedType, final ActionEffectiveStatement statement,
61 final List<RuntimeType> childTypes) {
62 return new DefaultActionRuntimeType(generatedType, statement, childTypes);