sb.append(blamed.getStartLocation()); sb.append(']');
/** * Throw an exception if the expression passed in is a String * Literal */ private void notStringLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof StringLiteral) { String msg = "Error " + exp.getStartLocation() + "\nFound string literal: " + exp + "\nExpecting: " + expected; throw new ParseException(msg, exp); } }
static void assertNonNull(TemplateModel model, Expression exp, Environment env) throws InvalidReferenceException { if (model == null) { throw new InvalidReferenceException( "Expression " + exp + " is undefined " + exp.getStartLocation() + ".", env); } }
static TemplateException invalidTypeException(TemplateModel model, Expression exp, Environment env, String expected) throws TemplateException { assertNonNull(model, exp, env); return new TemplateException( "Expected " + expected + ". " + exp + " evaluated instead to " + model.getClass().getName() + " " + exp.getStartLocation() + ".", env); } /**
/** * Throw an exception if the expression passed in is a Hash * Literal */ private void notHashLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof HashLiteral) { String msg = "Error " + exp.getStartLocation() + "\nFound hash literal: " + exp.getCanonicalForm() + "\nExpecting " + expected; throw new ParseException(msg, exp); } }
/** * Throw an exception if the expression passed in is a Number * Literal */ private void notNumberLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof NumberLiteral) { String msg = "Error " + exp.getStartLocation() + "\nFound number literal: " + exp.getCanonicalForm() + "\nExpecting " + expected; throw new ParseException(msg, exp); } }
/** * Throw an exception if the expression passed in is a boolean * Literal */ private void notBooleanLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof BooleanLiteral) { String msg = "Error " + exp.getStartLocation() + "\nFound: " + exp.getCanonicalForm() + "\nExpecting " + expected; throw new ParseException(msg, exp); } }
/** * Throw an exception if the expression passed in is a List * Literal */ private void notListLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof ListLiteral) { String msg = "Error " + exp.getStartLocation() + "\nFound list literal: " + exp.getCanonicalForm() + "\nExpecting " + expected; throw new ParseException(msg, exp); } } /**
private boolean getBoolean(Expression exp) throws ParseException { TemplateModel tm = null; try { tm = exp.getAsTemplateModel(null); } catch (Exception e) { throw new ParseException(e.getMessage() + "\nCould not evaluate expression: " + exp.getCanonicalForm() + exp.getStartLocation(), exp); } if (tm instanceof TemplateBooleanModel) { try { return ((TemplateBooleanModel) tm).getAsBoolean(); } catch (TemplateModelException tme) { } } if (tm instanceof TemplateScalarModel) { try { return StringUtil.getYesNo(((TemplateScalarModel) tm).getAsString()); } catch (Exception e) { throw new ParseException(e.getMessage() + "\nExpecting yes/no, found: " + exp.getCanonicalForm() + exp.getStartLocation(), exp); } } throw new ParseException("Expecting boolean (yes/no) parameter" + exp.getStartLocation(), exp); }
sb.append(blamed.getStartLocation()); sb.append(']');
sb.append(blamed.getStartLocation()); sb.append(']');
boolean isTrue(Environment env) throws TemplateException { TemplateModel referent = getAsTemplateModel(env); if (referent instanceof TemplateBooleanModel) { return ((TemplateBooleanModel) referent).getAsBoolean(); } if (env.isClassicCompatible()) { return referent != null && !isEmpty(referent); } assertNonNull(referent, this, env); String msg = "Error " + getStartLocation() + "\nExpecting a boolean (true/false) expression here" + "\nExpression " + this + " does not evaluate to true/false " + "\nit is an instance of " + referent.getClass().getName(); throw new NonBooleanException(msg, env); }
if (!hasRhs) end = sequence.size() -1; if (start < 0) { String msg = range.left.getStartLocation() + "\nNegative starting index for range, is " + range; throw new TemplateException(msg, env); String msg = range.left.getStartLocation() + "\nNegative ending index for range, is " + range; throw new TemplateException(msg, env); String msg = range.left.getStartLocation() + "\nLeft side index of range out of bounds, is " + start + ", but the sequence has only " + sequence.size() + " element(s) " String msg = range.right.getStartLocation() + "\nRight side index of range out of bounds, is " + end + ", but the sequence has only " + sequence.size() + " element(s)." if (!hasRhs) end = s.length() -1; if (start < 0) { String msg = range.left.getStartLocation() + "\nNegative starting index for range " + range + " : " + start; throw new TemplateException(msg, env); String msg = range.left.getStartLocation() + "\nNegative ending index for range " + range + " : " + end; throw new TemplateException(msg, env); String msg = range.left.getStartLocation() + "\nLeft side of range out of bounds, is: " + start + "\nbut string " + targetModel + " has " + s.length() + " elements."; String msg = range.right.getStartLocation()
{if (true) throw new ParseException("Could not evaluate expression: " + exp.getCanonicalForm() + " " + exp.getStartLocation() + "\nUnderlying cause: " + e.getMessage(), exp);} if (vs == null) { {if (true) throw new ParseException("expecting encoding string here: " + exp.getStartLocation(), exp);} {if (true) throw new ParseException("Expecting a hash of prefixes to namespace URI's here. " + exp.getStartLocation(), exp);} TemplateModel valueModel = prefixMap.get(prefix); if (!(valueModel instanceof TemplateScalarModel)) { {if (true) throw new ParseException("Non-string value in prefix to namespace hash. " + exp.getStartLocation(), exp);} template.addPrefixNSMapping(prefix, nsURI); } catch (IllegalArgumentException iae) { {if (true) throw new ParseException(iae.getMessage() + " " + exp.getStartLocation(), exp);} {if (true) throw new ParseException("Expecting a hash of attribute names to values here. " + exp.getStartLocation(), exp);}
String msg = "Error " + exp.getStartLocation() +"\nExpecting a string, " + (env.isClassicCompatible() ? "boolean, " : "" )