All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.cuni.mff.d3s.spl.formula.FormulaParsingException Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.0.4
Show newest version
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) + "...";
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy