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.runtime.api;
10 import java.util.List;
11 import java.util.stream.Collectors;
12 import java.util.stream.Stream;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
17 * A {@link RuntimeType} associated with a {@code grouping} statement.
19 public interface GroupingRuntimeType extends CompositeRuntimeType {
21 GroupingEffectiveStatement statement();
24 * Return the set of all concrete data tree instantiations of this {@code grouping}. This is necessary to completely
25 * resolve type information for {@code leafref}s.
28 * As an example, consider {@link GroupingRuntimeType} of {@code grouping baz} and it's instantiations roots
29 * {@code container one} and {@code container two} define in these three models:
47 * import baz { prefix baz; }
60 * import baz { prefix baz; }
72 * Since these are separate modules, each of them can be part of its own compilation unit and therefore
73 * {@code grouping baz} compile-time analysis cannot definitely determine the return type of {@code getBaz()} and
74 * must fall back to {@code Object}.
77 * At run-time, though, we have a closed world, and therefore we can provide accurate information about
78 * instantiation sites: this method will return the {@link CompositeRuntimeType}s for {@code one} and {@code two}.
79 * We can then use this information to know that {@code getBaz()} can either be a {@code String} or an
80 * {@code Uint32} and which type is appropriate at a particular point in YANG data tree.
82 * @return The set instantiated {@link CompositeRuntimeType}s which use this grouping
84 default @NonNull List<CompositeRuntimeType> instantiations() {
85 final var users = directUsers();
86 return switch (users.size()) {
89 final var user = users.get(0);
90 yield user instanceof GroupingRuntimeType grouping ? grouping.instantiations() : List.of(user);
92 default -> users.stream()
93 .flatMap(user -> user instanceof GroupingRuntimeType grouping ? grouping.instantiations().stream()
96 .collect(Collectors.toUnmodifiableList());
101 * Support method for {@link #instantiations()}. This method's return, unlike {@link #instantiations()} can contain
102 * other {@link GroupingRuntimeType}s.
104 * @return Direct users of this grouping
106 @NonNull List<CompositeRuntimeType> directUsers();