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.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 * A massively-misnamed superclass for statements which are both schema tree participants and can be created as implicit
23 * nodes. This covers {@code case}, {@code input} and {@code output} statements.
25 * @param <D> Declared Statement representation
26 * @param <E> Effective Statement representation
29 public abstract class BaseImplicitStatementSupport<D extends DeclaredStatement<QName>,
30 E extends SchemaTreeEffectiveStatement<D>> extends BaseSchemaTreeStatementSupport<D, E> {
31 protected BaseImplicitStatementSupport(final StatementDefinition publicDefinition) {
32 super(publicDefinition);
36 protected final E createEffective(
37 final StmtContext<QName, D, E> ctx,
38 final D declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
39 final StatementSource source = ctx.getStatementSource();
40 switch (ctx.getStatementSource()) {
42 return createUndeclaredEffective(ctx, substatements);
44 return createDeclaredEffective(ctx, substatements, declared);
46 throw new IllegalStateException("Unhandled statement source " + source);
51 protected final E createEmptyEffective(final StmtContext<QName, D, E> ctx, final D declared) {
52 return createEffective(ctx, declared, ImmutableList.of());
55 protected abstract @NonNull E createDeclaredEffective(@NonNull StmtContext<QName, D, E> ctx,
56 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements, @NonNull D declared);
58 protected abstract @NonNull E createUndeclaredEffective(@NonNull StmtContext<QName, D, E> ctx,
59 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);