/* * 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 static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; import java.util.function.Function; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; 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.model.api.stmt.SchemaTreeEffectiveStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; /** * Specialization of {@link BaseQNameStatementSupport} for {@code input} and {@code output} statements. * * @param Declared Statement representation * @param Effective Statement representation */ @Beta public abstract class BaseOperationContainerStatementSupport, E extends SchemaTreeEffectiveStatement> extends BaseImplicitStatementSupport { private final Function createArgument; protected BaseOperationContainerStatementSupport(final StatementDefinition publicDefinition, final Function createArgument, final CopyPolicy copyPolicy) { super(publicDefinition, copyPolicy); this.createArgument = requireNonNull(createArgument); } @Override public final QName parseArgumentValue(final StmtContext ctx, final String value) { return createArgument.apply(StmtContextUtils.getRootModuleQName(ctx)); } @Override protected final @NonNull E createDeclaredEffective(final Current stmt, final ImmutableList> substatements) { try { return createDeclaredEffective( EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt, substatements); } catch (SubstatementIndexingException e) { throw new SourceException(e.getMessage(), stmt, e); } } protected abstract @NonNull E createDeclaredEffective(int flags, @NonNull Current stmt, @NonNull ImmutableList> substatements); @Override protected final E createUndeclaredEffective(final Current stmt, final ImmutableList> substatements) { return createUndeclaredEffective(EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), stmt, substatements); } protected abstract @NonNull E createUndeclaredEffective(int flags, @NonNull Current stmt, @NonNull ImmutableList> substatements); }