Migrate InstanceIdentifierSpecificationSupport 03/90903/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 22:08:34 +0000 (00:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 22:31:55 +0000 (00:31 +0200)
InstanceIdentifierSpecificationSupport can use memory-efficient
representation through BaseStatementSupport. Furthermore we can reuse
TypeEffectiveStatementImpl instead of brewing a separate effective
implementation.

JIRA: YANGTOOLS-1065
Change-Id: I821172baf33bd639fd52e02160db7122b4f53367
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/EmptyIdentifierSpecification.java [moved from yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierSpecificationImpl.java with 54% similarity]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierSpecificationEffectiveStatement.java [deleted file]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierSpecificationSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/RegularInstanceIdentifierSpecification.java [new file with mode: 0644]

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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,
@@ -8,12 +8,11 @@
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-final class InstanceIdentifierSpecificationImpl extends AbstractDeclaredStatement<String>
-        implements InstanceIdentifierSpecification {
-    InstanceIdentifierSpecificationImpl(final StmtContext<String, InstanceIdentifierSpecification, ?> ctx) {
+final class EmptyIdentifierSpecification extends WithRawStringArgument implements InstanceIdentifierSpecification {
+    EmptyIdentifierSpecification(final StmtContext<String, ?, ?> ctx) {
         super(ctx);
     }
 }
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierSpecificationEffectiveStatement.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/InstanceIdentifierSpecificationEffectiveStatement.java
deleted file mode 100644 (file)
index 0dfbf4f..0000000
+++ /dev/null
@@ -1,52 +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.InstanceIdentifierSpecification;
-import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBuilder;
-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 InstanceIdentifierSpecificationEffectiveStatement
-        extends DeclaredEffectiveStatementBase<String, InstanceIdentifierSpecification>
-        implements TypeEffectiveStatement<InstanceIdentifierSpecification> {
-
-    private final @NonNull InstanceIdentifierTypeDefinition typeDefinition;
-
-    InstanceIdentifierSpecificationEffectiveStatement(final StmtContext<String,
-            InstanceIdentifierSpecification, EffectiveStatement<String, InstanceIdentifierSpecification>> ctx) {
-        super(ctx);
-
-        final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
-            BaseTypes.instanceIdentifierType(), ctx.getSchemaPath().get());
-
-        for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
-            if (stmt instanceof RequireInstanceEffectiveStatement) {
-                builder.setRequireInstance(((RequireInstanceEffectiveStatement)stmt).argument());
-            }
-            if (stmt instanceof UnknownSchemaNode) {
-                builder.addUnknownSchemaNode((UnknownSchemaNode)stmt);
-            }
-        }
-
-        typeDefinition = builder.build();
-    }
-
-    @Override
-    public InstanceIdentifierTypeDefinition getTypeDefinition() {
-        return typeDefinition;
-    }
-}
index be40ac355a6e8e6cec466e91be9d2b99a9dff9e7..19dfe29ff90a61fab8068ab4b4bb4fb5ed8c3e8a 100644 (file)
@@ -7,14 +7,20 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
 
+import com.google.common.collect.ImmutableList;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.stmt.RequireInstanceEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.InstanceIdentifierTypeBuilder;
+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.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 
-final class InstanceIdentifierSpecificationSupport extends AbstractStatementSupport<String,
+final class InstanceIdentifierSpecificationSupport extends BaseStatementSupport<String,
         InstanceIdentifierSpecification, EffectiveStatement<String, InstanceIdentifierSpecification>> {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
         YangStmtMapping.TYPE)
@@ -31,20 +37,47 @@ final class InstanceIdentifierSpecificationSupport extends AbstractStatementSupp
     }
 
     @Override
-    public InstanceIdentifierSpecification createDeclared(
+    protected SubstatementValidator getSubstatementValidator() {
+        return SUBSTATEMENT_VALIDATOR;
+    }
+
+    @Override
+    protected InstanceIdentifierSpecification createDeclared(
+            final StmtContext<String, InstanceIdentifierSpecification, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularInstanceIdentifierSpecification(ctx, substatements);
+    }
+
+    @Override
+    protected InstanceIdentifierSpecification createEmptyDeclared(
             final StmtContext<String, InstanceIdentifierSpecification, ?> ctx) {
-        return new InstanceIdentifierSpecificationImpl(ctx);
+        return new EmptyIdentifierSpecification(ctx);
     }
 
     @Override
-    public EffectiveStatement<String, InstanceIdentifierSpecification> createEffective(
+    protected EffectiveStatement<String, InstanceIdentifierSpecification> createEffective(
             final StmtContext<String, InstanceIdentifierSpecification,
-            EffectiveStatement<String, InstanceIdentifierSpecification>> ctx) {
-        return new InstanceIdentifierSpecificationEffectiveStatement(ctx);
+                EffectiveStatement<String, InstanceIdentifierSpecification>> ctx,
+            final InstanceIdentifierSpecification declared,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        final InstanceIdentifierTypeBuilder builder = RestrictedTypes.newInstanceIdentifierBuilder(
+            BaseTypes.instanceIdentifierType(), ctx.getSchemaPath().get());
+
+        for (EffectiveStatement<?, ?> stmt : substatements) {
+            if (stmt instanceof RequireInstanceEffectiveStatement) {
+                builder.setRequireInstance(((RequireInstanceEffectiveStatement)stmt).argument());
+            }
+        }
+
+        return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
     }
 
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
+    protected EffectiveStatement<String, InstanceIdentifierSpecification> createEmptyEffective(
+            final StmtContext<String, InstanceIdentifierSpecification,
+                EffectiveStatement<String, InstanceIdentifierSpecification>> ctx,
+            final InstanceIdentifierSpecification declared) {
+        // TODO: we could do better here, but its really splitting hairs
+        return createEffective(ctx, declared, ImmutableList.of());
     }
 }
\ No newline at end of file
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/RegularInstanceIdentifierSpecification.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/RegularInstanceIdentifierSpecification.java
new file mode 100644 (file)
index 0000000..b97d47a
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.InstanceIdentifierSpecification;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+final class RegularInstanceIdentifierSpecification extends WithSubstatements
+        implements InstanceIdentifierSpecification {
+    RegularInstanceIdentifierSpecification(final StmtContext<String, ?, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        super(ctx, substatements);
+    }
+}