Implemented support for generating YangModuleInfo implementation.
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YangParserListenerImpl.java
index 92d583f81c24df1b6cb418ae8e66b94f40fbc4d2..f186860c63ee51c5aa7c6277793dc966f5f033e4 100644 (file)
@@ -56,10 +56,13 @@ import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Strings;
+
 public final class YangParserListenerImpl extends YangParserBaseListener {
     private static final Logger LOGGER = LoggerFactory.getLogger(YangParserListenerImpl.class);
     private static final String AUGMENT_STR = "augment";
 
+    private final String sourcePath;
     private ModuleBuilder moduleBuilder;
     private String moduleName;
     private URI namespace;
@@ -77,6 +80,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         return actualPath.peek().pop();
     }
 
+    public YangParserListenerImpl(String sourcePath) {
+        this.sourcePath = sourcePath;
+    }
+
     @Override
     public void enterModule_stmt(YangParser.Module_stmtContext ctx) {
         moduleName = stringFromNode(ctx);
@@ -84,7 +91,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         enterLog("module", moduleName, 0);
         actualPath.push(new Stack<QName>());
 
-        moduleBuilder = new ModuleBuilder(moduleName);
+        moduleBuilder = new ModuleBuilder(moduleName, sourcePath);
 
         String description = null;
         String reference = null;
@@ -116,7 +123,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         enterLog("submodule", moduleName, 0);
         actualPath.push(new Stack<QName>());
 
-        moduleBuilder = new ModuleBuilder(moduleName, true);
+        moduleBuilder = new ModuleBuilder(moduleName, true, sourcePath);
 
         String description = null;
         String reference = null;
@@ -795,8 +802,8 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             nodeType = new QName(namespace, revision, splittedElement[0], splittedElement[1]);
         }
 
-        QName qname;
-        if (nodeParameter != null) {
+        QName qname = null;
+        if (!Strings.isNullOrEmpty(nodeParameter)) {
             String[] splittedName = nodeParameter.split(":");
             if (splittedName.length == 2) {
                 qname = new QName(null, null, splittedName[0], splittedName[1]);
@@ -804,10 +811,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 qname = new QName(namespace, revision, yangModelPrefix, splittedName[0]);
             }
         } else {
-            qname = new QName(namespace, revision, yangModelPrefix, nodeParameter);
+            qname = nodeType;
         }
-
-        addNodeToPath(new QName(namespace, revision, yangModelPrefix, nodeParameter));
+        addNodeToPath(qname);
         SchemaPath path = createActualSchemaPath(actualPath.peek());
 
         UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(line, qname, path);