/** * @return The source of this exception, or {@code null} if no source is * available. */ @Override public String getSource() { if (this.info != null) { return this.info.getSource(); } else { return null; } }
@Override public int getStopIndex() { if (this.info != null) { return this.info.getStopIndex(); } else { return -1; } }
/** * @return Line number where exception occurred, or {@code -1} if no line nr * is available. */ @Override public int getLineNumber() { if (this.info != null) { return this.info.getLineNumber(); } else { return -1; } }
@Override public boolean reportError(SyntaxError type, SourceInfo info, String... args) { SourceInfo isp = null; if (info != null) { isp = new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition(), ctxSource.getStartIndex() + info.getStartIndex(), ctxSource.getStartIndex() + info.getStopIndex() + 1, info.getSource()); } return super.reportError(type, isp, args); }
/** * @param info1 * A source info object. * @param info2 * A source info object. * @return {@code true} if source position of info1 object occurs before * position of info2 object. */ private static boolean before(SourceInfo info1, SourceInfo info2) { boolean source = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) < 0); boolean sourceEqual = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) == 0); boolean lineNr = sourceEqual && (info1.getLineNumber() < info2.getLineNumber()); boolean lineNrEqual = (info1.getLineNumber() == info2.getLineNumber()); boolean position = sourceEqual && lineNrEqual && (info1.getCharacterPosition() < info2.getCharacterPosition()); return source || lineNr || position; }
@Override public SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new InputStreamPosition(symbol.getLine(), symbol.getCharPositionInLine(), ctxSource.getStartIndex() + symbol.getStartIndex(), ctxSource.getStartIndex() + symbol.getStopIndex() + 1, ctxSource.getSource()); } };
/** * @return Character position where exception occurred, or {@code -1} if no * position is available. */ @Override public int getCharacterPosition() { if (this.info != null) { return this.info.getCharacterPosition(); } else { return -1; } }
@Override public int getStartIndex() { if (this.info != null) { return this.info.getStartIndex(); } else { return -1; } }
public void register(ParsedObject object) { final int register = this.counter++; if (object instanceof Module) { this.sources.put(((Module) object).getDefinition(), register); } else { this.sources.put(object.getSourceInfo(), register); } this.objects.put(register, object); }
@Override public boolean reportError(SyntaxError type, SourceInfo info, String... args) { SourceInfo isp = null; if (info != null) { isp = new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition(), ctxSource.getStartIndex() + info.getStartIndex(), ctxSource.getStartIndex() + info.getStopIndex() + 1, info.getSource()); } return super.reportError(type, isp, args); }
/** * Checks wether the position if the first source info is before the second * one. * * @param info1 * A source info object. * @param info2 * A source info object. * @return {@code true} if source position of info1 object occurs before * position of info2 object. */ private static boolean before(SourceInfo info1, SourceInfo info2) { boolean source = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) < 0); boolean sourceEqual = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) == 0); boolean lineNr = sourceEqual && (info1.getLineNumber() < info2.getLineNumber()); boolean lineNrEqual = (info1.getLineNumber() == info2.getLineNumber()); boolean position = sourceEqual && lineNrEqual && (info1.getCharacterPosition() < info2.getCharacterPosition()); return source || lineNr || position; } }
@Override public SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new InputStreamPosition(symbol.getLine(), symbol.getCharPositionInLine(), ctxSource.getStartIndex() + symbol.getStartIndex(), ctxSource.getStartIndex() + symbol.getStopIndex() + 1, ctxSource.getSource()); } };
/** * @return The source file used to construct this program. */ public File getSourceFile() { return new File(this.info.getSource()); }
@Override public int compareTo(SourceInfo o) { if (getSource() == null) { if (o.getSource() != null) { return -1; } } else { if (o.getSource() == null) { return 1; } // both files not null. int filecompare = getSource().compareTo(o.getSource()); if (filecompare != 0) { return filecompare; } } // files are equal (or both null). int linecompare = getLineNumber() - o.getLineNumber(); if (linecompare != 0) { return linecompare; } // lines are equal return getCharacterPosition() - o.getCharacterPosition(); } }
private SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new SourceInfoObject(this.source.getSource(), symbol.getLine(), symbol.getCharPositionInLine(), this.source.getStartIndex() + symbol.getStartIndex(), this.source.getStartIndex() + symbol.getStopIndex()); }
@Override public int compareTo(SourceInfo o) { return this.source.compareTo(o.getSource()); }
@Override public int compareTo(SourceInfo o) { if (getSource() == null) { if (o.getSource() != null) { return -1; } } else { if (o.getSource() == null) { return 1; } // both files not null. int filecompare = getSource().compareTo(o.getSource()); if (filecompare != 0) { return filecompare; } } // files are equal (or both null). int linecompare = getLineNumber() - o.getLineNumber(); if (linecompare != 0) { return linecompare; } // lines are equal return getCharacterPosition() - o.getCharacterPosition(); }
@Override public SourceInfo getSourceInfo(ParserRuleContext ctx) { Token start = (ctx == null) ? null : ctx.getStart(); Token stop = (ctx == null) ? null : ctx.getStop(); if (stop == null) { stop = start; } return (start == null) ? null : new InputStreamPosition(start.getLine(), start.getCharPositionInLine(), ctxSource.getStartIndex() + start.getStartIndex(), ctxSource.getStartIndex() + stop.getStopIndex() + 1, ctxSource.getSource()); }
@Override public SourceInfo getSourceInfo(ParserRuleContext ctx) { Token start = (ctx == null) ? null : ctx.getStart(); Token stop = (ctx == null) ? null : ctx.getStop(); if (stop == null) { stop = start; } return (start == null) ? null : new InputStreamPosition(start.getLine(), start.getCharPositionInLine(), ctxSource.getStartIndex() + start.getStartIndex(), ctxSource.getStartIndex() + stop.getStopIndex() + 1, ctxSource.getSource()); }
/** * Create {@link SourceInfoObject} for given context. * * @param ctx * the {@link DirectiveContext} from the parsed object * @return {@link SourceInfoObject} */ private SourceInfo getSourceInfo(ParserRuleContext ctx) { Token start = (ctx == null) ? null : ctx.getStart(); Token stop = (ctx == null) ? null : ctx.getStop(); if (stop == null) { // happens if we are at EOF... stop = start; } return (start == null) ? null : new SourceInfoObject(this.source.getSource(), start.getLine(), start.getCharPositionInLine(), this.source.getStartIndex() + start.getStartIndex(), this.source.getStartIndex() + stop.getStopIndex()); }