From d9a2da069eb0b9284590819634bf07582ab56c14 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 2 Jul 2020 19:52:49 +0200 Subject: [PATCH] Consolidate UnionTypeEffectiveStatementImpl TypeEffectiveStatementImpl can easily support the case of an union type, migrate it. This was the last user of AbstractTypeStatementSupport, so remove that, too. JIRA: YANGTOOLS-1065 Change-Id: Ic69a9b4126062c06fe137c0b3144d431fd8124e9 Signed-off-by: Robert Varga --- .../type/AbstractTypeEffectiveStatement.java | 42 ------------------- .../type/AbstractTypeStatementSupport.java | 8 +++- .../type/UnionTypeEffectiveStatementImpl.java | 23 ---------- 3 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeEffectiveStatement.java delete mode 100644 yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeEffectiveStatement.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeEffectiveStatement.java deleted file mode 100644 index 54e9e112e3..0000000000 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeEffectiveStatement.java +++ /dev/null @@ -1,42 +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.TypeDefinition; -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.TypeEffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement; -import org.opendaylight.yangtools.yang.model.util.type.TypeBuilder; -import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; - -abstract class AbstractTypeEffectiveStatement> extends - DeclaredEffectiveStatementBase implements TypeEffectiveStatement { - private final @NonNull T typeDefinition; - - AbstractTypeEffectiveStatement( - final StmtContext> ctx, - final TypeBuilder builder) { - super(ctx); - - for (EffectiveStatement stmt : effectiveSubstatements()) { - if (stmt instanceof UnknownSchemaNode) { - builder.addUnknownSchemaNode((UnknownSchemaNode)stmt); - } - } - - typeDefinition = builder.build(); - } - - @Override - public final T getTypeDefinition() { - return typeDefinition; - } -} 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 ff7821dcd9..dbad0d5e81 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 @@ -260,7 +260,7 @@ abstract class AbstractTypeStatementSupport return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint64Builder((Uint64TypeDefinition) baseType, typeEffectiveSchemaPath(ctx))); } else if (baseType instanceof UnionTypeDefinition) { - return new UnionTypeEffectiveStatementImpl(ctx, (UnionTypeDefinition) baseType); + return createUnion(ctx, (UnionTypeDefinition) baseType, declared, substatements); } else { throw new IllegalStateException("Unhandled base type " + baseType); } @@ -374,4 +374,10 @@ abstract class AbstractTypeStatementSupport typeEffectiveSchemaPath(ctx))); } + private static @NonNull TypeEffectiveStatement createUnion(final StmtContext ctx, + final UnionTypeDefinition baseType, final TypeStatement declared, + final ImmutableList> substatements) { + return new TypeEffectiveStatementImpl<>(declared, substatements, RestrictedTypes.newUnionBuilder(baseType, + typeEffectiveSchemaPath(ctx))); + } } \ No newline at end of file diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java deleted file mode 100644 index d98465b067..0000000000 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java +++ /dev/null @@ -1,23 +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.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement; -import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; - -final class UnionTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement { - UnionTypeEffectiveStatementImpl( - final StmtContext> ctx, - final UnionTypeDefinition baseType) { - super(ctx, RestrictedTypes.newUnionBuilder(baseType, - AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx))); - } -} -- 2.36.6