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 static com.google.common.base.Verify.verify;
12 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultFeatureRuntimeType;
13 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
14 import org.opendaylight.mdsal.binding.model.api.Type;
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.FeatureRuntimeType;
18 import org.opendaylight.yangtools.yang.binding.YangFeature;
19 import org.opendaylight.yangtools.yang.binding.contract.Naming;
20 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
21 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
24 final class FeatureGenerator extends AbstractExplicitGenerator<FeatureEffectiveStatement, FeatureRuntimeType> {
25 FeatureGenerator(final FeatureEffectiveStatement statement, final ModuleGenerator parent) {
26 super(statement, parent);
30 StatementNamespace namespace() {
31 return StatementNamespace.FEATURE;
35 void pushToInference(final SchemaInferenceStack inferenceStack) {
36 throw new UnsupportedOperationException("Cannot push " + statement() + " to data tree");
40 FeatureRuntimeType createExternalRuntimeType(final Type type) {
41 verify(type instanceof GeneratedTransferObject, "Unexpected type %s", type);
42 return new DefaultFeatureRuntimeType((GeneratedTransferObject) type, statement());
46 FeatureRuntimeType createInternalRuntimeType(final AugmentResolver resolver,
47 final FeatureEffectiveStatement statement, final Type type) {
48 // 'feature' statements are not part of schema tree and hence should never an internal reference
49 throw new UnsupportedOperationException("Should never be called");
53 GeneratedTransferObject createTypeImpl(final TypeBuilderFactory builderFactory) {
54 final var builder = builderFactory.newGeneratedTOBuilder(typeName());
55 builder.addImplementsType(BindingTypes.yangFeature(builder, Type.of(getParent().typeName())));
57 annotateDeprecatedIfNecessary(statement(), builder);
59 final var module = currentModule();
60 module.addQNameConstant(builder, localName());
62 // Constant implementation
63 builder.addConstant(Type.of(builder), Naming.VALUE_STATIC_FIELD_NAME, YangFeature.class);
65 builderFactory.addCodegenInformation(module, statement(), builder);
66 builder.setModuleName(module.statement().argument().getLocalName());
68 return builder.build();
72 void addAsGetterMethod(final GeneratedTypeBuilderBase<?> builder, final TypeBuilderFactory builderFactory) {
73 // features are a separate concept