import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.Beta;
+import com.google.common.base.VerifyException;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
/**
* Class providing necessary support for processing a YANG statement. This class is intended to be subclassed
implements StatementDefinition, StatementFactory<A, D, E>, StatementSupport<A, D, E> {
private final @NonNull StatementDefinition type;
+ private final @NonNull CopyPolicy copyPolicy;
- protected AbstractStatementSupport(final StatementDefinition publicDefinition) {
+ @Beta
+ protected AbstractStatementSupport(final StatementDefinition publicDefinition, final CopyPolicy copyPolicy) {
this.type = requireNonNull(publicDefinition);
+ this.copyPolicy = requireNonNull(copyPolicy);
checkArgument(publicDefinition != this);
}
return type;
}
+ @Override
+ public final CopyPolicy copyPolicy() {
+ return copyPolicy;
+ }
+
+ @Override
+ public final StmtContext<?, ?, ?> effectiveCopyOf(final StmtContext<?, ?, ?> stmt, final Mutable<?, ?, ?> parent,
+ final CopyType copyType, final QNameModule targetModule) {
+ switch (copyPolicy) {
+ case CONTEXT_INDEPENDENT:
+ return stmt;
+ case DECLARED_COPY:
+ // FIXME: YANGTOOLS-1195: this is too harsh, we need to make a callout to subclass methods so they
+ // actually examine the differences.
+ return parent.childCopyOf(stmt, copyType, targetModule);
+ default:
+ throw new VerifyException("Attempted to apply " + copyPolicy);
+ }
+ }
+
@Override
public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
// NOOP for most implementations
@Override
public boolean hasArgumentSpecificSupports() {
- // Most of statement supports don't have any argument specific
- // supports, so return 'false'.
+ // Most of statement supports don't have any argument specific supports, so return 'false'.
return false;
}
@Override
public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
- // Most of statement supports don't have any argument specific
- // supports, so return null.
+ // Most of statement supports don't have any argument specific supports, so return null.
return null;
}