import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.util.OptionalBoolean;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
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 Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.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;
+
+ // BooleanFields value
+ private byte supportedByFeatures;
StatementContextBase(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
final String rawArgument) {
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());
+ this.originalCtx = original.getOriginalCtx().orElse(original);
}
@Override
@Override
public boolean isSupportedByFeatures() {
- if (supportedByFeatures == null) {
- final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
- SupportedFeatures.SUPPORTED_FEATURES);
- // If the set of supported features has not been provided, all features are supported by default.
- supportedByFeatures = supportedFeatures == null ? Boolean.TRUE
- : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+ if (OptionalBoolean.isPresent(supportedByFeatures)) {
+ return OptionalBoolean.get(supportedByFeatures);
+ }
+
+ if (isIgnoringIfFeatures()) {
+ supportedByFeatures = OptionalBoolean.of(true);
+ return true;
+ }
+
+ final boolean isParentSupported = isParentSupportedByFeatures();
+ /*
+ * If parent is not supported, then this context is also not supported.
+ * So we do not need to check if-features statements of this context and
+ * we can return false immediately.
+ */
+ if (!isParentSupported) {
+ supportedByFeatures = OptionalBoolean.of(false);
+ return false;
}
- return supportedByFeatures.booleanValue();
+ /*
+ * If parent is supported, we need to check if-features statements of
+ * this context.
+ */
+ // If the set of supported features has not been provided, all features are supported by default.
+ final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
+ SupportedFeatures.SUPPORTED_FEATURES);
+ final boolean ret = supportedFeatures == null ? true
+ : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+
+ supportedByFeatures = OptionalBoolean.of(ret);
+ return ret;
}
+ protected abstract boolean isParentSupportedByFeatures();
+
+ protected abstract boolean isIgnoringIfFeatures();
+
+ protected abstract boolean isIgnoringConfig();
+
@Override
public boolean isSupportedToBuildEffective() {
return isSupportedToBuildEffective;
}
@Override
- public void appendCopyHistory(final CopyType typeOfCopy, final CopyHistory toAppend) {
- copyHistory = copyHistory.append(typeOfCopy, toAppend);
- }
-
- @Override
- public StmtContext<?, ?, ?> getOriginalCtx() {
- return originalCtx;
- }
-
- @Override
- public void setOriginalCtx(final StmtContext<?, ?, ?> originalCtx) {
- this.originalCtx = originalCtx;
- }
-
- @Override
- public void setOrder(final int order) {
- this.order = order;
- }
-
- @Override
- public int getOrder() {
- return order;
+ public Optional<StmtContext<?, ?, ?>> getOriginalCtx() {
+ return Optional.ofNullable(originalCtx);
}
@Override
final Optional<StatementContextBase<?, ?, ?>> implicitStatement = definition.beforeSubStatementCreated(this,
offset, def, ref, argument);
- if(implicitStatement.isPresent()) {
- final StatementContextBase<?, ?, ?> presentImplicitStmt = implicitStatement.get();
- return presentImplicitStmt.createSubstatement(offset, def, ref, argument);
+ if (implicitStatement.isPresent()) {
+ return implicitStatement.get().createSubstatement(offset, def, ref, argument);
}
final StatementContextBase<CA, CD, CE> ret = new SubstatementContext<>(this, def, ref, argument);