- public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
- final Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
-
- final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument();
-
- List<StatementContextBase<?, ?, ?>> rootStatementCtxList = new LinkedList<>();
-
- if (augmentTargetNode.isAbsolute()) {
-
- QNameModule module;
- if (augmentTargetNode != null) {
- module = augmentTargetNode.getPathFromRoot().iterator().next().getModule();
- } else {
- throw new IllegalArgumentException(
- "Augment argument null, something bad happened in some of previous parsing phases");
- }
-
- StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(
- NamespaceToModule.class, module);
- rootStatementCtxList.add(rootStatementCtx);
-
- final Map<?, ?> subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class);
- if (subModules != null) {
- rootStatementCtxList.addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules.values());
- }
-
- } else {
- StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode.getParentContext();
- if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) {
- rootStatementCtxList.add(parent.getParentContext());
- } else {
- //error
- }
- }
-
- List<QName> augmentTargetPath = new LinkedList<>();
-
- augmentTargetPath.addAll((Collection<? extends QName>) augmentTargetNode.getPathFromRoot());
-
- StatementContextBase<?, ?, ?> augmentTargetCtx = null;
- for (final StatementContextBase<?, ?, ?> rootStatementCtx : rootStatementCtxList) {
- augmentTargetCtx = Utils.findCtxOfNodeInRoot(rootStatementCtx,
- augmentTargetPath);
- if (augmentTargetCtx != null) break;
- }