Bump versions to 13.0.4-SNAPSHOT
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / LeafListGenerator.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.generator.impl.reactor;
9
10 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultLeafListRuntimeType;
11 import org.opendaylight.mdsal.binding.model.api.Type;
12 import org.opendaylight.mdsal.binding.model.ri.Types;
13 import org.opendaylight.mdsal.binding.runtime.api.LeafListRuntimeType;
14 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
15 import org.opendaylight.yangtools.yang.common.Ordering;
16 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
17
18 /**
19  * Generator corresponding to a {@code leaf-list} statement.
20  */
21 final class LeafListGenerator
22         extends AbstractTypeAwareGenerator<LeafListEffectiveStatement, LeafListRuntimeType, LeafListGenerator> {
23     LeafListGenerator(final LeafListEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
24         super(statement, parent);
25     }
26
27     @Override
28     StatementNamespace namespace() {
29         return StatementNamespace.LEAF_LIST;
30     }
31
32     @Override
33     Type methodReturnType(final TypeBuilderFactory builderFactory) {
34         // If we are a leafref and the reference cannot be resolved, we need to generate a list wildcard, not
35         // List<Object>, we will try to narrow the return type in subclasses.
36         final Type type = super.methodReturnType(builderFactory);
37         final boolean isObject = Types.objectType().equals(type);
38
39         if (statement().ordering() == Ordering.SYSTEM) {
40             return isObject ? Types.setTypeWildcard() : Types.setTypeFor(type);
41         }
42         return isObject ? Types.listTypeWildcard() : Types.listTypeFor(type);
43     }
44
45     @Override
46     LeafListRuntimeType createExternalRuntimeType(final Type type) {
47         return new DefaultLeafListRuntimeType(type, statement());
48     }
49
50     @Override
51     LeafListRuntimeType createInternalRuntimeType(final AugmentResolver resolver,
52             final LeafListEffectiveStatement statement, final Type type) {
53         return new DefaultLeafListRuntimeType(type, statement);
54     }
55 }