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 edu.umd.cs.findbugs.annotations.Nullable;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.PathExpression;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
18 * Abstract view on generation tree as viewed by a particular {@link Generator}.
20 abstract class GeneratorContext {
22 * Resolve generator for the type object pointed to by a {@code path} expression, or {@code null} it the if cannot
23 * the current generator is nested inside a {@code grouping} and the generator cannot be found.
25 * @param path A {@code path} expression
26 * @return Resolved generator, or {@code null} if legally not found
27 * @throws NullPointerException if {@code path} is {@code null}
28 * @throws IllegalStateException if this generator is not inside a {@code grouping} and the path cannot be resolved
30 abstract @Nullable AbstractTypeObjectGenerator<?> resolveLeafref(@NonNull PathExpression path);
33 * Resolve a tree-scoped namespace reference. This covers {@code typedef} and {@code grouping} statements, as per
34 * bullets 5 and 6 of <a href="https://tools.ietf.org/html/rfc6020#section-6.2.1">RFC6020, section 6.2.1</a>.
36 * @param <E> {@link EffectiveStatement} type
37 * @param type EffectiveStatement class
38 * @param argument Statement argument
39 * @return Resolved {@link Generator}
40 * @throws NullPointerException if any argument is null
41 * @throws IllegalStateException if the generator cannot be found
43 abstract <E extends EffectiveStatement<QName, ?>, G extends AbstractExplicitGenerator<E>>
44 @NonNull G resolveTreeScoped(@NonNull Class<G> type, @NonNull QName argument);
46 abstract @NonNull AbstractExplicitGenerator<?> resolveSchemaNode(@NonNull SchemaNodeIdentifier path);
48 abstract @NonNull IdentityGenerator resolveIdentity(@NonNull QName name);
50 final @NonNull TypedefGenerator resolveTypedef(final @NonNull QName qname) {
51 return resolveTreeScoped(TypedefGenerator.class, qname);