TemplateParser implements Parser { static List<String> splitDefine(String value) { List<String> vs = new ArrayList<String>(); Matcher matcher = DEFINE_PATTERN.matcher(value); while (matcher.find()) { StringBuffer rep = new StringBuffer(); matcher.appendReplacement(rep, "$1"); String v = rep.toString(); if (v.contains(",")) { if (!v.contains("<")) { vs.addAll(Arrays.asList(v.split(","))); } else if (v.indexOf(',') < v.indexOf('<')) { int j = v.indexOf('<'); int i = v.substring(0, j).lastIndexOf(','); vs.addAll(Arrays.asList(v.substring(0, i).split(","))); vs.add(v.substring(i + 1)); } else { vs.add(v); } } else { vs.add(v); } } if (vs.size() == 0) { vs = Arrays.asList(value.split(",")); } else { StringBuffer tail = new StringBuffer(); matcher.appendTail(tail); if (tail.toString().trim().length() > 0) { vs.add(tail.toString()); } } return vs; }  void setRemoveDirectiveBlankLine(boolean removeDirectiveBlankLine); void setSetDirective(String[] setDirective); void setIfDirective(String[] ifDirective); void setElseDirective(String[] elseDirective); void setForDirective(String[] forDirective); void setBreakDirective(String[] breakDirective); void setMacroDirective(String[] macroDirective); void setEndDirective(String[] endDirective); void setDefaultVariableType(String defaultVariableType); void setImportMacros(String[] importMacros); void setEngine(Engine engine); void setExpressionParser(Parser expressionParser); void setImportPackages(String[] importPackages); void setImportVariables(String[] importVariables); void setImportMethods(Object[] importMethods); String[] getImportDirective(); void init(); void inited(); Node parse(String source, int offset);  }
@Test public void testSplitDefine() throws Exception { List<String> list = TemplateParser.splitDefine("book"); Assert.assertEquals(1, list.size()); Assert.assertEquals("book", list.get(0)); list = TemplateParser.splitDefine("book1, book2"); Assert.assertEquals(2, list.size()); Assert.assertEquals("book1", list.get(0)); Assert.assertEquals(" book2", list.get(1)); list = TemplateParser.splitDefine("book1, book2, book3"); Assert.assertEquals(3, list.size()); Assert.assertEquals("book1", list.get(0)); Assert.assertEquals(" book2", list.get(1)); Assert.assertEquals(" book3", list.get(2)); list = TemplateParser.splitDefine("Book book"); Assert.assertEquals(1, list.size()); Assert.assertEquals("Book book", list.get(0)); list = TemplateParser.splitDefine("Book book1, Book book2"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Book book1", list.get(0)); Assert.assertEquals(" Book book2", list.get(1)); list = TemplateParser.splitDefine("Book book1, Book book2, Book book3"); Assert.assertEquals(3, list.size()); Assert.assertEquals("Book book1", list.get(0)); Assert.assertEquals(" Book book2", list.get(1)); Assert.assertEquals(" Book book3", list.get(2)); list = TemplateParser.splitDefine("Map<String, Book> books"); Assert.assertEquals(1, list.size()); Assert.assertEquals("Map<String, Book> books", list.get(0)); list = TemplateParser.splitDefine("Map<String, Book> bookMap, Map<String, Book> bookMap2"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Map<String, Book> bookMap", list.get(0)); Assert.assertEquals(" Map<String, Book> bookMap2", list.get(1)); list = TemplateParser.splitDefine("Map<String, Book> bookMap, Map<String, Book> bookMap2, Map<String, Book> bookMap3"); Assert.assertEquals(3, list.size()); Assert.assertEquals("Map<String, Book> bookMap", list.get(0)); Assert.assertEquals(" Map<String, Book> bookMap2", list.get(1)); Assert.assertEquals(" Map<String, Book> bookMap3", list.get(2)); list = TemplateParser.splitDefine("Book book1, book2"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Book book1", list.get(0)); Assert.assertEquals(" book2", list.get(1)); list = TemplateParser.splitDefine("Map<String, Book> bookMap, book"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Map<String, Book> bookMap", list.get(0)); Assert.assertEquals(" book", list.get(1)); list = TemplateParser.splitDefine("Map<String, Book> bookMap, Book book"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Map<String, Book> bookMap", list.get(0)); Assert.assertEquals(" Book book", list.get(1)); list = TemplateParser.splitDefine("Map<String, Book> bookMap, Book book1, book2"); Assert.assertEquals(3, list.size()); Assert.assertEquals("Map<String, Book> bookMap", list.get(0)); Assert.assertEquals(" Book book1", list.get(1)); Assert.assertEquals(" book2", list.get(2)); list = TemplateParser.splitDefine("book1, Book book2"); Assert.assertEquals(2, list.size()); Assert.assertEquals("book1", list.get(0)); Assert.assertEquals(" Book book2", list.get(1)); list = TemplateParser.splitDefine("book, Map<String, Book> bookMap"); Assert.assertEquals(2, list.size()); Assert.assertEquals("book", list.get(0)); Assert.assertEquals(" Map<String, Book> bookMap", list.get(1)); list = TemplateParser.splitDefine("Book book, Map<String, Book> bookMap"); Assert.assertEquals(2, list.size()); Assert.assertEquals("Book book", list.get(0)); Assert.assertEquals(" Map<String, Book> bookMap", list.get(1)); list = TemplateParser.splitDefine("book1, Book book2, Map<String, Book> bookMap"); Assert.assertEquals(3, list.size()); Assert.assertEquals("book1", list.get(0)); Assert.assertEquals(" Book book2", list.get(1)); Assert.assertEquals(" Map<String, Book> bookMap", list.get(2)); }