Allow derived context to be reused
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / AbstractStatementSupport.java
index ba8b61fed58a870f9295135352f84f35f1db7701..acc2f2880be740ce69b9463ec0e1db9f05a02d92 100644 (file)
@@ -61,16 +61,15 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
         return createEffective(stmt, substatements);
     }
 
-    @Override
-    public final E createEffective(final Current<A, D> stmt,
-            final Collection<? extends EffectiveStatement<?, ?>> substatements) {
-        // This copy should be a no-op
-        return createEffective(stmt, ImmutableList.copyOf(substatements));
-    }
-
     protected abstract @NonNull E createEffective(@NonNull Current<A, D> stmt,
             @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);
 
+    @Override
+    public E copyEffective(final Current<A, D> stmt, final E original) {
+        // Most implementations are only interested in substatements. copyOf() here should be a no-op
+        return createEffective(stmt, ImmutableList.copyOf(original.effectiveSubstatements()));
+    }
+
     /**
      * Give statement support a hook to transform statement contexts before they are built. Default implementation
      * does nothing, but note {@code augment} statement performs a real transformation.
@@ -86,7 +85,7 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
 
     // FIXME: add documentation
     public static final <E extends EffectiveStatement<?, ?>> @Nullable E findFirstStatement(
-            final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<E> type) {
+            final Collection<? extends EffectiveStatement<?, ?>> statements, final Class<E> type) {
         for (EffectiveStatement<?, ?> stmt : statements) {
             if (type.isInstance(stmt)) {
                 return type.cast(stmt);
@@ -97,7 +96,7 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
 
     // FIXME: add documentation
     public static final <A, E extends EffectiveStatement<A, ?>> A findFirstArgument(
-            final ImmutableList<? extends EffectiveStatement<?, ?>> statements, final Class<@NonNull E> type,
+            final Collection<? extends EffectiveStatement<?, ?>> statements, final Class<@NonNull E> type,
                     final A defValue) {
         final @Nullable E stmt = findFirstStatement(statements, type);
         return stmt != null ? stmt.argument() : defValue;