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.opendaylight.mdsal.binding.model.api.ConcreteType;
11 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
12 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
13 import org.opendaylight.mdsal.binding.model.ri.Types;
14 import org.opendaylight.yangtools.yang.binding.RpcInput;
15 import org.opendaylight.yangtools.yang.binding.RpcOutput;
16 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
22 * Generator corresponding to an {@code input} or an {@code output} statement.
24 class OperationContainerGenerator extends AbstractCompositeGenerator<SchemaTreeEffectiveStatement<?>> {
25 private static final ConcreteType RPC_INPUT = Types.typeForClass(RpcInput.class);
26 private static final ConcreteType RPC_OUTPUT = Types.typeForClass(RpcOutput.class);
28 private final ConcreteType baseInterface;
30 OperationContainerGenerator(final InputEffectiveStatement statement, final AbstractCompositeGenerator<?> parent) {
31 super(statement, parent);
32 baseInterface = RPC_INPUT;
35 OperationContainerGenerator(final OutputEffectiveStatement statement, final AbstractCompositeGenerator<?> parent) {
36 super(statement, parent);
37 baseInterface = RPC_OUTPUT;
41 final void pushToInference(final SchemaInferenceStack dataTree) {
42 dataTree.enterSchemaTree(statement().getIdentifier());
46 final GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
47 final AbstractCompositeGenerator<?> parent = getParent();
48 if (parent instanceof ActionGenerator && ((ActionGenerator) parent).isAddedByUses()) {
49 // final ActionDefinition orig = findOrigAction(parentSchema, action).get();
50 // // Original definition may live in a different module, make sure we account for that
51 // final ModuleContext origContext = moduleContext(
52 // orig.getPath().getPathFromRoot().iterator().next().getModule());
53 // input = context.addAliasType(origContext, orig.getInput(), action.getInput());
54 // output = context.addAliasType(origContext, orig.getOutput(), action.getOutput());
56 throw new UnsupportedOperationException("Lookup in original");
59 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
60 builder.addImplementsType(baseInterface);
61 addAugmentable(builder);
63 addUsesInterfaces(builder, builderFactory);
64 addConcreteInterfaceMethods(builder);
65 addGetterMethods(builder, builderFactory);
67 final ModuleGenerator module = currentModule();
68 module.addQNameConstant(builder, localName());
70 annotateDeprecatedIfNecessary(builder);
71 if (builderFactory instanceof TypeBuilderFactory.Codegen) {
72 addCodegenInformation(module, statement(), builder);
74 // builder.setSchemaPath(schemaNode.getPath());
75 builder.setModuleName(module.statement().argument().getLocalName());
77 return builder.build();