2 * Copyright (c) 2020 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.yangtools.yang.parser.rfc7950.stmt;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.Status;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
19 import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
26 * Specialization of {@link BaseQNameStatementSupport} for {@code input} and {@code output} statements.
28 * @param <D> Declared Statement representation
29 * @param <E> Effective Statement representation
32 public abstract class BaseOperationContainerStatementSupport<D extends DeclaredStatement<QName>,
33 E extends EffectiveStatement<QName, D>> extends BaseQNameStatementSupport<D, E> {
34 protected BaseOperationContainerStatementSupport(final StatementDefinition publicDefinition) {
35 super(publicDefinition);
39 public final void onStatementAdded(final Mutable<QName, D, E> stmt) {
40 stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), stmt);
44 protected final E createEffective(
45 final StmtContext<QName, D, E> ctx,
46 final D declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
47 final StatementSource source = ctx.getStatementSource();
48 final int flags = computeFlags(ctx, substatements);
49 switch (ctx.getStatementSource()) {
51 return createUndeclaredEffective(flags, ctx, substatements);
53 return createDeclaredEffective(flags, ctx, substatements, declared);
55 throw new IllegalStateException("Unhandled statement source " + source);
60 protected final E createEmptyEffective(final StmtContext<QName, D, E> ctx, final D declared) {
61 return createEffective(ctx, declared, ImmutableList.of());
64 protected abstract @NonNull E createDeclaredEffective(int flags, @NonNull StmtContext<QName, D, E> ctx,
65 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements, @NonNull D declared);
67 protected abstract @NonNull E createUndeclaredEffective(int flags, @NonNull StmtContext<QName, D, E> ctx,
68 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
70 private static int computeFlags(final StmtContext<?, ?, ?> ctx,
71 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
72 return new FlagsBuilder()
73 .setHistory(ctx.getCopyHistory())
74 .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))