+ /**
+ * Attach an effective copy of this statement. This essentially acts as a map, where we make a few assumptions:
+ * <ul>
+ * <li>{@code copy} and {@code this} statement share {@link #getOriginalCtx()} if it exists</li>
+ * <li>{@code copy} did not modify any statements relative to {@code this}</li>
+ * </ul>
+ *
+ * @param state effective statement state, acting as a lookup key
+ * @param stmt New copy to append
+ * @return {@code stmt} or a previously-created instances with the same {@code state}
+ */
+ @SuppressWarnings("unchecked")
+ final @NonNull E attachEffectiveCopy(final @NonNull EffectiveStatementState state, final @NonNull E stmt) {
+ final Object local = effectiveInstance;
+ final EffectiveInstances<E> instances;
+ if (local instanceof EffectiveInstances) {
+ instances = (EffectiveInstances<E>) local;
+ } else {
+ effectiveInstance = instances = new EffectiveInstances<>((E) local);
+ }
+ return instances.attachCopy(state, stmt);
+ }
+