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 org.eclipse.jdt.annotation.NonNull;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
14 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
15 import org.opendaylight.yangtools.yang.model.api.PathExpression;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
20 * Abstract view on generation tree as viewed by a particular {@link Generator}.
22 abstract class GeneratorContext extends AbstractEffectiveModelContextProvider {
23 GeneratorContext(final EffectiveModelContext modelContext) {
28 * Resolve generator for the type object pointed to by a {@code path} expression, or {@code null} it the if cannot
29 * the current generator is nested inside a {@code grouping} and the generator cannot be found.
31 * @param path A {@code path} expression
32 * @return Resolved generator, or {@code null} if legally not found
33 * @throws NullPointerException if {@code path} is {@code null}
34 * @throws IllegalStateException if this generator is not inside a {@code grouping} and the path cannot be resolved
36 abstract @Nullable AbstractTypeObjectGenerator<?, ?> resolveLeafref(@NonNull PathExpression path);
39 * Resolve a tree-scoped namespace reference. This covers {@code typedef} and {@code grouping} statements, as per
40 * bullets 5 and 6 of <a href="https://tools.ietf.org/html/rfc6020#section-6.2.1">RFC6020, section 6.2.1</a>.
42 * @param <E> {@link EffectiveStatement} type
43 * @param type EffectiveStatement class
44 * @param argument Statement argument
45 * @return Resolved {@link Generator}
46 * @throws NullPointerException if any argument is null
47 * @throws IllegalStateException if the generator cannot be found
49 abstract <E extends EffectiveStatement<QName, ?>, G extends AbstractExplicitGenerator<E, ?>>
50 @NonNull G resolveTreeScoped(@NonNull Class<G> type, @NonNull QName argument);
52 abstract @NonNull ModuleGenerator resolveModule(@NonNull QNameModule namespace);
54 final @NonNull IdentityGenerator resolveIdentity(final @NonNull QName name) {
55 for (Generator gen : resolveModule(name.getModule())) {
56 if (gen instanceof final IdentityGenerator idgen) {
57 if (name.equals(idgen.statement().argument())) {
62 throw new IllegalStateException("Failed to find identity " + name);
65 final @NonNull TypedefGenerator resolveTypedef(final @NonNull QName qname) {
66 return resolveTreeScoped(TypedefGenerator.class, qname);