We have a String on input and LeafRefPathParserImpl uses ANTLR's
CharStreams -- hence it makes no sense to bounce input through
an InputStream.
Remove this atrocity, eliminating an IOException/IllegalStateException
error path in process.
JIRA: YANGTOOLS-892
Change-Id: I78eadf30da6a1e64621ca4c14dfa13e84524b591
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
23b7ff7e2e39e0d520e249ae5b256746acef5abd)
package org.opendaylight.yangtools.yang.data.impl.leafref;
import com.google.common.collect.ImmutableMap;
package org.opendaylight.yangtools.yang.data.impl.leafref;
import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
} catch (LeafRefYangSyntaxErrorException e) {
throw new IllegalArgumentException(e);
return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
} catch (LeafRefYangSyntaxErrorException e) {
throw new IllegalArgumentException(e);
- } catch (IOException e) {
- throw new IllegalStateException(e);
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkNotNull;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
this.schemaContext = schemaContext;
}
this.schemaContext = schemaContext;
}
- LeafRefContext buildLeafRefContextTree() throws IOException, LeafRefYangSyntaxErrorException {
+ LeafRefContext buildLeafRefContextTree() throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(schemaContext.getQName(),
schemaContext.getPath(), schemaContext);
final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(schemaContext.getQName(),
schemaContext.getPath(), schemaContext);
}
private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule)
}
private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule)
- throws IOException, LeafRefYangSyntaxErrorException {
+ throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
if (type instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
final String leafRefPathString = leafrefType.getPathStatement().toString();
if (type instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
final String leafRefPathString = leafrefType.getPathStatement().toString();
-
- currentLeafRefContextBuilder.setLeafRefTargetPathString(leafRefPathString);
- currentLeafRefContextBuilder.setReferencing(true);
-
final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext,
checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),
node);
final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext,
checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),
node);
+ final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(leafRefPathString);
- final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPathSourceToSchemaPath(
- new ByteArrayInputStream(leafRefPathString.getBytes(StandardCharsets.UTF_8)));
-
+ currentLeafRefContextBuilder.setLeafRefTargetPathString(leafRefPathString);
+ currentLeafRefContextBuilder.setReferencing(true);
currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
}
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule)
}
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule)
- throws IOException,LeafRefYangSyntaxErrorException {
+ throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
if (node instanceof DataNodeContainer) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
if (node instanceof DataNodeContainer) {
*/
package org.opendaylight.yangtools.yang.data.impl.leafref;
*/
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;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
this.node = currentNode;
}
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(
final ParseTreeWalker walker = new ParseTreeWalker();
final LeafRefPathParserListenerImpl leafRefPathParserListenerImpl = new LeafRefPathParserListenerImpl(
return leafRefPathParserListenerImpl.getLeafRefPath();
}
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();
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final LeafRefPathParser parser = new LeafRefPathParser(tokens);
parser.removeErrorListeners();