/* * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; /** * Specialization of {@link BaseStatementSupport} for QName statement arguments. * * @param Declared Statement representation * @param Effective Statement representation */ @Beta public abstract class BaseQNameStatementSupport, E extends EffectiveStatement> extends AbstractQNameStatementSupport { protected BaseQNameStatementSupport(final StatementDefinition publicDefinition) { super(publicDefinition); } @Override public final E createEffective(final StmtContext ctx) { final D declared = ctx.buildDeclared(); final ImmutableList> substatements = BaseStatementSupport.buildEffectiveSubstatements(ctx); return substatements.isEmpty() ? createEmptyEffective(ctx, declared) : createEffective(ctx, declared, substatements); } protected abstract @NonNull E createEffective(@NonNull StmtContext ctx, @NonNull D declared, @NonNull ImmutableList> substatements); protected abstract @NonNull E createEmptyEffective(@NonNull StmtContext ctx, @NonNull D declared); protected static final > @Nullable E findFirstStatement( final ImmutableList> statements, final Class type) { return BaseStatementSupport.findFirstStatement(statements, type); } protected static final > A findFirstArgument( final ImmutableList> statements, final Class type, final A defValue) { return BaseStatementSupport.findFirstArgument(statements, type, defValue); } }