use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportNoViableAlternative.
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) {
TokenStream tokens = recognizer.getInputStream();
String input;
if (tokens instanceof TokenStream) {
if (e.getStartToken().getType() == Token.EOF)
input = "<文件尾>";
else
input = tokens.getText(e.getStartToken(), e.getOffendingToken());
} else {
input = "<未知输入>";
}
BeetlException exception = null;
if (keys.contains(e.getOffendingToken().getText())) {
exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, "不允许" + e.getOffendingToken().getText() + "关键出现在这里" + ":" + escapeWSAndQuote(input), e);
} else {
exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, escapeWSAndQuote(input), e);
}
// String msg = "no viable alternative at input " + escapeWSAndQuote(input);
exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
throw exception;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class BeetlAntlrErrorStrategy method reportError.
@Override
public void reportError(Parser recognizer, RecognitionException e) {
// yet successfully, don't report any errors.
if (inErrorRecoveryMode(recognizer)) {
// don't report spurious errors
return;
}
beginErrorCondition(recognizer);
if (e instanceof NoViableAltException) {
reportNoViableAlternative(recognizer, (NoViableAltException) e);
} else if (e instanceof InputMismatchException) {
reportInputMismatch(recognizer, (InputMismatchException) e);
} else if (e instanceof FailedPredicateException) {
reportFailedPredicate(recognizer, (FailedPredicateException) e);
} else {
// System.err.println("unknown recognition error type: " + e.getClass().getName());
BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
// exception.token = this.getGrammarToken(e.getOffendingToken());
exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
throw exception;
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class SyntaxErrorListener method syntaxError.
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
BeetlException be = new BeetlException(BeetlException.TOKEN_ERROR);
be.token = new GrammarToken(BeetlUtil.reportChineseTokenError(msg), line, charPositionInLine);
throw be;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class ClasspathResource method openReader.
@Override
public Reader openReader() {
ClasspathResourceLoader loader = ((ClasspathResourceLoader) resourceLoader);
ClassLoader cs = loader.getClassLoader();
URL url = cs.getResource(path);
if (url == null) {
// 兼容以前的写法
url = resourceLoader.getClass().getResource(path);
}
if (url == null) {
BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
be.pushResource(this);
throw be;
}
InputStream is;
try {
is = url.openStream();
} catch (IOException e1) {
BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
be.pushResource(this);
throw be;
}
if (is == null) {
BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
be.pushResource(this);
throw be;
}
if (url.getProtocol().equals("file")) {
file = new File(url.getFile());
lastModified = file.lastModified();
}
Reader br;
try {
br = new BufferedReader(new InputStreamReader(is, ((ClasspathResourceLoader) this.resourceLoader).charset));
return br;
} catch (UnsupportedEncodingException e) {
return null;
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class TypeBindingProbe method check.
@Override
public void check(Context ctx) {
if (isCompleted)
return;
int y = 0;
for (int i = 0; i < program.metaData.tempVarStartIndex; i++) {
if (types[i] == null) {
if (ctx.vars[i] != ctx.NOT_EXIST_OBJECT && ctx.vars[i] != null) {
Object o = ctx.vars[i];
if (isDynamicObject(ctx, i)) {
types[i] = Type.ObjectType;
y++;
continue;
}
Type c = getType(o);
if (c == null)
continue;
else {
types[i] = c;
y++;
}
} else {
continue;
}
} else {
y++;
}
}
// 推测完毕
if (y == program.metaData.tempVarStartIndex) {
try {
infer();
isCompleted = true;
// 调用下一个filter
nextFilter.setProgram(this.program);
nextFilter.check(ctx);
} catch (BeetlException bex) {
// bex.printStackTrace();
ProgramReplaceErrorEvent event = new ProgramReplaceErrorEvent(program.res.getId(), bex.getMessage(), bex);
program.gt.fireEvent(event);
isCompleted = true;
}
}
}
Aggregations