From: Robert Varga Date: Thu, 2 Jul 2020 18:14:41 +0000 (+0200) Subject: Consolidate LeafrefTypeEffectiveStatementImpl X-Git-Tag: v5.0.4~27 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=6e1828c546d431a2777f0ce0d818ea92412b2ab5;p=yangtools.git Consolidate LeafrefTypeEffectiveStatementImpl TypeEffectiveStatementImpl can easily support the case of a leafref type, migrate it. JIRA: YANGTOOLS-1065 Change-Id: I39bd8f7520c4c1678725ab2dfb1d805fc07e8034 Signed-off-by: Robert Varga --- diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java index 5d2aaba39c..f6266f1703 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java @@ -61,6 +61,7 @@ import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBui import org.opendaylight.yangtools.yang.model.util.type.InvalidLengthConstraintException; import org.opendaylight.yangtools.yang.model.util.type.LengthRestrictedTypeBuilder; import org.opendaylight.yangtools.yang.model.util.type.RangeRestrictedTypeBuilder; +import org.opendaylight.yangtools.yang.model.util.type.RequireInstanceRestrictedTypeBuilder; import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes; import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport; import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace; @@ -259,7 +260,7 @@ abstract class AbstractTypeStatementSupport return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt64Builder((Int64TypeDefinition) baseType, typeEffectiveSchemaPath(ctx))); } else if (baseType instanceof LeafrefTypeDefinition) { - return new LeafrefTypeEffectiveStatementImpl(ctx, (LeafrefTypeDefinition) baseType); + return createLeafref(ctx, (LeafrefTypeDefinition) baseType, declared, substatements); } else if (baseType instanceof StringTypeDefinition) { return new StringTypeEffectiveStatementImpl(ctx, (StringTypeDefinition) baseType); } else if (baseType instanceof Uint8TypeDefinition) { @@ -482,6 +483,21 @@ abstract class AbstractTypeStatementSupport return new TypeEffectiveStatementImpl<>(declared, substatements, builder); } + private static @NonNull TypeEffectiveStatement createLeafref(final StmtContext ctx, + final LeafrefTypeDefinition baseType, final TypeStatement declared, + final ImmutableList> substatements) { + final RequireInstanceRestrictedTypeBuilder builder = + RestrictedTypes.newLeafrefBuilder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)); + + for (final EffectiveStatement stmt : substatements) { + if (stmt instanceof RequireInstanceEffectiveStatement) { + builder.setRequireInstance(((RequireInstanceEffectiveStatement) stmt).argument()); + } + } + + return new TypeEffectiveStatementImpl<>(declared, substatements, builder); + } + private static @NonNull TypeEffectiveStatement createUnion(final StmtContext ctx, final UnionTypeDefinition baseType, final TypeStatement declared, final ImmutableList> substatements) { diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/LeafrefTypeEffectiveStatementImpl.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/LeafrefTypeEffectiveStatementImpl.java deleted file mode 100644 index f5c9a67f72..0000000000 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/LeafrefTypeEffectiveStatementImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type; - -import org.eclipse.jdt.annotation.NonNull; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceEffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.type.RequireInstanceRestrictedTypeBuilder; -import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes; -import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; - -final class LeafrefTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase - implements TypeEffectiveStatement { - - private final @NonNull LeafrefTypeDefinition typeDefinition; - - LeafrefTypeEffectiveStatementImpl( - final StmtContext> ctx, - final LeafrefTypeDefinition baseType) { - super(ctx); - - final RequireInstanceRestrictedTypeBuilder builder = - RestrictedTypes.newLeafrefBuilder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)); - - for (final EffectiveStatement stmt : effectiveSubstatements()) { - if (stmt instanceof RequireInstanceEffectiveStatement) { - builder.setRequireInstance(((RequireInstanceEffectiveStatement) stmt).argument()); - } else if (stmt instanceof UnknownSchemaNode) { - builder.addUnknownSchemaNode((UnknownSchemaNode)stmt); - } - } - - typeDefinition = builder.build(); - } - - @Override - public LeafrefTypeDefinition getTypeDefinition() { - return typeDefinition; - } -}