View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.cpd;
    5
    6   import java.io.StringReader;
    7
    8   import net.sourceforge.pmd.lang.Language;
    9   import net.sourceforge.pmd.lang.LanguageVersionHandler;
    10  import net.sourceforge.pmd.lang.TokenManager;
    11  import net.sourceforge.pmd.lang.jsp.ast.Token;
    12
    13  public class JSPTokenizer implements Tokenizer {
    14
    15      public void tokenize(SourceCode sourceCode, Tokens tokenEntries) {
    16  	StringBuilder buffer = sourceCode.getCodeBuffer();
    17  	LanguageVersionHandler languageVersionHandler = Language.JSP.getDefaultVersion().getLanguageVersionHandler();
    18  	TokenManager tokenMgr = languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions())
    19  		.getTokenManager(sourceCode.getFileName(), new StringReader(buffer.toString()));
    20  	Token currentToken = (Token) tokenMgr.getNextToken();
    21  	while (currentToken.image.length() > 0) {
    22  	    tokenEntries.add(new TokenEntry(String.valueOf(currentToken.kind), sourceCode.getFileName(),
    23  		    currentToken.beginLine));
    24  	    currentToken = (Token) tokenMgr.getNextToken();
    25  	}
    26  	tokenEntries.add(TokenEntry.getEOF());
    27      }
    28  }