Adopt odlparent-10.0.0/yangtools-8.0.0-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.common.Ordering;
15 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
16
17 /**
18  * Generator corresponding to a {@code leaf-list} statement.
19  */
20 final class LeafListGenerator
21         extends AbstractTypeAwareGenerator<LeafListEffectiveStatement, LeafListRuntimeType, LeafListGenerator> {
22     LeafListGenerator(final LeafListEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
23         super(statement, parent);
24     }
25
26     @Override
27     Type methodReturnType(final TypeBuilderFactory builderFactory) {
28         // If we are a leafref and the reference cannot be resolved, we need to generate a list wildcard, not
29         // List<Object>, we will try to narrow the return type in subclasses.
30         final Type type = super.methodReturnType(builderFactory);
31         final boolean isObject = Types.objectType().equals(type);
32
33         if (statement().ordering() == Ordering.SYSTEM) {
34             return isObject ? Types.setTypeWildcard() : Types.setTypeFor(type);
35         }
36         return isObject ? Types.listTypeWildcard() : Types.listTypeFor(type);
37     }
38
39     @Override
40     LeafListRuntimeType createRuntimeType(final Type type) {
41         return new DefaultLeafListRuntimeType(type, statement());
42     }
43
44     @Override
45     LeafListRuntimeType rebaseRuntimeType(final LeafListRuntimeType type, final LeafListEffectiveStatement statement) {
46         return new DefaultLeafListRuntimeType(type.javaType(), statement);
47     }
48 }