BUG-6522: do not re-read models 29/47529/2
authorRobert Varga <rovarga@cisco.com>
Tue, 25 Oct 2016 14:22:29 +0000 (16:22 +0200)
committerAnil Belur <abelur@linuxfoundation.org>
Sun, 30 Oct 2016 11:47:52 +0000 (11:47 +0000)
The source text is ignored, so there is no point in reading it.

Deprecate the current method which makes it look like the text
is needed. And eliminate the read.

Change-Id: Ib5550e6e40ecad1c0883a21e39fada8136c5b820
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TextToASTTransformer.java

index 5e3ab5eaabf926f71a22c701e1a682c394f15d54..3ccc8f0935c85f19c06b446b7db4a6d287e07580 100644 (file)
@@ -96,9 +96,29 @@ public final class ASTSchemaSource implements SchemaSourceRepresentation {
      * @return A new representation instance.
      * @throws YangSyntaxErrorException
      *             if we fail to extract dependency information.
+     *
+     * @deprecated Use {@link #create(SourceIdentifier, ParserRuleContext)} instead.
      */
+    @Deprecated
     public static ASTSchemaSource create(@Nonnull final SourceIdentifier identifier,
             @Nonnull final ParserRuleContext tree, final String text) throws YangSyntaxErrorException {
+        return create(identifier, tree);
+    }
+
+    /**
+     * Create a new instance of AST representation for a abstract syntax tree,
+     * performing minimal semantic analysis to acquire dependency information.
+     *
+     * @param identifier
+     *            SourceIdentifier of yang schema source.
+     * @param tree
+     *            ANTLR abstract syntax tree
+     * @return A new representation instance.
+     * @throws YangSyntaxErrorException
+     *             if we fail to extract dependency information.
+     */
+    public static ASTSchemaSource create(@Nonnull final SourceIdentifier identifier,
+            @Nonnull final ParserRuleContext tree) throws YangSyntaxErrorException {
         final YangModelDependencyInfo depInfo = YangModelDependencyInfo.fromAST(identifier.getName(), tree);
         final SourceIdentifier id = getSourceId(depInfo);
 
index 25b5b9d1e5e0e7367e17b80adc6834c74c882854..3028f1859b986a0d14b465207aab90ef4c2a5412 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import org.antlr.v4.runtime.ParserRuleContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
@@ -41,10 +40,7 @@ public final class TextToASTTransformer extends SchemaSourceTransformer<YangText
 
                 //:TODO missing validation (YangModelBasicValidationListener should be re-implemented to new parser)
 
-                // Backwards compatibility
-                final String text = input.asCharSource(StandardCharsets.UTF_8).read();
-
-                return Futures.immediateCheckedFuture(ASTSchemaSource.create(input.getIdentifier(), ctx, text));
+                return Futures.immediateCheckedFuture(ASTSchemaSource.create(input.getIdentifier(), ctx));
             }
         }
     }