Add Current.equalParentPath() 34/94834/7
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 09:20:48 +0000 (10:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 13:12:42 +0000 (14:12 +0100)
This check needs to be controlled by the reactor, hence move it
from BaseSchemaTreeStatementSupport to EffectiveStmtCtx.Current
as a default equalParentPath() method.

JIRA: YANGTOOLS-1208
Change-Id: I445789e9442db92b8081baad144f269ed14c35af
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/BaseSchemaTreeStatementSupport.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java

index a2d2ea2436afef36e411ddbaa388905423a8bb6e..20d536014136ca7e543ce2ba525bafa3f1daed64 100644 (file)
@@ -49,8 +49,9 @@ public abstract class BaseSchemaTreeStatementSupport<D extends DeclaredStatement
         public boolean canReuseCurrent(final Current<QName, D> copy, final Current<QName, D> current,
                 final Collection<? extends EffectiveStatement<?, ?>> substatements) {
             return equalHistory(copy.history(), current.history())
-                // FIXME: this should devolve to getArgument() equality
-                && copy.getSchemaPath().equals(current.getSchemaPath());
+                && copy.getArgument().equals(current.getArgument())
+                // FIXME: 8.0.0: eliminate this call
+                && copy.equalParentPath(current);
         }
 
         private static boolean equalHistory(final CopyHistory copy, final CopyHistory current) {
index 54e1c0231ebc1b25dab8fd6114b4603c63360df1..f389280535d597fed4b5b7a3aab169fa82361874 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Verify.verifyNotNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.VerifyException;
+import java.util.Objects;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -141,5 +142,19 @@ public interface EffectiveStmtCtx extends CommonStmtCtx, StmtContextCompat, Immu
         // FIXME: YANGTOOLS-1186: lob the Holy Hand Grenade of Antioch
         @Deprecated
         <E extends EffectiveStatement<A, D>> @NonNull StmtContext<A, D, E> caerbannog();
+
+        /**
+         * Compare another context for equality of {@code getEffectiveParent().getSchemaPath()}, just in a safer manner.
+         *
+         * @param other Other {@link Current}
+         * @return True if {@code other} has parent path equal to this context's parent path.
+         */
+        // FIXME: 8.0.0: Remove this method
+        default boolean equalParentPath(final Current<A, D> other) {
+            final Parent ours = effectiveParent();
+            final Parent theirs = other.effectiveParent();
+            return ours == theirs
+                || ours != null && theirs != null && Objects.equals(ours.schemaPath(), theirs.schemaPath());
+        }
     }
 }