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.common.QName;
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.RequireInstanceEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
17 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
18 import org.opendaylight.yangtools.yang.model.ri.type.InstanceIdentifierTypeBuilder;
19 import org.opendaylight.yangtools.yang.model.ri.type.RestrictedTypes;
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 AbstractTypeSupport<InstanceIdentifierSpecification> {
26 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
28 .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
32 protected SubstatementValidator getSubstatementValidator() {
33 return SUBSTATEMENT_VALIDATOR;
37 protected InstanceIdentifierSpecification createDeclared(
38 final StmtContext<QName, InstanceIdentifierSpecification, ?> ctx,
39 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
40 return substatements.isEmpty() ? new EmptyIdentifierSpecification(ctx.getRawArgument(), ctx.getArgument())
41 : new RegularInstanceIdentifierSpecification(ctx.getRawArgument(), ctx.getArgument(), substatements);
45 protected EffectiveStatement<QName, InstanceIdentifierSpecification> createEffective(
46 final Current<QName, InstanceIdentifierSpecification> stmt,
47 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
48 final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
49 BaseTypes.instanceIdentifierType(), stmt.argumentAsTypeQName());
51 // TODO: we could do better here for empty substatements, but its really splitting hairs
52 for (EffectiveStatement<?, ?> subStmt : substatements) {
53 if (subStmt instanceof RequireInstanceEffectiveStatement) {
54 builder.setRequireInstance(((RequireInstanceEffectiveStatement)subStmt).argument());
58 return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);