VelocityParser { public int getKeyWord(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context) throws InvalidVelocityException { int i = currentIndex; if (i + 1 >= array.length) { throw new InvalidVelocityException(); } if (array[i + 1] == '#') { i = getSimpleComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '*') { i = getMultilinesComment(array, currentIndex, velocityBlock, context); } else if (array[i + 1] == '{' || Character.isLetter(array[i + 1])) { i = getDirective(array, currentIndex, velocityBlock, context); } else { throw new InvalidVelocityException(); } return i; }  int getKeyWord(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVelocityIdentifier(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); boolean isValidVelocityIdentifierChar(char c); int getDirectiveName(char[] array, int currentIndex, StringBuffer directiveName, StringBuffer velocityBlock,
        VelocityParserContext context); int getDirectiveEndOfLine(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getVar(char[] array, int currentIndex, StringBuffer varName, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodOrProperty(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getParameters(char[] array, int currentIndex, StringBuffer velocityBlock, char endingChar,
        VelocityParserContext context); int getEscape(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getWhiteSpaces(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context); int getSpaces(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); int getMacroParameter(char[] array, int currentIndex, StringBuffer velocityBlock,
        VelocityParserContext context); static final Set<String> VELOCITYDIRECTIVE_BEGIN; static final Set<String> VELOCITYDIRECTIVE_END; static final Set<String> VELOCITYDIRECTIVE_PARAM; static final Set<String> VELOCITYDIRECTIVE_NOPARAM; static final Set<String> VELOCITYDIRECTIVE_ALL; }
@Test void getKeyWordComment() throws InvalidVelocityException { VelocityParserContext context = new VelocityParserContext(); StringBuffer buffer = new StringBuffer(); int index = this.parser.getKeyWord("## some comment\n ".toCharArray(), 0, buffer, context); assertEquals("## some comment\n".length(), index); assertEquals("## some comment\n", buffer.toString()); assertFalse(context.isInVelocityBlock()); assertEquals(VelocityType.COMMENT, context.getType()); }
@Test void getKeyWordMultiLinesComment() throws InvalidVelocityException { VelocityParserContext context = new VelocityParserContext(); StringBuffer buffer = new StringBuffer(); int index = this.parser.getKeyWord("#*\n some comment\n*# ".toCharArray(), 0, buffer, context); assertEquals("#*\n some comment\n*#".length(), index); assertEquals("#*\n some comment\n*#", buffer.toString()); assertFalse(context.isInVelocityBlock()); assertEquals(VelocityType.COMMENT, context.getType()); }
@Test void getKeyWordDirective() throws InvalidVelocityException { VelocityParserContext context = new VelocityParserContext(); StringBuffer buffer = new StringBuffer(); int index = this.parser.getKeyWord("#directive(param1 param2, param2) ".toCharArray(), 0, buffer, context); assertEquals("#directive(param1 param2, param2)".length(), index); assertEquals("#directive(param1 param2, param2)", buffer.toString()); assertFalse(context.isInVelocityBlock()); assertEquals(VelocityType.MACRO, context.getType()); }