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