use of com.sonar.sslr.api.TokenType in project sonar-web by SonarSource.
the class WebTokensVisitor method highlightAndDuplicate.
private void highlightAndDuplicate() {
NewHighlighting highlighting = context.newHighlighting();
InputFile inputFile = getWebSourceCode().inputFile();
highlighting.onFile(inputFile);
NewCpdTokens cpdTokens = context.newCpdTokens();
cpdTokens.onFile(inputFile);
for (Token token : WebLexer.create(context.fileSystem().encoding()).lex(inputFile.file())) {
TokenType tokenType = token.getType();
if (!tokenType.equals(GenericTokenType.EOF)) {
TokenLocation tokenLocation = new TokenLocation(token);
cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startCharacter(), tokenLocation.endLine(), tokenLocation.endCharacter(), token.getValue());
}
if (tokenType.equals(WebTokenType.DOCTYPE)) {
highlight(highlighting, token, TypeOfText.STRUCTURED_COMMENT);
} else if (tokenType.equals(WebTokenType.EXPRESSION)) {
highlight(highlighting, token, TypeOfText.ANNOTATION);
} else if (tokenType.equals(WebTokenType.TAG)) {
highlight(highlighting, token, TypeOfText.KEYWORD);
} else if (tokenType.equals(WebTokenType.ATTRIBUTE)) {
TokenLocation tokenLocation = new TokenLocation(token);
highlighting.highlight(tokenLocation.startLine(), tokenLocation.startCharacter() + /* = */
1, tokenLocation.endLine(), tokenLocation.endCharacter(), TypeOfText.STRING);
}
for (Trivia trivia : token.getTrivia()) {
highlight(highlighting, trivia.getToken(), TypeOfText.COMMENT);
}
}
highlighting.save();
cpdTokens.save();
}
Aggregations