Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / DeclaredEffectiveStatementBase.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 com.google.common.base.Verify;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
14 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16
17 public abstract class DeclaredEffectiveStatementBase<A, D extends DeclaredStatement<A>> extends
18         EffectiveStatementBase<A, D> {
19
20     private final StatementSource statementSource;
21     private final A argument;
22     private final D declaredInstance;
23
24     /**
25      * Constructor.
26      *
27      * @param ctx
28      *            context of statement.
29      */
30     protected DeclaredEffectiveStatementBase(final StmtContext<A, D, ?> ctx) {
31         super(ctx);
32
33         this.argument = ctx.getStatementArgument();
34         this.statementSource = ctx.getStatementSource();
35
36         /*
37          * Share original instance of declared statement between all effective
38          * statements which have been copied or derived from this original
39          * declared statement.
40          */
41         @SuppressWarnings("unchecked")
42         final StmtContext<?, D, ?> lookupCtx = (StmtContext<?, D, ?>) ctx.getOriginalCtx().orElse(ctx);
43         declaredInstance = Verify.verifyNotNull(lookupCtx.buildDeclared(),
44             "Statement %s failed to build declared statement", lookupCtx);
45     }
46
47     @Nonnull
48     @Override
49     public final StatementDefinition statementDefinition() {
50         return declaredInstance.statementDefinition();
51     }
52
53     @Override
54     public A argument() {
55         return argument;
56     }
57
58     @Nonnull
59     @Override
60     public final StatementSource getStatementSource() {
61         return statementSource;
62     }
63
64     @Override
65     public final D getDeclared() {
66         return declaredInstance;
67     }
68 }