Fix AbstractResumedStatement reparent 53/87253/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Jan 2020 17:34:29 +0000 (18:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 29 Jan 2020 11:03:23 +0000 (12:03 +0100)
When we are reparenting AbstractResumedStatement we need to make
sure the state is copied correctly. This shows that it cannot
be semantically copied, hence it does not make sense to track
previous/original context.

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

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/AbstractResumedStatement.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java

index ddfe0123dd89efb2000922cb6ea908d159917aaf..7c7f0db7b66b956d6d14559bd57015efe449d5bb 100644 (file)
@@ -36,18 +36,15 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter.Resumed
 abstract class AbstractResumedStatement<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
         extends StatementContextBase<A, D, E> implements ResumedStatement {
     private final @NonNull StatementSourceReference statementDeclSource;
-    private final StmtContext<?, ?, ?> originalCtx;
-    private final StmtContext<?, ?, ?> prevCopyCtx;
     private final String rawArgument;
 
     private StatementMap substatements = StatementMap.empty();
 
+    // Copy constructor
     AbstractResumedStatement(final AbstractResumedStatement<A, D, E> original) {
         super(original);
         this.statementDeclSource = original.statementDeclSource;
         this.rawArgument = original.rawArgument;
-        this.originalCtx = original.getOriginalCtx().orElse(original);
-        this.prevCopyCtx = original;
         this.substatements = original.substatements;
     }
 
@@ -56,8 +53,6 @@ abstract class AbstractResumedStatement<A, D extends DeclaredStatement<A>, E ext
         super(def);
         this.statementDeclSource = requireNonNull(ref);
         this.rawArgument = def.internArgument(rawArgument);
-        this.originalCtx = null;
-        this.prevCopyCtx = null;
     }
 
     AbstractResumedStatement(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
@@ -65,18 +60,16 @@ abstract class AbstractResumedStatement<A, D extends DeclaredStatement<A>, E ext
         super(def, CopyHistory.of(copyType, CopyHistory.original()));
         this.statementDeclSource = requireNonNull(ref);
         this.rawArgument = rawArgument;
-        this.originalCtx = null;
-        this.prevCopyCtx = null;
     }
 
     @Override
     public final Optional<StmtContext<?, ?, ?>> getOriginalCtx() {
-        return Optional.ofNullable(originalCtx);
+        return Optional.empty();
     }
 
     @Override
     public final Optional<? extends StmtContext<?, ?, ?>> getPreviousCopyCtx() {
-        return Optional.ofNullable(prevCopyCtx);
+        return Optional.empty();
     }
 
     @Override
index 50ce3ca06157e1f017dc331c9b39281799dffca6..f5824cdd2d9ab58f87285daae887e691bf2eb62f 100644 (file)
@@ -163,9 +163,16 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     // a bit in terms of size -- but those are only a few and SchemaPath is on its way out anyway.
     private volatile SchemaPath schemaPath;
 
+    // Copy constructor used by subclasses to implement reparent()
     StatementContextBase(final StatementContextBase<A, D, E> original) {
         this.copyHistory = original.copyHistory;
         this.definition = original.definition;
+
+        this.isSupportedToBuildEffective = original.isSupportedToBuildEffective;
+        this.fullyDefined = original.fullyDefined;
+        this.completedPhase = original.completedPhase;
+        this.declaredInstance = original.declaredInstance;
+        this.flags = original.flags;
     }
 
     StatementContextBase(final StatementDefinitionContext<A, D, E> def) {