@Override public String toString() { String s; try { s = getSource(); } catch (Exception e) { // REVISIT: A bit of a hack? (JR) s = null; } return s != null ? s : getCanonicalForm(); }
final void setLocation(Template template, TemplateObject begin, Token end) { setLocation(template, begin.beginColumn, begin.beginLine, end.endColumn, end.endLine); }
private void calculatePosition() { synchronized (lock) { if (!positionsCalculated) { // The expressions is the argument of the template element, so we prefer it as it's more specific. TemplateObject templateObject = blamedExpression != null ? (TemplateObject) blamedExpression : ( ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length != 0 ? ftlInstructionStackSnapshot[0] : null); // Line number blow 0 means no info, negative means position in ?eval-ed value that we won't use here. if (templateObject != null && templateObject.getBeginLine() > 0) { final Template template = templateObject.getTemplate(); templateName = template != null ? template.getName() : null; templateSourceName = template != null ? template.getSourceName() : null; lineNumber = Integer.valueOf(templateObject.getBeginLine()); columnNumber = Integer.valueOf(templateObject.getBeginColumn()); endLineNumber = Integer.valueOf(templateObject.getEndLine()); endColumnNumber = Integer.valueOf(templateObject.getEndColumn()); } positionsCalculated = true; deleteFTLInstructionStackSnapshotIfNotNeeded(); } } }
private Blaming findBlaming(TemplateObject parent, Expression blamed, int recursionDepth) { // Just in case a loop ever gets into the AST somehow, try not fill the stack and such: if (recursionDepth > 50) return null; int paramCnt = parent.getParameterCount(); for (int i = 0; i < paramCnt; i++) { Object paramValue = parent.getParameterValue(i); if (paramValue == blamed) { Blaming blaming = new Blaming(); blaming.blamer = parent; blaming.roleOfblamed = parent.getParameterRole(i); return blaming; } else if (paramValue instanceof TemplateObject) { Blaming blaming = findBlaming((TemplateObject) paramValue, blamed, recursionDepth + 1); if (blaming != null) return blaming; } } return null; }
@Override protected String doConversion(Object obj) { try { return ((TemplateObject) obj).getCanonicalForm(); } catch (Exception e) { return "{Error getting canonical form}"; } }
/** * As of 2.3.20. the same as {@link #getEndLocation}. Meant to be used where there's a risk of XSS * when viewing error messages. */ public String getEndLocationQuoted() { return getEndLocation(); }
if (blaming != null) { sb.append("For "); String nss = blaming.blamer.getNodeTypeSymbol(); char q = nss.indexOf('"') == -1 ? '\"' : '`'; sb.append(q).append(nss).append(q);
private Blaming findBlaming(TemplateObject parent, Expression blamed, int recursionDepth) { // Just in case a loop ever gets into the AST somehow, try not fill the stack and such: if (recursionDepth > 50) return null; int paramCnt = parent.getParameterCount(); for (int i = 0; i < paramCnt; i++) { Object paramValue = parent.getParameterValue(i); if (paramValue == blamed) { Blaming blaming = new Blaming(); blaming.blamer = parent; blaming.roleOfblamed = parent.getParameterRole(i); return blaming; } else if (paramValue instanceof TemplateObject) { Blaming blaming = findBlaming((TemplateObject) paramValue, blamed, recursionDepth + 1); if (blaming != null) return blaming; } } return null; }
public final String getSource() { String s; if (template != null) { s = template.getSource(beginColumn, beginLine, endColumn, endLine); } else { s = null; } // Can't just return null for backward-compatibility... return s != null ? s : getCanonicalForm(); }
/** * As of 2.3.20. the same as {@link #getEndLocation}. Meant to be used where there's a risk of XSS * when viewing error messages. */ public String getEndLocationQuoted() { return getEndLocation(); }
if (blaming != null) { sb.append("For "); String nss = blaming.blamer.getNodeTypeSymbol(); char q = nss.indexOf('"') == -1 ? '\"' : '`'; sb.append(q).append(nss).append(q);
private void calculatePosition() { synchronized (lock) { if (!positionsCalculated) { // The expressions is the argument of the template element, so we prefer it as it's more specific. TemplateObject templateObject = blamedExpression != null ? (TemplateObject) blamedExpression : ( ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length != 0 ? ftlInstructionStackSnapshot[0] : null); // Line number blow 0 means no info, negative means position in ?eval-ed value that we won't use here. if (templateObject != null && templateObject.getBeginLine() > 0) { final Template template = templateObject.getTemplate(); templateName = template != null ? template.getName() : null; templateSourceName = template != null ? template.getSourceName() : null; lineNumber = Integer.valueOf(templateObject.getBeginLine()); columnNumber = Integer.valueOf(templateObject.getBeginColumn()); endLineNumber = Integer.valueOf(templateObject.getEndLine()); endColumnNumber = Integer.valueOf(templateObject.getEndColumn()); } positionsCalculated = true; deleteFTLInstructionStackSnapshotIfNotNeeded(); } } }
final void setLocation(Template template, TemplateObject begin, TemplateObject end) { setLocation(template, begin.beginColumn, begin.beginLine, end.endColumn, end.endLine); }
@Override public String toString() { String s; try { s = getSource(); } catch (Exception e) { // REVISIT: A bit of a hack? (JR) s = null; } return s != null ? s : getCanonicalForm(); }
private Blaming findBlaming(TemplateObject parent, Expression blamed, int recursionDepth) { // Just in case a loop ever gets into the AST somehow, try not fill the stack and such: if (recursionDepth > 50) return null; int paramCnt = parent.getParameterCount(); for (int i = 0; i < paramCnt; i++) { Object paramValue = parent.getParameterValue(i); if (paramValue == blamed) { Blaming blaming = new Blaming(); blaming.blamer = parent; blaming.roleOfblamed = parent.getParameterRole(i); return blaming; } else if (paramValue instanceof TemplateObject) { Blaming blaming = findBlaming((TemplateObject) paramValue, blamed, recursionDepth + 1); if (blaming != null) return blaming; } } return null; }
@Override protected String doConversion(Object obj) { try { return ((TemplateObject) obj).getCanonicalForm(); } catch (Exception e) { return "{Error getting canonical form}"; } }
/** * As of 2.3.20. the same as {@link #getEndLocation}. Meant to be used where there's a risk of XSS * when viewing error messages. */ public String getEndLocationQuoted() { return getEndLocation(); }
if (blaming != null) { sb.append("For "); String nss = blaming.blamer.getNodeTypeSymbol(); char q = nss.indexOf('"') == -1 ? '\"' : '`'; sb.append(q).append(nss).append(q);
private void calculatePosition() { synchronized (lock) { if (!positionsCalculated) { // The expressions is the argument of the template element, so we prefer it as it's more specific. TemplateObject templateObject = blamedExpression != null ? (TemplateObject) blamedExpression : ( ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length != 0 ? ftlInstructionStackSnapshot[0] : null); // Line number blow 0 means no info, negative means position in ?eval-ed value that we won't use here. if (templateObject != null && templateObject.getBeginLine() > 0) { final Template template = templateObject.getTemplate(); templateName = template != null ? template.getName() : null; templateSourceName = template != null ? template.getSourceName() : null; lineNumber = Integer.valueOf(templateObject.getBeginLine()); columnNumber = Integer.valueOf(templateObject.getBeginColumn()); endLineNumber = Integer.valueOf(templateObject.getEndLine()); endColumnNumber = Integer.valueOf(templateObject.getEndColumn()); } positionsCalculated = true; deleteFTLInstructionStackSnapshotIfNotNeeded(); } } }
final void setLocation(Template template, Token begin, Token end) { setLocation(template, begin.beginColumn, begin.beginLine, end.endColumn, end.endLine); }