2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
16 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
17 import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBuilder;
18 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStringStatementSupport;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
24 final class InstanceIdentifierSpecificationSupport
25 extends AbstractStringStatementSupport<InstanceIdentifierSpecification,
26 EffectiveStatement<String, InstanceIdentifierSpecification>> {
27 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
29 .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
32 InstanceIdentifierSpecificationSupport() {
33 super(YangStmtMapping.TYPE, StatementPolicy.contextIndependent());
37 protected SubstatementValidator getSubstatementValidator() {
38 return SUBSTATEMENT_VALIDATOR;
42 protected InstanceIdentifierSpecification createDeclared(
43 final StmtContext<String, InstanceIdentifierSpecification, ?> ctx,
44 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
45 return new RegularInstanceIdentifierSpecification(ctx.getRawArgument(), substatements);
49 protected InstanceIdentifierSpecification createEmptyDeclared(
50 final StmtContext<String, InstanceIdentifierSpecification, ?> ctx) {
51 return new EmptyIdentifierSpecification(ctx.getRawArgument());
55 protected EffectiveStatement<String, InstanceIdentifierSpecification> createEffective(
56 final Current<String, InstanceIdentifierSpecification> stmt,
57 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
58 final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
59 BaseTypes.instanceIdentifierType(), stmt.argumentAsTypeQName());
61 // TODO: we could do better here for empty substatements, but its really splitting hairs
62 for (EffectiveStatement<?, ?> subStmt : substatements) {
63 if (subStmt instanceof RequireInstanceEffectiveStatement) {
64 builder.setRequireInstance(((RequireInstanceEffectiveStatement)subStmt).argument());
68 return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);