@Test public void testLines() { Engine engine = Engine.builder().addDefaultSectionHelpers() .build(); Template template = engine.parse("{@org.acme.Foo foo}\n" + "<style type=\"text/css\">\n" + "body {\n" + " font-family: sans-serif;\n" + "}\n" + "{#for item in foo.items}\n\n" + "{item.name}" + "{/}"); assertEquals(6, find(template.getExpressions(), "foo.items").getOrigin().getLine()); assertEquals(8, find(template.getExpressions(), "item.name").getOrigin().getLine()); }
Template parse(Reader reader, Optional<Variant> variant, String id, String generatedId) { long start = System.currentTimeMillis(); this.id = id; this.generatedId = generatedId; this.variant = variant; try { int val; while ((val = reader.read()) != -1) { processCharacter((char) val); lineCharacter++; } if (buffer.length() > 0) { if (state == State.TEXT || state == State.LINE_SEPARATOR) { flushText(); } else { throw parserError( "unexpected non-text buffer at the end of the template - probably an unterminated tag: " + buffer); } } SectionNode.Builder root = sectionStack.peek(); if (root == null) { throw parserError("no root section found"); } if (!root.helperName.equals(ROOT_HELPER_NAME)) { throw parserError("unterminated section [" + root.helperName + "] detected"); } SectionBlock.Builder part = sectionBlockStack.peek(); if (part == null) { throw parserError("no root section part found"); } root.addBlock(part.build()); TemplateImpl template = new TemplateImpl(engine, root.build(), generatedId, variant); Set<TemplateNode> nodesToRemove; if (engine.removeStandaloneLines) { nodesToRemove = new HashSet<>(); List<List<TemplateNode>> lines = readLines(template.root); for (List<TemplateNode> line : lines) { if (isStandalone(line)) { for (TemplateNode node : line) { if (node instanceof SectionNode) { continue; } nodesToRemove.add(node); } } } } else { nodesToRemove = Collections.emptySet(); } template.root.optimizeNodes(nodesToRemove); LOGGER.tracef("Parsing finished in %s ms", System.currentTimeMillis() - start); return template; } catch (IOException e) { throw new TemplateException(e); } }
Parser implements Function<String, Expression>, ParserHelper { Template parse(Reader reader, Optional<Variant> variant, String id, String generatedId) { long start = System.currentTimeMillis(); this.id = id; this.generatedId = generatedId; this.variant = variant; try { int val; while ((val = reader.read()) != -1) { processCharacter((char) val); lineCharacter++; } if (buffer.length() > 0) { if (state == State.TEXT || state == State.LINE_SEPARATOR) { flushText(); } else { throw parserError( "unexpected non-text buffer at the end of the template - probably an unterminated tag: " + buffer); } } SectionNode.Builder root = sectionStack.peek(); if (root == null) { throw parserError("no root section found"); } if (!root.helperName.equals(ROOT_HELPER_NAME)) { throw parserError("unterminated section [" + root.helperName + "] detected"); } SectionBlock.Builder part = sectionBlockStack.peek(); if (part == null) { throw parserError("no root section part found"); } root.addBlock(part.build()); TemplateImpl template = new TemplateImpl(engine, root.build(), generatedId, variant); Set<TemplateNode> nodesToRemove; if (engine.removeStandaloneLines) { nodesToRemove = new HashSet<>(); List<List<TemplateNode>> lines = readLines(template.root); for (List<TemplateNode> line : lines) { if (isStandalone(line)) { for (TemplateNode node : line) { if (node instanceof SectionNode) { continue; } nodesToRemove.add(node); } } } } else { nodesToRemove = Collections.emptySet(); } template.root.optimizeNodes(nodesToRemove); LOGGER.tracef("Parsing finished in %s ms", System.currentTimeMillis() - start); return template; } catch (IOException e) { throw new TemplateException(e); } } }
Parser implements Function<String, Expression>, ParserHelper { Template parse(Reader reader, Optional<Variant> variant, String id, String generatedId) { long start = System.currentTimeMillis(); this.id = id; this.generatedId = generatedId; this.variant = variant; try { int val; while ((val = reader.read()) != -1) { processCharacter((char) val); lineCharacter++; } if (buffer.length() > 0) { if (state == State.TEXT || state == State.LINE_SEPARATOR) { flushText(); } else { throw parserError( "unexpected non-text buffer at the end of the template - probably an unterminated tag: " + buffer); } } SectionNode.Builder root = sectionStack.peek(); if (root == null) { throw parserError("no root section found"); } if (!root.helperName.equals(ROOT_HELPER_NAME)) { throw parserError("unterminated section [" + root.helperName + "] detected"); } SectionBlock.Builder part = sectionBlockStack.peek(); if (part == null) { throw parserError("no root section part found"); } root.addBlock(part.build()); TemplateImpl template = new TemplateImpl(engine, root.build(), generatedId, variant); Set<TemplateNode> nodesToRemove; if (engine.removeStandaloneLines) { nodesToRemove = new HashSet<>(); List<List<TemplateNode>> lines = readLines(template.root); for (List<TemplateNode> line : lines) { if (isStandalone(line)) { for (TemplateNode node : line) { if (node instanceof SectionNode) { continue; } nodesToRemove.add(node); } } } } else { nodesToRemove = Collections.emptySet(); } template.root.optimizeNodes(nodesToRemove); LOGGER.tracef("Parsing finished in %s ms", System.currentTimeMillis() - start); return template; } catch (IOException e) { throw new TemplateException(e); } } Parser(EngineImpl engine); }
Parser implements Function<String, Expression>, ParserHelper { Template parse(Reader reader, Optional<Variant> variant, String id, String generatedId) { long start = System.currentTimeMillis(); this.id = id; this.generatedId = generatedId; this.variant = variant; try { int val; while ((val = reader.read()) != -1) { processCharacter((char) val); lineCharacter++; } if (buffer.length() > 0) { if (state == State.TEXT || state == State.LINE_SEPARATOR) { flushText(); } else { throw parserError( "unexpected non-text buffer at the end of the template - probably an unterminated tag: " + buffer); } } SectionNode.Builder root = sectionStack.peek(); if (root == null) { throw parserError("no root section found"); } if (!root.helperName.equals(ROOT_HELPER_NAME)) { throw parserError("unterminated section [" + root.helperName + "] detected"); } SectionBlock.Builder part = sectionBlockStack.peek(); if (part == null) { throw parserError("no root section part found"); } root.addBlock(part.build()); TemplateImpl template = new TemplateImpl(engine, root.build(), generatedId, variant); Set<TemplateNode> nodesToRemove; if (engine.removeStandaloneLines) { nodesToRemove = new HashSet<>(); List<List<TemplateNode>> lines = readLines(template.root); for (List<TemplateNode> line : lines) { if (isStandalone(line)) { for (TemplateNode node : line) { if (node instanceof SectionNode) { continue; } nodesToRemove.add(node); } } } } else { nodesToRemove = Collections.emptySet(); } template.root.optimizeNodes(nodesToRemove); LOGGER.tracef("Parsing finished in %s ms", System.currentTimeMillis() - start); return template; } catch (IOException e) { throw new TemplateException(e); } } Parser(EngineImpl engine); @Override ExpressionImpl apply(String value); @Override void addParameter(String name, String type); }
Parser implements Function<String, Expression>, ParserHelper { Template parse(Reader reader, Optional<Variant> variant, String id, String generatedId) { long start = System.currentTimeMillis(); this.id = id; this.generatedId = generatedId; this.variant = variant; try { int val; while ((val = reader.read()) != -1) { processCharacter((char) val); lineCharacter++; } if (buffer.length() > 0) { if (state == State.TEXT || state == State.LINE_SEPARATOR) { flushText(); } else { throw parserError( "unexpected non-text buffer at the end of the template - probably an unterminated tag: " + buffer); } } SectionNode.Builder root = sectionStack.peek(); if (root == null) { throw parserError("no root section found"); } if (!root.helperName.equals(ROOT_HELPER_NAME)) { throw parserError("unterminated section [" + root.helperName + "] detected"); } SectionBlock.Builder part = sectionBlockStack.peek(); if (part == null) { throw parserError("no root section part found"); } root.addBlock(part.build()); TemplateImpl template = new TemplateImpl(engine, root.build(), generatedId, variant); Set<TemplateNode> nodesToRemove; if (engine.removeStandaloneLines) { nodesToRemove = new HashSet<>(); List<List<TemplateNode>> lines = readLines(template.root); for (List<TemplateNode> line : lines) { if (isStandalone(line)) { for (TemplateNode node : line) { if (node instanceof SectionNode) { continue; } nodesToRemove.add(node); } } } } else { nodesToRemove = Collections.emptySet(); } template.root.optimizeNodes(nodesToRemove); LOGGER.tracef("Parsing finished in %s ms", System.currentTimeMillis() - start); return template; } catch (IOException e) { throw new TemplateException(e); } } Parser(EngineImpl engine); @Override ExpressionImpl apply(String value); @Override void addParameter(String name, String type);  }