+ /**
+ * Extracts {@link YangModelDependencyInfo} from an abstract syntax tree
+ * of a YANG model.
+ *
+ * @param tree Abstract syntax tree
+ * @return {@link YangModelDependencyInfo}
+ * @throws YangSyntaxErrorException
+ * If the AST is not a valid YANG module/submodule
+ */
+ public static YangModelDependencyInfo fromAST(final String name, final ParserRuleContext tree) throws YangSyntaxErrorException {
+ final Optional<Module_stmtContext> moduleCtx = getFirstContext(tree, Module_stmtContext.class);
+ if (moduleCtx.isPresent()) {
+ return parseModuleContext(moduleCtx.get());
+ }
+
+ final Optional<Submodule_stmtContext> submoduleCtx = getFirstContext(tree, Submodule_stmtContext.class);
+ if (submoduleCtx.isPresent()) {
+ return parseSubmoduleContext(submoduleCtx.get());
+ }
+
+ throw new YangSyntaxErrorException(name, 0, 0, "Unknown YANG text type");
+ }
+
+ /**
+ * Extracts {@link YangModelDependencyInfo} from input stream
+ * containing YANG model.
+ *
+ * This parsing does not validate full YANG module, only
+ * parses header up to the revisions and imports.
+ *
+ * @param yangStream
+ * Opened Input stream containing text source of YANG model
+ * @return {@link YangModelDependencyInfo}
+ * @throws IllegalArgumentException
+ * If input stream is not valid YANG stream
+ */