Do not use StatementSourceReference in AbstractDeclaredEffectiveStatement
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / BaseOperationContainerStatementSupport.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import java.util.function.Function;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26
27 /**
28  * Specialization of {@link BaseQNameStatementSupport} for {@code input} and {@code output} statements.
29  *
30  * @param <D> Declared Statement representation
31  * @param <E> Effective Statement representation
32  */
33 @Beta
34 public abstract class BaseOperationContainerStatementSupport<D extends DeclaredStatement<QName>,
35         E extends SchemaTreeEffectiveStatement<D>> extends BaseImplicitStatementSupport<D, E> {
36     private final Function<QNameModule, QName> createArgument;
37
38     protected BaseOperationContainerStatementSupport(final StatementDefinition publicDefinition,
39             final Function<QNameModule, QName> createArgument) {
40         super(publicDefinition);
41         this.createArgument = requireNonNull(createArgument);
42     }
43
44     @Override
45     public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
46         return createArgument.apply(StmtContextUtils.getRootModuleQName(ctx));
47     }
48
49     @Override
50     protected final @NonNull E createDeclaredEffective(final Current<QName, D> stmt,
51             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
52         try {
53             return createDeclaredEffective(historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
54         } catch (SubstatementIndexingException e) {
55             throw new SourceException(e.getMessage(), stmt.sourceReference(), e);
56         }
57     }
58
59     protected abstract @NonNull E createDeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
60             @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
61
62     @Override
63     protected final E createUndeclaredEffective(final Current<QName, D> stmt,
64             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
65         return createUndeclaredEffective(historyAndStatusFlags(stmt.history(), substatements), stmt, substatements);
66     }
67
68     protected abstract @NonNull E createUndeclaredEffective(int flags, @NonNull Current<QName, D> stmt,
69             @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
70 }