package org.opendaylight.yangtools.yang.parser.spi.meta;
import com.google.common.annotations.Beta;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Verify;
import org.opendaylight.yangtools.concepts.Immutable;
return ORIGINAL;
}
+ public static CopyHistory of(final CopyType copyType, final CopyHistory copyHistory) {
+ return ORIGINAL.append(copyType, copyHistory);
+ }
+
private static CopyHistory[] cacheArray(final CopyType lastOperation) {
final int ordinal = lastOperation.ordinal();
CopyHistory[] ret = CACHE[ordinal];
return VALUES[lastOperation];
}
- public CopyHistory append(final CopyType typeOfCopy, final CopyHistory toAppend) {
+ @VisibleForTesting
+ CopyHistory append(final CopyType typeOfCopy, final CopyHistory toAppend) {
final int newOperations = operations | toAppend.operations | typeOfCopy.bit();
if (newOperations == operations && typeOfCopy.ordinal() == lastOperation) {
return this;
@Override
public int hashCode() {
- return Integer.hashCode(operations | (lastOperation << Short.SIZE));
+ return Integer.hashCode(operations | lastOperation << Short.SIZE);
}
@Override
private final StatementDefinitionContext<A, D, E> definition;
private final StatementSourceReference statementDeclSource;
+ private final StmtContext<?, ?, ?> originalCtx;
+ private final CopyHistory copyHistory;
private final String rawArgument;
private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = ImmutableMultimap.of();
private StatementMap substatements = StatementMap.empty();
private Boolean supportedByFeatures = null;
- private CopyHistory copyHistory = CopyHistory.original();
private boolean isSupportedToBuildEffective = true;
private ModelProcessingPhase completedPhase = null;
- private StmtContext<?, ?, ?> originalCtx;
private D declaredInstance;
private E effectiveInstance;
private int order = 0;
this.definition = Preconditions.checkNotNull(def);
this.statementDeclSource = Preconditions.checkNotNull(ref);
this.rawArgument = def.internArgument(rawArgument);
+ this.copyHistory = CopyHistory.original();
+ this.originalCtx = null;
}
- StatementContextBase(final StatementContextBase<A, D, E> original) {
+ StatementContextBase(final StatementContextBase<A, D, E> original, final CopyType copyType) {
this.definition = Preconditions.checkNotNull(original.definition,
"Statement context definition cannot be null copying from: %s", original.getStatementSourceReference());
this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource,
"Statement context statementDeclSource cannot be null copying from: %s",
original.getStatementSourceReference());
this.rawArgument = original.rawArgument;
+ this.copyHistory = CopyHistory.of(copyType, original.getCopyHistory());
+
+ if (original.getOriginalCtx() != null) {
+ this.originalCtx = original.getOriginalCtx();
+ } else {
+ this.originalCtx = original;
+ }
}
@Override
return copyHistory;
}
- final void appendCopyHistory(final CopyType typeOfCopy, final CopyHistory toAppend) {
- copyHistory = copyHistory.append(typeOfCopy, toAppend);
- }
-
@Override
public StmtContext<?, ?, ?> getOriginalCtx() {
return originalCtx;
}
- final void setOriginalCtx(final StmtContext<?, ?, ?> originalCtx) {
- this.originalCtx = originalCtx;
- }
-
@Override
public void setOrder(final int order) {
this.order = order;
@SuppressWarnings("unchecked")
private SubstatementContext(final SubstatementContext<A, D, E> original, final QNameModule newQNameModule,
- final StatementContextBase<?, ?, ?> newParent, final CopyType typeOfCopy) {
- super(original);
+ final StatementContextBase<?, ?, ?> newParent, final CopyType copyType) {
+ super(original, copyType);
this.parent = Preconditions.checkNotNull(newParent);
if (newQNameModule != null) {
final SubstatementContext<A, D, E> copy = new SubstatementContext<>(this, newQNameModule, newParent, typeOfCopy);
- copy.appendCopyHistory(typeOfCopy, this.getCopyHistory());
-
- if (this.getOriginalCtx() != null) {
- copy.setOriginalCtx(this.getOriginalCtx());
- } else {
- copy.setOriginalCtx(this);
- }
-
definition().onStatementAdded(copy);
copy.copyStatements(this, newQNameModule, typeOfCopy);