cz.cuni.mff.d3s.spl.formula.FormulaParsingException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spl-evaluation-java Show documentation
Show all versions of spl-evaluation-java Show documentation
Stochastice Performance Logic is a formalism for capturing performance
assumptions. It is, for example, possible to capture assumption that
newer version of a function bar is faster than the previous version or
that library foobar is faster than library barfoo when rendering
antialiased text.
The purpose of this framework is to allow evaluation of SPL formulas
inside Java applications.
package cz.cuni.mff.d3s.spl.formula;
/** Wrapping exception for a parsing error within a formula.
*
* Since formulas would be probably prepared by developers this is
* an unchecked exception.
*/
public class FormulaParsingException extends RuntimeException {
private static final long serialVersionUID = 1L;
public FormulaParsingException(ParseException cause, String formula) {
super(String.format("Parsing error in \"%s\" near %s (line %d, column %d).",
getFirstCharacters(formula, 15),
cause.currentToken.image,
cause.currentToken.endLine,
cause.currentToken.endColumn), cause);
}
public FormulaParsingException(TokenMgrError cause, String formula) {
super(String.format("Lexical error in \"%s\" caused by \"%s\".",
getFirstCharacters(formula, 15),
cause.getMessage()), cause);
}
private static String getFirstCharacters(String input, int recommendedLength) {
if (input.length() + 1 <= recommendedLength) {
return input;
} else {
return input.substring(0, recommendedLength - 3) + "...";
}
}
}