package org.opendaylight.yangtools.yang.model.api.stmt;
import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
@Beta
public interface DeviationEffectiveStatement extends EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> {
-
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.DEVIATION;
+ }
}
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
public interface DeviationStatement extends DocumentedDeclaredStatement<SchemaNodeIdentifier> {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.DEVIATION;
+ }
+
default @NonNull SchemaNodeIdentifier getTargetNode() {
// FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
return verifyNotNull(argument());
}
public abstract static class WithArgument<A> extends WithRawArgument<A> {
+ public abstract static class WithSubstatements<A> extends WithArgument<A> {
+ private final @NonNull Object substatements;
+
+ protected WithSubstatements(final StmtContext<A, ?, ?> context,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(context);
+ this.substatements = maskList(substatements);
+ }
+
+ @Override
+ public final Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
+ return unmaskList(substatements);
+ }
+ }
+
private final A argument;
protected WithArgument(final StmtContext<A, ?, ?> context) {
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviation;
import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DocumentedNodeMixin;
-final class DeviationEffectiveStatementImpl
- extends AbstractEffectiveDocumentedNodeWithoutStatus<SchemaNodeIdentifier, DeviationStatement>
- implements Deviation, DeviationEffectiveStatement, Immutable {
- private final SchemaPath targetPath;
- private final @NonNull ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
- private final ImmutableList<DeviateDefinition> deviateDefinitions;
-
- DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
- super(ctx);
- this.targetPath = ctx.getStatementArgument().asSchemaPath();
- this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
-
- List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
- }
- }
- unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
+final class DeviationEffectiveStatementImpl extends WithSubstatements<SchemaNodeIdentifier, DeviationStatement>
+ implements DeviationEffectiveStatement, Deviation,
+ DocumentedNodeMixin<SchemaNodeIdentifier, DeviationStatement> {
+ DeviationEffectiveStatementImpl(final DeviationStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared, substatements);
}
@Override
public SchemaPath getTargetPath() {
- return targetPath;
+ return argument().asSchemaPath();
}
@Override
public List<DeviateDefinition> getDeviates() {
- return deviateDefinitions;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return unknownSchemaNodes;
+ return filterEffectiveStatementsList(DeviateDefinition.class);
}
@Override
public int hashCode() {
- return Objects.hash(targetPath, deviateDefinitions, nullableDescription(), nullableReference());
+ return Objects.hash(getTargetPath(), getDeviates(), getDescription().orElse(null), getReference().orElse(null));
}
@Override
return false;
}
final DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
- return Objects.equals(targetPath, other.targetPath)
- && Objects.equals(deviateDefinitions, other.deviateDefinitions)
- && Objects.equals(nullableDescription(), other.nullableDescription())
- && Objects.equals(nullableReference(), other.nullableReference());
+ return Objects.equals(getTargetPath(), other.getTargetPath())
+ && Objects.equals(getDeviates(), other.getDeviates())
+ && Objects.equals(getDescription(), other.getDescription())
+ && Objects.equals(getReference(), other.getReference());
}
@Override
public String toString() {
return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
- + "targetPath=" + targetPath
- + ", deviates=" + deviateDefinitions
- + ", description=" + nullableDescription()
- + ", reference=" + nullableReference()
+ + "targetPath=" + getTargetPath()
+ + ", deviates=" + getDeviates()
+ + ", description=" + getDescription().orElse(null)
+ + ", reference=" + getReference().orElse(null)
+ "]";
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviation;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument.WithSubstatements;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier>
+final class DeviationStatementImpl extends WithSubstatements<SchemaNodeIdentifier>
implements DeviationStatement {
- DeviationStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
- super(context);
+ DeviationStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(context, substatements);
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviation;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.stmt.DeviationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
public final class DeviationStatementSupport
- extends AbstractStatementSupport<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> {
+ extends BaseStatementSupport<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
.DEVIATION)
.addOptional(YangStmtMapping.DESCRIPTION)
return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
}
- @Override
- public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
- return new DeviationStatementImpl(ctx);
- }
-
- @Override
- public DeviationEffectiveStatement createEffective(
- final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx) {
- return new DeviationEffectiveStatementImpl(ctx);
- }
-
@Override
public void onFullDefinitionDeclared(
final Mutable<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx) {
protected SubstatementValidator getSubstatementValidator() {
return SUBSTATEMENT_VALIDATOR;
}
+
+ @Override
+ protected DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new DeviationStatementImpl(ctx, substatements);
+ }
+
+ @Override
+ protected DeviationStatement createEmptyDeclared(
+ final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+ return new DeviationStatementImpl(ctx, ImmutableList.of());
+ }
+
+ @Override
+ protected DeviationEffectiveStatement createEffective(
+ final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
+ final DeviationStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new DeviationEffectiveStatementImpl(declared, substatements);
+ }
+
+ @Override
+ protected DeviationEffectiveStatement createEmptyEffective(
+ final StmtContext<SchemaNodeIdentifier, DeviationStatement, DeviationEffectiveStatement> ctx,
+ final DeviationStatement declared) {
+ return new DeviationEffectiveStatementImpl(declared, ImmutableList.of());
+ }
}
\ No newline at end of file