final Set<UsesNode> mutableUses = new LinkedHashSet<>();
final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
- final var rabbit = stmt.caerbannog();
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
if (effectiveStatement instanceof UsesNode && !mutableUses.add((UsesNode) effectiveStatement)) {
- throw EffectiveStmtUtils.createNameCollisionSourceException(rabbit, stmt.sourceReference(),
- effectiveStatement);
+ throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
}
if (effectiveStatement instanceof TypedefEffectiveStatement) {
final TypeDefinition<?> type = ((TypedefEffectiveStatement) effectiveStatement).getTypeDefinition();
if (!mutableTypeDefinitions.add(type)) {
- throw EffectiveStmtUtils.createNameCollisionSourceException(rabbit, stmt.sourceReference(),
- effectiveStatement);
+ throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
}
}
if (effectiveStatement instanceof GroupingDefinition
&& !mutableGroupings.add((GroupingDefinition) effectiveStatement)) {
- throw EffectiveStmtUtils.createNameCollisionSourceException(rabbit, stmt.sourceReference(),
- effectiveStatement);
+ throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, effectiveStatement);
}
}
.toString();
}
- protected static final @NonNull String findPrefix1(final Current<?, ?> stmt, final String type, final String name) {
- return findPrefix(stmt.caerbannog(), type, name);
- }
-
protected static final @NonNull String findPrefix(final StmtContext<?, ?, ?> stmt, final String type,
final String name) {
return SourceException.throwIfNull(
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
@Beta
public final class EffectiveStmtUtils {
// Hidden on purpose
}
- public static SourceException createNameCollisionSourceException(final StmtContext<?, ?, ?> ctx,
- final StatementSourceReference ref, final EffectiveStatement<?, ?> effectiveStatement) {
- return new SourceException(ref,
+ public static SourceException createNameCollisionSourceException(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final EffectiveStatement<?, ?> effectiveStatement) {
+ return new SourceException(stmt.sourceReference(),
"Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared.",
- ctx.getRoot().rawStatementArgument(), effectiveStatement.argument(), effectiveStatement.argument());
+ stmt.caerbannog().getRoot().rawStatementArgument(), effectiveStatement.argument(),
+ effectiveStatement.argument());
}
public static Optional<ElementCountConstraint> createElementCountConstraint(final EffectiveStatement<?, ?> stmt) {
return false;
}
- public static void checkUniqueGroupings(final StmtContext<?, ?, ?> ctx,
- final Collection<? extends EffectiveStatement<?, ?>> statements, final StatementSourceReference ref) {
- checkUniqueNodes(ctx, statements, GroupingDefinition.class, ref);
+ public static void checkUniqueGroupings(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> statements) {
+ checkUniqueNodes(stmt, statements, GroupingDefinition.class);
}
- public static void checkUniqueTypedefs(final StmtContext<?, ?, ?> ctx,
- final Collection<? extends EffectiveStatement<?, ?>> statements, final StatementSourceReference ref) {
+ public static void checkUniqueTypedefs(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> statements) {
final Set<Object> typedefs = new HashSet<>();
- for (EffectiveStatement<?, ?> stmt : statements) {
- if (stmt instanceof TypedefEffectiveStatement
- && !typedefs.add(((TypedefEffectiveStatement) stmt).getTypeDefinition())) {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, ref, stmt);
+ for (EffectiveStatement<?, ?> statement : statements) {
+ if (statement instanceof TypedefEffectiveStatement
+ && !typedefs.add(((TypedefEffectiveStatement) statement).getTypeDefinition())) {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, statement);
}
}
}
- public static void checkUniqueUses(final StmtContext<?, ?, ?> ctx,
- final Collection<? extends EffectiveStatement<?, ?>> statements, final StatementSourceReference ref) {
- checkUniqueNodes(ctx, statements, UsesNode.class, ref);
+ public static void checkUniqueUses(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> statements) {
+ checkUniqueNodes(stmt, statements, UsesNode.class);
}
- private static void checkUniqueNodes(final StmtContext<?, ?, ?> ctx,
- final Collection<? extends EffectiveStatement<?, ?>> statements, final Class<?> type,
- final StatementSourceReference ref) {
+ private static void checkUniqueNodes(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> statements, final Class<?> type) {
final Set<Object> nodes = new HashSet<>();
- for (EffectiveStatement<?, ?> stmt : statements) {
- if (type.isInstance(stmt) && !nodes.add(stmt)) {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, ref, stmt);
+ for (EffectiveStatement<?, ?> statement : statements) {
+ if (type.isInstance(statement) && !nodes.add(statement)) {
+ throw EffectiveStmtUtils.createNameCollisionSourceException(stmt, statement);
}
}
}
final StatementSourceReference ref = stmt.sourceReference();
checkState(!substatements.isEmpty(), "Missing implicit input/output statements at %s", ref);
final QName argument = stmt.coerceArgument();
- final var rabbit = stmt.caerbannog();
- SourceException.throwIf(StmtContextUtils.hasAncestorOfType(rabbit, ILLEGAL_PARENTS), ref,
+ SourceException.throwIf(StmtContextUtils.hasAncestorOfType(stmt, ILLEGAL_PARENTS), ref,
"Action %s is defined within a notification, rpc or another action", argument);
SourceException.throwIf(
- !StmtContextUtils.hasAncestorOfTypeWithChildOfType(rabbit, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
+ !StmtContextUtils.hasAncestorOfTypeWithChildOfType(stmt, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
"Action %s is defined within a list that has no key statement", argument);
- SourceException.throwIf(StmtContextUtils.hasParentOfType(rabbit, YangStmtMapping.CASE), ref,
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.CASE), ref,
"Action %s is defined within a case statement", argument);
- SourceException.throwIf(StmtContextUtils.hasParentOfType(rabbit, YangStmtMapping.MODULE), ref,
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.MODULE), ref,
"Action %s is defined at the top level of a module", argument);
return new ActionEffectiveStatementImpl(stmt.declared(), stmt.getSchemaPath(),
.setPresence(findFirstStatement(substatements, PresenceEffectiveStatement.class) != null)
.toFlags();
- final var ref = stmt.sourceReference();
- final var rabbit = stmt.caerbannog();
- EffectiveStmtUtils.checkUniqueGroupings(rabbit, substatements, ref);
- EffectiveStmtUtils.checkUniqueTypedefs(rabbit, substatements, ref);
- EffectiveStmtUtils.checkUniqueUses(rabbit, substatements, ref);
+ EffectiveStmtUtils.checkUniqueGroupings(stmt, substatements);
+ EffectiveStmtUtils.checkUniqueTypedefs(stmt, substatements);
+ EffectiveStmtUtils.checkUniqueUses(stmt, substatements);
return new ContainerEffectiveStatementImpl(stmt.declared(), substatements, stmt.sourceReference(), flags, path,
original);
final ImmutableList<QName> keyDefinition) {
super(stmt.declared(), substatements, stmt.sourceReference());
- final var rabbit = stmt.caerbannog();
- EffectiveStmtUtils.checkUniqueGroupings(rabbit, substatements, stmt.sourceReference());
- EffectiveStmtUtils.checkUniqueTypedefs(rabbit, substatements, stmt.sourceReference());
- EffectiveStmtUtils.checkUniqueUses(rabbit, substatements, stmt.sourceReference());
+ EffectiveStmtUtils.checkUniqueGroupings(stmt, substatements);
+ EffectiveStmtUtils.checkUniqueTypedefs(stmt, substatements);
+ EffectiveStmtUtils.checkUniqueUses(stmt, substatements);
this.substatements = maskList(substatements);
this.path = requireNonNull(path);
void checkEffective(final Current<QName, NotificationStatement> stmt) {
final QName argument = stmt.argument();
final StatementSourceReference ref = stmt.sourceReference();
- final var rabbit = stmt.caerbannog();
- SourceException.throwIf(StmtContextUtils.hasAncestorOfType(rabbit, ILLEGAL_PARENTS), ref,
+ SourceException.throwIf(StmtContextUtils.hasAncestorOfType(stmt, ILLEGAL_PARENTS), ref,
"Notification %s is defined within an rpc, action, or another notification", argument);
SourceException.throwIf(
- !StmtContextUtils.hasAncestorOfTypeWithChildOfType(rabbit, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
+ !StmtContextUtils.hasAncestorOfTypeWithChildOfType(stmt, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
"Notification %s is defined within a list that has no key statement", argument);
- SourceException.throwIf(StmtContextUtils.hasParentOfType(rabbit, YangStmtMapping.CASE), ref,
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.CASE), ref,
"Notification %s is defined within a case statement", argument);
}
}
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Parent;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
* Checks whether at least one ancestor of a StatementContext matches one from a collection of statement
* definitions.
*
- * @param ctx
- * StatementContext to be checked
- * @param ancestorTypes
- * collection of statement definitions
+ * @param stmt EffectiveStmtCtx to be checked
+ * @param ancestorTypes collection of statement definitions
* @return true if at least one ancestor of a StatementContext matches one
* from collection of statement definitions, otherwise false.
*/
- public static boolean hasAncestorOfType(final StmtContext<?, ?, ?> ctx,
+ public static boolean hasAncestorOfType(final EffectiveStmtCtx stmt,
final Collection<StatementDefinition> ancestorTypes) {
requireNonNull(ancestorTypes);
- StmtContext<?, ?, ?> current = ctx.getParentContext();
+ Parent current = stmt.parent();
while (current != null) {
- if (ancestorTypes.contains(current.getPublicDefinition())) {
+ if (ancestorTypes.contains(current.publicDefinition())) {
return true;
}
- current = current.getParentContext();
+ current = current.parent();
}
return false;
}
/**
* Checks whether all of StmtContext's ancestors of specified type have a child of specified type.
*
- * @param ctx StmtContext to be checked
+ * @param stmt EffectiveStmtCtx to be checked
* @param ancestorType type of ancestor to search for
* @param ancestorChildType type of child to search for in the specified ancestor type
* @return true if all of StmtContext's ancestors of specified type have a child of specified type, otherwise false
*/
public static <A, D extends DeclaredStatement<A>> boolean hasAncestorOfTypeWithChildOfType(
- final StmtContext<?, ?, ?> ctx, final StatementDefinition ancestorType,
+ final EffectiveStmtCtx.Current<?, ?> stmt, final StatementDefinition ancestorType,
final StatementDefinition ancestorChildType) {
- requireNonNull(ctx);
+ requireNonNull(stmt);
requireNonNull(ancestorType);
requireNonNull(ancestorChildType);
- StmtContext<?, ?, ?> current = ctx.coerceParentContext();
+ StmtContext<?, ?, ?> current = stmt.caerbannog().getParentContext();
StmtContext<?, ?, ?> parent = current.getParentContext();
while (parent != null) {
if (ancestorType.equals(current.getPublicDefinition())
return true;
}
+ /**
+ * Checks whether the parent of EffectiveStmtCtx is of specified type.
+ *
+ * @param stmt EffectiveStmtCtx to be checked
+ * @param parentType type of parent to check
+ * @return true if the parent of StmtContext is of specified type, otherwise false
+ */
+ public static boolean hasParentOfType(final EffectiveStmtCtx.Current<?, ?> stmt,
+ final StatementDefinition parentType) {
+ return hasParentOfType(stmt.caerbannog(), parentType);
+ }
+
/**
* Checks whether the parent of StmtContext is of specified type.
*
- * @param ctx
- * StmtContext to be checked
- * @param parentType
- * type of parent to check
+ * @param ctx StmtContext to be checked
+ * @param parentType type of parent to check
* @return true if the parent of StmtContext is of specified type, otherwise false
*/
public static boolean hasParentOfType(final StmtContext<?, ?, ?> ctx, final StatementDefinition parentType) {