import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PresenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
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.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
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;
}
@SafeVarargs
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public static StmtContext<?, ?, ?> findFirstDeclaredSubstatement(final StmtContext<?, ?, ?> stmtContext,
int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
if (startIndex >= types.length) {
}
for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (producesDeclared(subStmtContext, types[startIndex])) {
+ if (subStmtContext.producesDeclared((Class) types[startIndex])) {
return startIndex + 1 == types.length ? subStmtContext : findFirstDeclaredSubstatement(subStmtContext,
++startIndex, types);
}
* @param <A> statement argument type
* @param <D> declared statement type
* @return statement context that was searched for or null if was not found
+ * @deprecated Use {@link StmtContext#findSubstatementArgument(Class)} instead.
*/
+ @Deprecated(forRemoval = true)
public static <A, D extends DeclaredStatement<A>> StmtContext<A, ?, ?> findFirstSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<D> declaredType) {
final StmtContext<A, ?, ?> effectiveSubstatement = findFirstEffectiveSubstatement(stmtContext, declaredType);
}
public static <D extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatementOnSublevel(
- final StmtContext<?, ?, ?> stmtContext, final Class<D> declaredType, int sublevel) {
+ final StmtContext<?, ?, ?> stmtContext, final Class<? super D> declaredType, int sublevel) {
for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (sublevel == 1 && producesDeclared(subStmtContext, declaredType)) {
+ if (sublevel == 1 && subStmtContext.producesDeclared(declaredType)) {
return subStmtContext;
}
if (sublevel > 1) {
}
public static <D extends DeclaredStatement<?>> StmtContext<?, ?, ?> findDeepFirstDeclaredSubstatement(
- final StmtContext<?, ?, ?> stmtContext, final Class<D> declaredType) {
+ final StmtContext<?, ?, ?> stmtContext, final Class<? super D> declaredType) {
for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (producesDeclared(subStmtContext, declaredType)) {
+ if (subStmtContext.producesDeclared(declaredType)) {
return subStmtContext;
}
return null;
}
- @Deprecated(forRemoval = true)
- public static boolean producesDeclared(final StmtContext<?, ?, ?> ctx,
- final Class<? extends DeclaredStatement<?>> type) {
- return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
- }
-
public static boolean isInExtensionBody(final StmtContext<?, ?, ?> stmtCtx) {
StmtContext<?, ?, ?> current = stmtCtx;
}
private static boolean containsPresenceSubStmt(final StmtContext<?, ?, ?> stmtCtx) {
- return findFirstSubstatement(stmtCtx, PresenceStatement.class) != null;
+ return stmtCtx.hasSubstatement(PresenceEffectiveStatement.class);
}
/**
StmtContext<?, ?, ?> current = ctx.coerceParentContext();
StmtContext<?, ?, ?> parent = current.getParentContext();
while (parent != null) {
- if (ancestorType.equals(current.getPublicDefinition())) {
- @SuppressWarnings("unchecked")
- final Class<D> ancestorChildTypeClass = (Class<D>) ancestorChildType.getDeclaredRepresentationClass();
- if (findFirstSubstatement(current, ancestorChildTypeClass) == null) {
- return false;
- }
+ if (ancestorType.equals(current.getPublicDefinition())
+ && !current.hasSubstatement(ancestorChildType.getEffectiveRepresentationClass())) {
+ return false;
}
current = parent;
}
public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) {
- final StmtContext<?, ?, ?> importedModule = ctx.getRoot().getFromNamespace(ImportPrefixToModuleCtx.class,
- prefix);
+ final StmtContext<?, ?, ?> root = ctx.getRoot();
+ final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(ImportPrefixToModuleCtx.class, prefix);
final QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, importedModule);
if (qnameModule != null) {
return qnameModule;
}
- final StmtContext<?, ?, ?> root = ctx.getRoot();
if (root.producesDeclared(SubmoduleStatement.class)) {
final String moduleName = root.getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
return ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
return null;
}
- public static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
- final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
- if (qNameModule != null) {
- // creates SourceIdentifier for a module
- return RevisionSourceIdentifier.create((String) root.getStatementArgument(), qNameModule.getRevision());
- }
-
- // creates SourceIdentifier for a submodule
- final Optional<Revision> revision = getLatestRevision(root.declaredSubstatements());
- return RevisionSourceIdentifier.create((String) root.getStatementArgument(), revision);
- }
-
public static Optional<Revision> getLatestRevision(final Iterable<? extends StmtContext<?, ?, ?>> subStmts) {
Revision revision = null;
for (final StmtContext<?, ?, ?> subStmt : subStmts) {