Do not use StatementSourceReference in AbstractDeclaredEffectiveStatement
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / input / AbstractInputStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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.input;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.common.YangConstants;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
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.StatementSource;
17 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseOperationContainerStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24
25 abstract class AbstractInputStatementSupport
26         extends BaseOperationContainerStatementSupport<InputStatement, InputEffectiveStatement> {
27     AbstractInputStatementSupport() {
28         super(YangStmtMapping.INPUT, YangConstants::operationInputQName);
29     }
30
31     @Override
32     protected final InputStatement createDeclared(final StmtContext<QName, InputStatement, ?> ctx,
33             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
34         final StatementSource source = ctx.source();
35         switch (source) {
36             case CONTEXT:
37                 return new RegularUndeclaredInputStatement(ctx.getArgument(), substatements);
38             case DECLARATION:
39                 return new RegularInputStatement(ctx.getArgument(), substatements);
40             default:
41                 throw new IllegalStateException("Unhandled statement source " + source);
42         }
43     }
44
45     @Override
46     protected final InputStatement createEmptyDeclared(final StmtContext<QName, InputStatement, ?> ctx) {
47         final StatementSource source = ctx.source();
48         switch (source) {
49             case CONTEXT:
50                 return new EmptyUndeclaredInputStatement(ctx.getArgument());
51             case DECLARATION:
52                 return new EmptyInputStatement(ctx.getArgument());
53             default:
54                 throw new IllegalStateException("Unhandled statement source " + source);
55         }
56     }
57
58     @Override
59     protected final InputEffectiveStatement createDeclaredEffective(final int flags,
60             final Current<QName, InputStatement> stmt,
61             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
62         return new DeclaredInputEffectiveStatement(flags, stmt.declared(), substatements, stmt.getSchemaPath());
63     }
64
65     @Override
66     protected final InputEffectiveStatement createUndeclaredEffective(final int flags,
67             final Current<QName, InputStatement> stmt,
68             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
69         try {
70             return new UndeclaredInputEffectiveStatement(flags, substatements, stmt.getSchemaPath());
71         } catch (SubstatementIndexingException e) {
72             throw new SourceException(e.getMessage(), stmt.sourceReference(), e);
73         }
74     }
75 }