From: Robert Varga Date: Thu, 8 Jun 2017 17:02:49 +0000 (+0200) Subject: BUG-6972: Do not allow root StmtContext to be copied X-Git-Tag: release/carbon-sr1~6 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=177924d2a8d4805768cea6b06f1e692ad7822cb9;hp=28fc34ebe5c72b6d76c0c392e7240cf510f4ead7;p=yangtools.git BUG-6972: Do not allow root StmtContext to be copied It cannot be targeted, hence it does not make sense to copy it. Removes a chunk of duplicate code and takes this class out of the picture where copy operations are concerned. Change-Id: I7a8d46ba59658a534534cd8204c43d894d017247 Signed-off-by: Robert Varga (cherry picked from commit 36a5673da061c01ed2c3c58e4e3b418b01e9876a) --- diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 4bf2541ffc..a54ae2744a 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -116,8 +116,18 @@ public interface StmtContext, E extends Effect Collection> getEffectOfStatement(); + /** + * @return copy of this considering {@link CopyType} (augment, uses) + * + * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException + */ Mutable createCopy(StatementContextBase newParent, CopyType typeOfCopy); + /** + * @return copy of this considering {@link CopyType} (augment, uses) + * + * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException + */ Mutable createCopy(QNameModule newQNameModule, StatementContextBase newParent, CopyType typeOfCopy); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java index 3d1bef5e2a..1246b9a835 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java @@ -31,7 +31,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext; import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference; @@ -71,29 +70,6 @@ public class RootStatementContext, E extends E this.setRootIdentifier(identifier); } - private RootStatementContext(final RootStatementContext original, final QNameModule newQNameModule, - final CopyType typeOfCopy) { - super(original); - - sourceContext = Preconditions.checkNotNull(original.sourceContext); - this.argument = original.argument; - - final Collection> declared = original.mutableDeclaredSubstatements(); - final Collection> effective = original.mutableEffectiveSubstatements(); - final Collection> buffer = new ArrayList<>(declared.size() + effective.size()); - - for (final Mutable stmtContext : declared) { - if (stmtContext.isSupportedByFeatures()) { - buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy)); - } - } - for (final StmtContext stmtContext : effective) { - buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy)); - } - - addEffectiveSubstatements(buffer); - } - /** * @return null as root cannot have parent */ @@ -137,36 +113,16 @@ public class RootStatementContext, E extends E return argument; } - /** - * @return copy of this considering {@link CopyType} (augment, uses) - * - * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException - */ @Override public StatementContextBase createCopy(final StatementContextBase newParent, final CopyType typeOfCopy) { - return createCopy(null, newParent, typeOfCopy); + throw new UnsupportedOperationException("Root context cannot be copied"); } - /** - * @return copy of this considering {@link CopyType} (augment, uses) - * - * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException - */ @Override public StatementContextBase createCopy(final QNameModule newQNameModule, final StatementContextBase newParent, final CopyType typeOfCopy) { - final RootStatementContext copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy); - - copy.appendCopyHistory(typeOfCopy, this.getCopyHistory()); - - if (this.getOriginalCtx() != null) { - copy.setOriginalCtx(this.getOriginalCtx()); - } else { - copy.setOriginalCtx(this); - } - definition().onStatementAdded(copy); - return copy; + throw new UnsupportedOperationException("Root context cannot be copied"); } @Nonnull