2 * Copyright (c) 2022 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.GeneratedType;
12 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
13 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
14 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
15 import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
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;
21 abstract class AbstractInvokableGenerator<S extends SchemaTreeEffectiveStatement<?>, R extends CompositeRuntimeType>
22 extends CompositeSchemaTreeGenerator<S, R> {
23 private static final JavaTypeName FUNCTIONAL_INTERFACE_ANNOTATION = JavaTypeName.create(FunctionalInterface.class);
25 AbstractInvokableGenerator(final S statement, final AbstractCompositeGenerator<?, ?> parent) {
26 super(statement, parent);
30 final void pushToInference(final SchemaInferenceStack dataTree) {
31 dataTree.enterSchemaTree(statement().argument());
35 final void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
36 // RPCs/Actions are a separate concept
40 final GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
41 final var builder = builderFactory.newGeneratedTypeBuilder(typeName());
42 builder.addImplementsType(implementedType(builderFactory,
43 getChild(this, InputEffectiveStatement.class).getOriginal().getGeneratedType(builderFactory),
44 getChild(this, OutputEffectiveStatement.class).getOriginal().getGeneratedType(builderFactory)));
45 builder.addAnnotation(FUNCTIONAL_INTERFACE_ANNOTATION);
46 defaultImplementedInterace(builder);
48 final var module = currentModule();
49 module.addQNameConstant(builder, statement().argument());
51 annotateDeprecatedIfNecessary(builder);
52 builderFactory.addCodegenInformation(module, statement(), builder);
54 return builder.build();
57 abstract @NonNull ParameterizedType implementedType(TypeBuilderFactory builderFactory, GeneratedType input,
58 GeneratedType output);