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.DeclarationReference;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
18 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
19 import org.opendaylight.yangtools.yang.model.ri.type.InstanceIdentifierTypeBuilder;
20 import org.opendaylight.yangtools.yang.model.ri.type.RestrictedTypes;
21 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
26 final class InstanceIdentifierSpecificationSupport
27 extends AbstractTypeSupport<InstanceIdentifierSpecification> {
28 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
29 SubstatementValidator.builder(YangStmtMapping.TYPE).addOptional(YangStmtMapping.REQUIRE_INSTANCE).build();
31 InstanceIdentifierSpecificationSupport(final YangParserConfiguration config) {
32 super(config, SUBSTATEMENT_VALIDATOR);
36 protected InstanceIdentifierSpecification createDeclared(final BoundStmtCtx<QName> ctx,
37 final ImmutableList<DeclaredStatement<?>> substatements) {
38 return substatements.isEmpty() ? new EmptyIdentifierSpecification(ctx.getRawArgument(), ctx.getArgument())
39 : new RegularInstanceIdentifierSpecification(ctx.getRawArgument(), ctx.getArgument(), substatements);
43 protected InstanceIdentifierSpecification attachDeclarationReference(final InstanceIdentifierSpecification stmt,
44 final DeclarationReference reference) {
45 return new RefInstanceIdentifierSpecification(stmt, reference);
49 protected EffectiveStatement<QName, InstanceIdentifierSpecification> createEffective(
50 final Current<QName, InstanceIdentifierSpecification> stmt,
51 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
52 final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
53 BaseTypes.instanceIdentifierType(), stmt.argumentAsTypeQName());
55 // TODO: we could do better here for empty substatements, but its really splitting hairs
56 for (EffectiveStatement<?, ?> subStmt : substatements) {
57 if (subStmt instanceof RequireInstanceEffectiveStatement) {
58 builder.setRequireInstance(((RequireInstanceEffectiveStatement)subStmt).argument());
62 return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);