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.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
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.parser.spi.meta.AbstractQNameStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 * Specialization of {@link BaseStatementSupport} for QName statement arguments.
24 * @param <D> Declared Statement representation
25 * @param <E> Effective Statement representation
28 public abstract class BaseQNameStatementSupport<D extends DeclaredStatement<QName>,
29 E extends EffectiveStatement<QName, D>> extends AbstractQNameStatementSupport<D, E> {
30 protected BaseQNameStatementSupport(final StatementDefinition publicDefinition) {
31 super(publicDefinition);
35 public final E createEffective(final StmtContext<QName, D, E> ctx) {
36 final D declared = ctx.buildDeclared();
37 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements =
38 BaseStatementSupport.buildEffectiveSubstatements(ctx);
39 return substatements.isEmpty() ? createEmptyEffective(ctx, declared)
40 : createEffective(ctx, declared, substatements);
43 protected abstract @NonNull E createEffective(@NonNull StmtContext<QName, D, E> ctx, @NonNull D declared,
44 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
46 protected abstract @NonNull E createEmptyEffective(@NonNull StmtContext<QName, D, E> ctx, @NonNull D declared);
48 protected static final <E extends EffectiveStatement<?, ?>> @Nullable E findFirstStatement(
49 final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<E> type) {
50 return BaseStatementSupport.findFirstStatement(statements, type);
53 protected static final <A, E extends EffectiveStatement<A, ?>> A findFirstArgument(
54 final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<E> type, final A defValue) {
55 return BaseStatementSupport.findFirstArgument(statements, type, defValue);