import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
@Beta
public interface NotificationEffectiveStatement extends SchemaTreeEffectiveStatement<NotificationStatement>,
DataTreeAwareEffectiveStatement<QName, NotificationStatement> {
-
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.NOTIFICATION;
+ }
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
public interface NotificationStatement extends DocumentedDeclaredStatement.WithStatus<QName>,
DataDefinitionAwareDeclaredStatement.WithReusableDefinitions<QName>, IfFeatureAwareDeclaredStatement<QName>,
MustStatementAwareDeclaredStatement<QName> {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.NOTIFICATION;
+ }
+
default @NonNull QName getName() {
// FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
return verifyNotNull(argument());
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Status;
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.NotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseQNameStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
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.meta.StmtContextUtils;
abstract class AbstractNotificationStatementSupport
- extends AbstractQNameStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
+ extends BaseQNameStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
AbstractNotificationStatementSupport() {
super(YangStmtMapping.NOTIFICATION);
}
}
@Override
- public final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
- return new NotificationStatementImpl(ctx);
+ protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
}
+
+ @Override
+ protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
+ return new EmptyNotificationStatement(ctx.coerceStatementArgument());
+ }
+
+ @Override
+ protected final NotificationEffectiveStatement createEffective(
+ final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
+ final NotificationStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ checkEffective(ctx);
+
+ final int flags = new FlagsBuilder()
+ .setHistory(ctx.getCopyHistory())
+ .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
+ .toFlags();
+
+ return new NotificationEffectiveStatementImpl(declared, flags, ctx, substatements);
+ }
+
+ @Override
+ protected final NotificationEffectiveStatement createEmptyEffective(
+ final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
+ final NotificationStatement declared) {
+ return createEffective(ctx, declared, ImmutableList.of());
+ }
+
+ abstract void checkEffective(StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx);
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithQNameArgument;
-final class NotificationStatementImpl extends AbstractDeclaredStatement<QName> implements NotificationStatement {
- NotificationStatementImpl(final StmtContext<QName, NotificationStatement, ?> context) {
- super(context);
+final class EmptyNotificationStatement extends WithQNameArgument implements NotificationStatement {
+ EmptyNotificationStatement(final QName argument) {
+ super(argument);
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
-import com.google.common.collect.ImmutableSet;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.VarHandle;
-import java.util.LinkedHashSet;
+import com.google.common.collect.ImmutableList;
import java.util.Objects;
-import java.util.Set;
+import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedDataNodeContainer;
-import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
-import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultWithDataTree.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.AugmentationTargetMixin;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.CopyableMixin;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DataNodeContainerMixin;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.MustConstraintMixin;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.SchemaNodeMixin;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
final class NotificationEffectiveStatementImpl
- extends AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement>
- implements NotificationDefinition, NotificationEffectiveStatement {
- private static final VarHandle MUST_CONSTRAINTS;
+ extends WithSubstatements<QName, NotificationStatement, NotificationEffectiveStatement>
+ implements NotificationDefinition, NotificationEffectiveStatement,
+ SchemaNodeMixin<QName, NotificationStatement>, DataNodeContainerMixin<QName, NotificationStatement>,
+ AugmentationTargetMixin<QName, NotificationStatement>, CopyableMixin<QName, NotificationStatement>,
+ MustConstraintMixin<QName, NotificationStatement> {
- static {
- try {
- MUST_CONSTRAINTS = MethodHandles.lookup().findVarHandle(
- NotificationEffectiveStatementImpl.class, "mustConstraints", ImmutableSet.class);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
-
- private final @NonNull QName qname;
private final @NonNull SchemaPath path;
- private final ImmutableSet<AugmentationSchemaNode> augmentations;
- private final boolean augmenting;
- private final boolean addedByUses;
+ private final int flags;
- @SuppressWarnings("unused")
- private volatile ImmutableSet<MustDefinition> mustConstraints;
-
- NotificationEffectiveStatementImpl(
- final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
- super(ctx);
- this.qname = ctx.coerceStatementArgument();
+ NotificationEffectiveStatementImpl(final NotificationStatement declared, final int flags,
+ final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared, ctx, substatements);
this.path = ctx.getSchemaPath().get();
-
- // initSubstatementCollections
- final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>();
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof AugmentationSchemaNode) {
- final AugmentationSchemaNode augmentationSchema = (AugmentationSchemaNode) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
- }
- }
- this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-
- // initCopyType
- final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
- if (copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
- this.augmenting = true;
- this.addedByUses = true;
- } else {
- this.augmenting = copyTypesFromOriginal.contains(CopyType.ADDED_BY_AUGMENTATION);
- this.addedByUses = copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES);
- }
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return path;
+ this.flags = flags;
}
@Override
- public ImmutableSet<MustDefinition> getMustConstraints() {
- return derivedSet(MUST_CONSTRAINTS, MustDefinition.class);
+ public @NonNull QName argument() {
+ return getQName();
}
@Override
- public Set<AugmentationSchemaNode> getAvailableAugmentations() {
- return augmentations;
+ public Optional<DataSchemaNode> findDataChildByName(final QName name) {
+ return findDataSchemaNode(name);
}
- @Deprecated
@Override
- public boolean isAugmenting() {
- return augmenting;
+ public int flags() {
+ return flags;
}
- @Deprecated
@Override
- public boolean isAddedByUses() {
- return addedByUses;
+ public SchemaPath getPath() {
+ return path;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Objects.hashCode(qname);
+ result = prime * result + Objects.hashCode(getQName());
result = prime * result + Objects.hashCode(path);
return result;
}
if (this == obj) {
return true;
}
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
+ if (obj == null || getClass() != obj.getClass()) {
return false;
}
final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
- return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
+ return Objects.equals(getQName(), other.getQName()) && Objects.equals(path, other.path);
}
@Override
public String toString() {
- return NotificationEffectiveStatementImpl.class.getSimpleName() + "[qname=" + qname + ", path=" + path + "]";
+ return NotificationEffectiveStatementImpl.class.getSimpleName() + "[qname=" + getQName() + ", path=" + path
+ + "]";
}
}
}
@Override
- public NotificationEffectiveStatement createEffective(
- final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
- return new NotificationEffectiveStatementImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ void checkEffective(final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
+ // No-op
}
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
/**
* Class providing necessary support for processing YANG 1.1 Notification
}
@Override
- public NotificationEffectiveStatement createEffective(
- final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
- SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS),
- ctx.getStatementSourceReference(),
- "Notification %s is defined within an rpc, action, or another notification",
- ctx.getStatementArgument());
- SourceException.throwIf(!StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST,
- YangStmtMapping.KEY), ctx.getStatementSourceReference(),
- "Notification %s is defined within a list that has no key statement", ctx.getStatementArgument());
- SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE),
- ctx.getStatementSourceReference(), "Notification %s is defined within a case statement",
- ctx.getStatementArgument());
- return new NotificationEffectiveStatementImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
+
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ void checkEffective(final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
+ final StatementSourceReference ref = ctx.getStatementSourceReference();
+ final QName argument = ctx.getStatementArgument();
+ SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS), ref,
+ "Notification %s is defined within an rpc, action, or another notification", argument);
+ SourceException.throwIf(
+ !StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
+ "Notification %s is defined within a list that has no key statement", argument);
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE), ref,
+ "Notification %s is defined within a case statement", argument);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithQNameArgument.WithSubstatements;
+
+final class RegularNotificationStatement extends WithSubstatements implements NotificationStatement {
+ RegularNotificationStatement(final QName argument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(argument, substatements);
+ }
+}