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 static com.google.common.base.Verify.verify;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultAnydataRuntimeType;
14 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultAnyxmlRuntimeType;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
16 import org.opendaylight.mdsal.binding.model.api.Type;
17 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
18 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
19 import org.opendaylight.mdsal.binding.runtime.api.AnydataRuntimeType;
20 import org.opendaylight.mdsal.binding.runtime.api.AnyxmlRuntimeType;
21 import org.opendaylight.mdsal.binding.runtime.api.OpaqueRuntimeType;
22 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
23 import org.opendaylight.yangtools.yang.model.api.stmt.AnydataEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
29 * Common generator for {@code anydata} and {@code anyxml}.
31 abstract class OpaqueObjectGenerator<S extends DataTreeEffectiveStatement<?>, R extends OpaqueRuntimeType>
32 extends AbstractExplicitGenerator<S, R> {
33 static final class Anydata extends OpaqueObjectGenerator<AnydataEffectiveStatement, AnydataRuntimeType> {
34 Anydata(final AnydataEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
35 super(statement, parent);
39 StatementNamespace namespace() {
40 return StatementNamespace.ANYDATA;
44 AnydataRuntimeType createExternalRuntimeType(final GeneratedType type) {
45 return new DefaultAnydataRuntimeType(type, statement());
49 AnydataRuntimeType createInternalRuntimeType(final AnydataEffectiveStatement statement,
50 final GeneratedType type) {
51 return new DefaultAnydataRuntimeType(type, statement);
55 static final class Anyxml extends OpaqueObjectGenerator<AnyxmlEffectiveStatement, AnyxmlRuntimeType> {
56 Anyxml(final AnyxmlEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
57 super(statement, parent);
61 StatementNamespace namespace() {
62 return StatementNamespace.ANYXML;
66 AnyxmlRuntimeType createExternalRuntimeType(final GeneratedType type) {
67 return new DefaultAnyxmlRuntimeType(type, statement());
71 AnyxmlRuntimeType createInternalRuntimeType(final AnyxmlEffectiveStatement statement,
72 final GeneratedType type) {
73 return new DefaultAnyxmlRuntimeType(type, statement);
77 OpaqueObjectGenerator(final S statement, final AbstractCompositeGenerator<?, ?> parent) {
78 super(statement, parent);
82 void pushToInference(final SchemaInferenceStack dataTree) {
83 dataTree.enterDataTree(statement().argument());
87 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
88 final var builder = builderFactory.newGeneratedTypeBuilder(typeName());
89 builder.addImplementsType(BindingTypes.opaqueObject(builder));
90 addImplementsChildOf(builder);
91 defaultImplementedInterace(builder);
92 annotateDeprecatedIfNecessary(builder);
94 final var module = currentModule();
95 module.addQNameConstant(builder, localName());
97 builderFactory.addCodegenInformation(module, statement(), builder);
98 builder.setModuleName(module.statement().argument().getLocalName());
99 // newType.setSchemaPath(schemaNode.getPath());
101 return builder.build();
105 void constructRequire(final GeneratedTypeBuilderBase<?> builder, final Type returnType) {
106 constructRequireImpl(builder, returnType);
110 final @NonNull R createExternalRuntimeType(final Type type) {
111 verify(type instanceof GeneratedType, "Unexpected type %s", type);
112 return createExternalRuntimeType((GeneratedType) type);
115 abstract @NonNull R createExternalRuntimeType(@NonNull GeneratedType type);
118 final R createInternalRuntimeType(final AugmentResolver resolver, final S statement, final Type type) {
119 verify(type instanceof GeneratedType, "Unexpected type %s", type);
120 return createInternalRuntimeType(statement, (GeneratedType) type);
123 abstract @NonNull R createInternalRuntimeType(@NonNull S statement, @NonNull GeneratedType type);