Consolidate UnionTypeEffectiveStatementImpl 87/90887/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 17:52:49 +0000 (19:52 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 22:31:55 +0000 (00:31 +0200)
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 <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeEffectiveStatement.java [deleted file]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/UnionTypeEffectiveStatementImpl.java [deleted file]

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 (file)
index 54e9e11..0000000
+++ /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<T extends TypeDefinition<T>> extends
-        DeclaredEffectiveStatementBase<String, TypeStatement> implements TypeEffectiveStatement<TypeStatement> {
-    private final @NonNull T typeDefinition;
-
-    AbstractTypeEffectiveStatement(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final TypeBuilder<T> 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;
-    }
-}
index ff7821dcd947c56c2e2aa5a92de156564936c2f6..dbad0d5e8191cd3f4b316f64c2894c868a44accb 100644 (file)
@@ -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<TypeStatement> createUnion(final StmtContext<?, ?, ?> ctx,
+            final UnionTypeDefinition baseType, final TypeStatement declared,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> 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 (file)
index d98465b..0000000
+++ /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<UnionTypeDefinition> {
-    UnionTypeEffectiveStatementImpl(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final UnionTypeDefinition baseType) {
-        super(ctx, RestrictedTypes.newUnionBuilder(baseType,
-            AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)));
-    }
-}