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.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultActionRuntimeType;
13 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
14 import org.opendaylight.mdsal.binding.model.api.Type;
15 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
16 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
17 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
18 import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
19 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
20 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
27 * Generator corresponding to a {@code action} statement.
29 final class ActionGenerator extends CompositeSchemaTreeGenerator<ActionEffectiveStatement, ActionRuntimeType> {
30 ActionGenerator(final ActionEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
31 super(statement, parent);
35 void pushToInference(final SchemaInferenceStack dataTree) {
36 dataTree.enterSchemaTree(statement().getIdentifier());
40 ClassPlacement classPlacement() {
41 // We do not generate Actions for groupings as they are inexact, and do not capture an actual instantiation --
42 // therefore they do not have an InstanceIdentifier. We still need to allocate a package name for the purposes
43 // of generating shared classes for input/output
44 return getParent() instanceof GroupingGenerator ? ClassPlacement.PHANTOM : ClassPlacement.TOP_LEVEL;
48 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
49 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
50 builder.addImplementsType(implementedType(builderFactory));
52 final ModuleGenerator module = currentModule();
53 module.addQNameConstant(builder, statement().argument());
55 // addGetterMethods(builder, builderFactory);
57 annotateDeprecatedIfNecessary(builder);
58 builderFactory.addCodegenInformation(module, statement(), builder);
60 return builder.build();
64 ActionRuntimeType createRuntimeType(final GeneratedType type, final ActionEffectiveStatement statement,
65 final List<RuntimeType> children, final List<AugmentRuntimeType> augments) {
66 return new DefaultActionRuntimeType(type, statement, children, augments);
69 private @NonNull Type implementedType(final TypeBuilderFactory builderFactory) {
70 final GeneratedType input = getChild(this, InputEffectiveStatement.class).getOriginal()
71 .getGeneratedType(builderFactory);
72 final GeneratedType output = getChild(this, OutputEffectiveStatement.class).getOriginal()
73 .getGeneratedType(builderFactory);
75 final AbstractCompositeGenerator<?, ?> parent = getParent();
76 if (parent instanceof ListGenerator) {
77 final KeyGenerator keyGen = ((ListGenerator) parent).keyGenerator();
79 return BindingTypes.keyedListAction(Type.of(parent.typeName()), keyGen.getGeneratedType(builderFactory),
84 return BindingTypes.action(Type.of(parent.typeName()), input, output);
88 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
89 // actions are a separate concept