Consider AugmentationNodes when direct descendant is not found
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / leafref / LeafRefPathParserImpl.java
index e5552c55ea599fb68a48077c2dfeafc4fc61c286..3c5877839a22a598b8b6229c56f0b4e4817c154d 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.leafref;
 
-import java.io.IOException;
-import java.io.InputStream;
 import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonTokenStream;
 import org.antlr.v4.runtime.tree.ParseTreeWalker;
@@ -22,28 +20,25 @@ final class LeafRefPathParserImpl {
     private final Module module;
     private final SchemaNode node;
 
-     public LeafRefPathParserImpl(final SchemaContext schemaContext, final Module currentModule, final SchemaNode currentNode) {
+    LeafRefPathParserImpl(final SchemaContext schemaContext, final Module currentModule, final SchemaNode currentNode) {
         this.schemaContext = schemaContext;
         this.module = currentModule;
         this.node = currentNode;
     }
 
-    public LeafRefPath parseLeafRefPathSourceToSchemaPath(final InputStream stream) throws IOException, LeafRefYangSyntaxErrorException {
-
-        final Path_argContext pathCtx = parseLeafRefPathSource(stream);
+    LeafRefPath parseLeafRefPath(final String path) throws LeafRefYangSyntaxErrorException {
+        final Path_argContext pathCtx = parseLeafRefPathSource(path);
 
         final ParseTreeWalker walker = new ParseTreeWalker();
-        final LeafRefPathParserListenerImpl leafRefPathParserListenerImpl = new LeafRefPathParserListenerImpl(schemaContext, module, node);
-        walker.walk(leafRefPathParserListenerImpl,pathCtx);
-
-        final LeafRefPath leafRefPath = leafRefPathParserListenerImpl.getLeafRefPath();
+        final LeafRefPathParserListenerImpl leafRefPathParserListenerImpl = new LeafRefPathParserListenerImpl(
+            schemaContext, module, node);
+        walker.walk(leafRefPathParserListenerImpl, pathCtx);
 
-        return leafRefPath;
+        return leafRefPathParserListenerImpl.getLeafRefPath();
     }
 
-
-    private Path_argContext parseLeafRefPathSource(final InputStream stream) throws IOException, LeafRefYangSyntaxErrorException {
-        final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromStream(stream));
+    private Path_argContext parseLeafRefPathSource(final String path) throws LeafRefYangSyntaxErrorException {
+        final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromString(path));
         final CommonTokenStream tokens = new CommonTokenStream(lexer);
         final LeafRefPathParser parser = new LeafRefPathParser(tokens);
         parser.removeErrorListeners();
@@ -53,8 +48,6 @@ final class LeafRefPathParserImpl {
 
         final Path_argContext result = parser.path_arg();
         errorListener.validate();
-
         return result;
     }
-
 }