Eliminate AbstractEffectiveModule.schemaTreeNamespace 59/93959/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 27 Nov 2020 10:29:19 +0000 (11:29 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 27 Nov 2020 13:16:00 +0000 (14:16 +0100)
We already have DefaultWithDataTree.WithSubstatements's indices,
hence there is no point in re-doing the same work.
Eliminate duplication and defer to our superclass.

JIRA: YANGTOOLS-1188
Change-Id: I9fd775be737ef603be7ae2a914dda2c2d87bf8a3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d8119ea5b4ead35fc3dfad489e80e49a034226f6)

yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java

index aab5cb9ac333835b953d68c5fee8a504e4a12408..603673e94e2a58035cc8e41a55ef7fa02d81ae1f 100644 (file)
@@ -14,12 +14,10 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
 import java.util.LinkedHashSet;
-import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
@@ -43,7 +41,6 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.stmt.ContactEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeAwareEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
@@ -51,8 +48,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.compat.NotificationNodeContainerCompat;
@@ -73,23 +68,12 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqual
     private final ImmutableSet<GroupingDefinition> groupings;
     private final ImmutableSet<UsesNode> uses;
     private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
-    private final ImmutableMap<QName, SchemaTreeEffectiveStatement<?>> schemaTreeNamespace;
 
     protected AbstractEffectiveModule(final D declared,
             final StmtContext<UnqualifiedQName, D, ? extends EffectiveStatement<UnqualifiedQName, ?>> ctx,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final String prefix) {
         super(declared, ctx, substatements);
 
-        // This check is rather weird, but comes from our desire to lower memory footprint while providing both
-        // EffectiveStatements and SchemaNode interfaces -- which do not overlap completely where child lookups are
-        // concerned. This ensures that we have SchemaTree index available for use with child lookups.
-        final Map<QName, SchemaTreeEffectiveStatement<?>> schemaTree =
-                createSchemaTreeNamespace(ctx.getStatementSourceReference(), effectiveSubstatements());
-        schemaTreeNamespace = ImmutableMap.copyOf(schemaTree);
-
-        // Data tree check, not currently used
-        createDataTreeNamespace(ctx.getStatementSourceReference(), schemaTree.values(), schemaTreeNamespace);
-
         this.prefix = requireNonNull(prefix);
 
         final Set<GroupingDefinition> mutableGroupings = new LinkedHashSet<>();
@@ -206,8 +190,7 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqual
     @Override
     @SuppressWarnings("checkstyle:hiddenField")
     public final Optional<DataSchemaNode> findDataChildByName(final QName name) {
-        final SchemaTreeEffectiveStatement<?> child = schemaTreeNamespace.get(requireNonNull(name));
-        return child instanceof DataSchemaNode ? Optional.of((DataSchemaNode) child) : Optional.empty();
+        return findDataSchemaNode(name);
     }
 
     @Override
@@ -220,16 +203,6 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqual
         return findFirstEffectiveSubstatementArgument(OpenConfigVersionEffectiveStatement.class);
     }
 
-    @Override
-    @SuppressWarnings("unchecked")
-    protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
-            final Class<N> namespace) {
-        if (SchemaTreeAwareEffectiveStatement.Namespace.class.equals(namespace)) {
-            return Optional.of((Map<K, V>) schemaTreeNamespace);
-        }
-        return super.getNamespaceContents(namespace);
-    }
-
     @Override
     public String toString() {
         return MoreObjects.toStringHelper(this).omitNullValues()