Populate parser/ hierarchy
[yangtools.git] / parser / odlext-parser-support / src / main / java / org / opendaylight / yangtools / odlext / parser / ContextReferenceStatementSupport.java
1 /*
2  * Copyright (c) 2021 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.odlext.parser;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement;
13 import org.opendaylight.yangtools.odlext.model.api.ContextReferenceStatement;
14 import org.opendaylight.yangtools.odlext.model.api.OpenDaylightExtensionsStatements;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
20 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
23
24 @Beta
25 public final class ContextReferenceStatementSupport
26         extends AbstractIdentityAwareStatementSupport<ContextReferenceStatement, ContextReferenceEffectiveStatement> {
27     private static final SubstatementValidator VALIDATOR =
28         SubstatementValidator.builder(OpenDaylightExtensionsStatements.CONTEXT_REFERENCE).build();
29
30     public ContextReferenceStatementSupport(final YangParserConfiguration config) {
31         super(OpenDaylightExtensionsStatements.CONTEXT_REFERENCE, config, VALIDATOR);
32     }
33
34     @Override
35     protected ContextReferenceStatement createDeclared(final StmtContext<QName, ContextReferenceStatement, ?> ctx,
36             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
37         return new ContextReferenceStatementImpl(ctx.rawArgument(), ctx.getArgument(), substatements);
38     }
39
40     @Override
41     protected ContextReferenceStatement attachDeclarationReference(final ContextReferenceStatement stmt,
42             final DeclarationReference reference) {
43         return new RefContextReferenceStatement(stmt, reference);
44     }
45
46     @Override
47     ContextReferenceEffectiveStatement createEffective(final ContextReferenceStatement declared,
48             final IdentityEffectiveStatement identity,
49             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
50         return new ContextReferenceEffectiveStatementImpl(declared, identity, substatements);
51     }
52 }