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.generator.impl.rt.DefaultAnydataRuntimeType;
11 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultAnyxmlRuntimeType;
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.ri.BindingTypes;
17 import org.opendaylight.mdsal.binding.runtime.api.AnydataRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.AnyxmlRuntimeType;
19 import org.opendaylight.mdsal.binding.runtime.api.OpaqueRuntimeType;
20 import org.opendaylight.yangtools.yang.model.api.stmt.AnydataEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
26 * Common generator for {@code anydata} and {@code anyxml}.
28 abstract class OpaqueObjectGenerator<S extends DataTreeEffectiveStatement<?>, R extends OpaqueRuntimeType>
29 extends AbstractExplicitGenerator<S, R> {
30 static final class Anydata extends OpaqueObjectGenerator<AnydataEffectiveStatement, AnydataRuntimeType> {
31 Anydata(final AnydataEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
32 super(statement, parent);
36 AnydataRuntimeType createRuntimeType() {
37 return generatedType().map(type -> new DefaultAnydataRuntimeType(type, statement())).orElse(null);
41 AnydataRuntimeType rebaseRuntimeType(final AnydataRuntimeType type, final AnydataEffectiveStatement statement) {
42 return new DefaultAnydataRuntimeType(type.javaType(), statement);
46 static final class Anyxml extends OpaqueObjectGenerator<AnyxmlEffectiveStatement, AnyxmlRuntimeType> {
47 Anyxml(final AnyxmlEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
48 super(statement, parent);
52 AnyxmlRuntimeType createRuntimeType() {
53 return generatedType().map(type -> new DefaultAnyxmlRuntimeType(type, statement())).orElse(null);
57 AnyxmlRuntimeType rebaseRuntimeType(final AnyxmlRuntimeType type, final AnyxmlEffectiveStatement statement) {
58 return new DefaultAnyxmlRuntimeType(type.javaType(), statement);
62 OpaqueObjectGenerator(final S statement, final AbstractCompositeGenerator<?, ?> parent) {
63 super(statement, parent);
67 void pushToInference(final SchemaInferenceStack dataTree) {
68 dataTree.enterDataTree(statement().getIdentifier());
72 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
73 final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
74 builder.addImplementsType(BindingTypes.opaqueObject(builder));
75 addImplementsChildOf(builder);
76 defaultImplementedInterace(builder);
77 annotateDeprecatedIfNecessary(builder);
79 final ModuleGenerator module = currentModule();
80 module.addQNameConstant(builder, localName());
82 builderFactory.addCodegenInformation(module, statement(), builder);
83 builder.setModuleName(module.statement().argument().getLocalName());
84 // newType.setSchemaPath(schemaNode.getPath());
86 return builder.build();
90 void constructRequire(final GeneratedTypeBuilderBase<?> builder, final Type returnType) {
91 constructRequireImpl(builder, returnType);