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 org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.model.api.DefaultType;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.Type;
14 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
15 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
16 import org.opendaylight.mdsal.binding.model.util.BindingTypes;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
23 * Generator corresponding to a {@code action} statement.
25 final class ActionGenerator extends AbstractCompositeGenerator<ActionEffectiveStatement> {
26 ActionGenerator(final ActionEffectiveStatement statement, final AbstractCompositeGenerator<?> parent) {
27 super(statement, parent);
31 void pushToInference(final SchemaInferenceStack dataTree) {
32 dataTree.enterSchemaTree(statement().getIdentifier());
36 ClassPlacement classPlacement() {
37 // We do not generate Actions for groupings as they are inexact, and do not capture an actual instantiation --
38 // therefore they do not have an InstanceIdentifier. We still need to allocate a package name for the purposes
39 // of generating shared classes for input/output
40 return getParent() instanceof GroupingGenerator ? ClassPlacement.PHANTOM : ClassPlacement.TOP_LEVEL;
44 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
45 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
46 builder.addImplementsType(implementedType(builderFactory));
48 final ModuleGenerator module = currentModule();
49 module.addQNameConstant(builder, statement().argument().getLocalName());
51 // addGetterMethods(builder, builderFactory);
53 annotateDeprecatedIfNecessary(builder);
54 if (builderFactory instanceof TypeBuilderFactory.Codegen) {
55 addCodegenInformation(module, statement(), builder);
58 return builder.build();
61 private @NonNull Type implementedType(final TypeBuilderFactory builderFactory) {
62 final GeneratedType input = getChild(this, InputEffectiveStatement.class).getOriginal()
63 .getGeneratedType(builderFactory);
64 final GeneratedType output = getChild(this, OutputEffectiveStatement.class).getOriginal()
65 .getGeneratedType(builderFactory);
67 final AbstractCompositeGenerator<?> parent = getParent();
68 if (parent instanceof ListGenerator) {
69 final KeyGenerator keyGen = ((ListGenerator) parent).keyGenerator();
71 return BindingTypes.keyedListAction(DefaultType.of(parent.typeName()),
72 keyGen.getGeneratedType(builderFactory), input, output);
76 return BindingTypes.action(DefaultType.of(parent.typeName()), input, output);
80 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
81 // actions are a separate concept