private YangStatementParser.StatementContext statementContext;
private ParseTreeWalker walker;
private String sourceName;
-// private String source;
-// private InputStream sourceStream;
private static final Logger LOG = LoggerFactory.getLogger(YangStatementSourceImpl.class);
- public YangStatementSourceImpl(final String fileName, boolean isAbsolute) {
+ public YangStatementSourceImpl(final String fileName, final boolean isAbsolute) {
try {
statementContext = parseYangSource(loadFile(fileName, isAbsolute));
walker = new ParseTreeWalker();
}
}
- public YangStatementSourceImpl(SourceIdentifier identifier, YangStatementParser.StatementContext statementContext) {
+ public YangStatementSourceImpl(final SourceIdentifier identifier, final YangStatementParser.StatementContext statementContext) {
try {
this.statementContext = statementContext;
this.sourceName = identifier.getName();
walker.walk(yangStatementModelParser, statementContext);
}
- private NamedFileInputStream loadFile(final String fileName, boolean isAbsolute) throws URISyntaxException,
+ private NamedFileInputStream loadFile(final String fileName, final boolean isAbsolute) throws URISyntaxException,
IOException {
//TODO: we need absolute path first!
return isAbsolute ? new NamedFileInputStream(new File(fileName), fileName) : new NamedFileInputStream(new File
(getClass().getResource(fileName).toURI()), fileName);
-
-// final File file = new File(fileName);
-// final ByteSource byteSource = BuilderUtils.fileToByteSource(file);
-// source = byteSource.asCharSource(Charsets.UTF_8).read();
-// return isAbsolute ? new NamedFileInputStream(file, fileName) : new NamedFileInputStream(new File
-// (getClass().getResource(fileName).toURI()), fileName);
}
private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException,
final YangErrorListener errorListener = new YangErrorListener();
parser.addErrorListener(errorListener);
- if(stream instanceof NamedFileInputStream) {
+ if (stream instanceof NamedFileInputStream) {
sourceName = stream.toString();
} else {
sourceName = null;
}
-// sourceStream = stream;
-// sourceName = parser.getSourceName();
-//
-// if (sourceName == null) {
-// sourceName = stream.toString();
-// }
final StatementContext result = parser.statement();
errorListener.validate();
return sourceName;
}
-// public InputStream getSourceStream() {
-// return sourceStream;
-// }
-
- private static void logError(Exception e) {
+ private static void logError(final Exception e) {
if (e instanceof YangSyntaxErrorException) {
LOG.error(((YangSyntaxErrorException) e).getFormattedMessage(), e);
} else {