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.model.api.stmt.AnydataEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
28 * Common generator for {@code anydata} and {@code anyxml}.
30 abstract class OpaqueObjectGenerator<S extends DataTreeEffectiveStatement<?>, R extends OpaqueRuntimeType>
31 extends AbstractExplicitGenerator<S, R> {
32 static final class Anydata extends OpaqueObjectGenerator<AnydataEffectiveStatement, AnydataRuntimeType> {
33 Anydata(final AnydataEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
34 super(statement, parent);
38 StatementNamespace namespace() {
39 return StatementNamespace.ANYDATA;
43 AnydataRuntimeType createExternalRuntimeType(final GeneratedType type) {
44 return new DefaultAnydataRuntimeType(type, statement());
48 AnydataRuntimeType createInternalRuntimeType(final AnydataEffectiveStatement statement,
49 final GeneratedType type) {
50 return new DefaultAnydataRuntimeType(type, statement);
54 static final class Anyxml extends OpaqueObjectGenerator<AnyxmlEffectiveStatement, AnyxmlRuntimeType> {
55 Anyxml(final AnyxmlEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
56 super(statement, parent);
60 StatementNamespace namespace() {
61 return StatementNamespace.ANYXML;
65 AnyxmlRuntimeType createExternalRuntimeType(final GeneratedType type) {
66 return new DefaultAnyxmlRuntimeType(type, statement());
70 AnyxmlRuntimeType createInternalRuntimeType(final AnyxmlEffectiveStatement statement,
71 final GeneratedType type) {
72 return new DefaultAnyxmlRuntimeType(type, statement);
76 OpaqueObjectGenerator(final S statement, final AbstractCompositeGenerator<?, ?> parent) {
77 super(statement, parent);
81 void pushToInference(final SchemaInferenceStack dataTree) {
82 dataTree.enterDataTree(statement().argument());
86 GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
87 final var builder = builderFactory.newGeneratedTypeBuilder(typeName());
88 builder.addImplementsType(BindingTypes.opaqueObject(builder));
89 addImplementsChildOf(builder);
90 defaultImplementedInterace(builder);
91 annotateDeprecatedIfNecessary(builder);
93 final var module = currentModule();
94 module.addQNameConstant(builder, localName());
96 builderFactory.addCodegenInformation(module, statement(), builder);
97 builder.setModuleName(module.statement().argument().getLocalName());
98 // newType.setSchemaPath(schemaNode.getPath());
100 return builder.build();
104 void constructRequire(final GeneratedTypeBuilderBase<?> builder, final Type returnType) {
105 constructRequireImpl(builder, returnType);
109 final @NonNull R createExternalRuntimeType(final Type type) {
110 verify(type instanceof GeneratedType, "Unexpected type %s", type);
111 return createExternalRuntimeType((GeneratedType) type);
114 abstract @NonNull R createExternalRuntimeType(@NonNull GeneratedType type);
117 final R createInternalRuntimeType(final AugmentResolver resolver, final S statement, final Type type) {
118 verify(type instanceof GeneratedType, "Unexpected type %s", type);
119 return createInternalRuntimeType(statement, (GeneratedType) type);
122 abstract @NonNull R createInternalRuntimeType(@NonNull S statement, @NonNull GeneratedType type);