Migrate rawStatementArgument()/getStatementSourceReference() callers
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / position / PositionStatementSupport.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.position;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.common.Uint32;
12 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.PositionEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseInternedStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21
22 public final class PositionStatementSupport
23         extends BaseInternedStatementSupport<Uint32, PositionStatement, PositionEffectiveStatement> {
24     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
25         YangStmtMapping.POSITION).build();
26     private static final PositionStatementSupport INSTANCE = new PositionStatementSupport();
27
28     private PositionStatementSupport() {
29         super(YangStmtMapping.POSITION);
30     }
31
32     public static PositionStatementSupport getInstance() {
33         return INSTANCE;
34     }
35
36     @Override
37     public Uint32 parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
38         try {
39             return Uint32.valueOf(value).intern();
40         } catch (IllegalArgumentException e) {
41             throw new SourceException(ctx.sourceReference(), e, "Bit position value %s is not valid integer", value);
42         }
43     }
44
45     @Override
46     protected SubstatementValidator getSubstatementValidator() {
47         return SUBSTATEMENT_VALIDATOR;
48     }
49
50     @Override
51     protected PositionStatement createDeclared(final Uint32 argument,
52             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
53         return new RegularPositionStatement(argument, substatements);
54     }
55
56     @Override
57     protected PositionStatement createEmptyDeclared(final Uint32 argument) {
58         return new EmptyPositionStatement(argument);
59     }
60
61     @Override
62     protected PositionEffectiveStatement createEffective(final PositionStatement declared,
63             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
64         return new RegularPositionEffectiveStatement(declared, substatements);
65     }
66
67     @Override
68     protected PositionEffectiveStatement createEmptyEffective(final PositionStatement declared) {
69         return new EmptyPositionEffectiveStatement(declared);
70     }
71 }