private static TemplateElement findTemplateElement(TemplateElement te, int line) { if (te.getBeginLine() > line || te.getEndLine() < line) { return null; for (Enumeration children = te.children(); children.hasMoreElements(); ) { TemplateElement child = (TemplateElement) children.nextElement(); TemplateElement childmatch = findTemplateElement(child, line); if ( e.getBeginLine() == line && e.getEndLine() > line ) { bestMatch = e; if ( e.getBeginLine() == e.getEndLine() && e.getBeginLine() == line) { bestMatch = e; break;
/** * Dump the raw template in canonical form. */ public void dump(PrintStream ps) { ps.print(rootElement.getCanonicalForm()); }
private void addInterruptionChecks(final TemplateElement te) throws TemplatePostProcessorException { if (te == null) { return; } final int childCount = te.getChildCount(); for (int i = 0; i < childCount; i++) { addInterruptionChecks(te.getChild(i)); } if (te.isNestedBlockRepeater()) { try { te.addChild(0, new ThreadInterruptionCheck(te)); } catch (ParseException e) { throw new TemplatePostProcessorException("Unexpected error; see cause", e); } } }
private TemplateElement getFirstLeaf() { TemplateElement te = this; while (!te.isLeaf() && !(te instanceof Macro) && !(te instanceof BlockAssignment)) { // A macro or macro invocation is treated as a leaf here for special reasons te = te.getFirstChild(); } return te; }
TemplateElement nextTerminalNode() { TemplateElement next = nextSibling(); if (next != null) { return next.getFirstLeaf(); } else if (parent != null) { return parent.nextTerminalNode(); } return null; }
final String canonicalForm = templateElement.getCanonicalForm(); new Object[]{templateElement.getNodeName(), expression}); final Enumeration<TemplateElement> children = templateElement.children(); while (children.hasMoreElements()) { final TemplateElement nextElement = children.nextElement();
/** * @return an array of the {@link TemplateElement}s containing the given column and line numbers. * @deprecated Should only be used internally, and might will be removed later. */ @Deprecated public TreePath containingElements(int column, int line) { final ArrayList elements = new ArrayList(); TemplateElement element = rootElement; mainloop: while (element.contains(column, line)) { elements.add(element); for (Enumeration enumeration = element.children(); enumeration.hasMoreElements(); ) { TemplateElement elem = (TemplateElement) enumeration.nextElement(); if (elem.contains(column, line)) { element = elem; continue mainloop; } } break; } if (elements.isEmpty()) { return null; } return new TreePath(elements.toArray()); }
private void extractVariables(TemplateElement templateElement, FieldsExtractor extractor) throws TemplateModelException { if (DOLLAR_VARIABLE.equals(templateElement.getClass().getSimpleName())) { String fieldName = templateElement.getCanonicalForm(); fieldName = fieldName.substring(2, fieldName.length() - 1); extractor.addFieldName(fieldName); } Enumeration<TemplateElement> enums = templateElement.children(); while (enums.hasMoreElements()) { TemplateElement element = (TemplateElement) enums.nextElement(); extractVariables(element, extractor); } }
@Override protected TemplateElement[] accept(Environment env) throws TemplateException, IOException { if (!DebuggerService.suspendEnvironment( env, this.getTemplate().getSourceName(), getChild(0).getBeginLine())) { return getChild(0).accept(env); } else { throw new StopException(env, "Stopped by debugger"); } }
private void removeDebugBreaks(TemplateElement te) { int count = te.getChildCount(); for (int i = 0; i < count; ++i) { TemplateElement child = _CoreAPI.getChildElement(te, i); while (child instanceof DebugBreak) { TemplateElement dbchild = _CoreAPI.getChildElement(child, 0); te.setChildAt(i, dbchild); child = dbchild; } removeDebugBreaks(child); } }
public Enumeration children() { final Enumeration e = element.children(); return new Enumeration() { public boolean hasMoreElements() { return e.hasMoreElements(); } public Object nextElement() { return getNode((TemplateElement) e.nextElement()); } }; }
private void removeDebugBreaks(TemplateElement te) { int count = te.getChildCount(); for(int i = 0; i < count; ++i) { TemplateElement child = (TemplateElement)te.getChildAt(i); while(child instanceof DebugBreak) { TemplateElement dbchild = (TemplateElement)child.getChildAt(0); te.setChildAt(i, dbchild); child = dbchild; } removeDebugBreaks(child); } }
static void appendInstructionStackItem(TemplateElement stackEl, StringBuilder sb) { sb.append(_MessageUtil.shorten(stackEl.getDescription(), 40)); sb.append(" ["); Macro enclosingMacro = getEnclosingMacro(stackEl); if (enclosingMacro != null) { sb.append(_MessageUtil.formatLocationForEvaluationError( enclosingMacro, stackEl.beginLine, stackEl.beginColumn)); } else { sb.append(_MessageUtil.formatLocationForEvaluationError( stackEl.getTemplate(), stackEl.beginLine, stackEl.beginColumn)); } sb.append("]"); }
/** * "Visit" the template element. */ void visit(TemplateElement element) throws IOException, TemplateException { // ATTENTION: This method body is manually "inlined" into visit(TemplateElement[]); keep them in sync! pushElement(element); try { TemplateElement[] templateElementsToVisit = element.accept(this); if (templateElementsToVisit != null) { for (TemplateElement el : templateElementsToVisit) { if (el == null) { break; // Skip unused trailing buffer capacity } visit(el); } } } catch (TemplateException te) { handleTemplateException(te); } finally { popElement(); } // ATTENTION: This method body above is manually "inlined" into visit(TemplateElement[]); keep them in sync! }
Set<String> result = new HashSet<>(); TemplateElement rootTreeNode = template.getRootTreeNode(); for (int i = 0; i < rootTreeNode.getChildCount(); i++) { TemplateModel templateModel = rootTreeNode.getChildNodes().get(i); if (!(templateModel instanceof StringModel)) { continue;
@Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof TemplateElement) { return ((TemplateElement) value).getDescription(); } return value.toString(); }
public int getChildCount() { return element.getChildCount(); }
/** * Outputs the instruction stack. Useful for debugging. * {@link TemplateException}s incorporate this information in their stack * traces. */ public void outputInstructionStack(PrintWriter pw) { pw.println("----------"); ListIterator iter = elementStack.listIterator(elementStack.size()); if(iter.hasPrevious()) { pw.print("==> "); TemplateElement prev = (TemplateElement) iter.previous(); pw.print(prev.getDescription()); pw.print(" ["); pw.print(prev.getStartLocation()); pw.println("]"); } while(iter.hasPrevious()) { TemplateElement prev = (TemplateElement) iter.previous(); if (prev instanceof UnifiedCall || prev instanceof Include) { String location = prev.getDescription() + " [" + prev.getStartLocation() + "]"; if(location != null && location.length() > 0) { pw.print(" in "); pw.println(location); } } } pw.println("----------"); pw.flush(); }
final String canonicalForm = templateElement.getCanonicalForm(); new Object[]{templateElement.getNodeName(), expression}); final Enumeration<TemplateElement> children = templateElement.children(); while (children.hasMoreElements()) { final TemplateElement nextElement = children.nextElement();
/** * @return an array of the {@link TemplateElement}s containing the given column and line numbers. * @deprecated Should only be used internally, and might will be removed later. */ @Deprecated public List containingElements(int column, int line) { final ArrayList elements = new ArrayList(); TemplateElement element = rootElement; mainloop: while (element.contains(column, line)) { elements.add(element); for (Enumeration enumeration = element.children(); enumeration.hasMoreElements(); ) { TemplateElement elem = (TemplateElement) enumeration.nextElement(); if (elem.contains(column, line)) { element = elem; continue mainloop; } } break; } return elements.isEmpty() ? null : elements; }