本文整理汇总了Java中com.sonar.sslr.api.Trivia类的典型用法代码示例。如果您正苦于以下问题:Java Trivia类的具体用法?Java Trivia怎么用?Java Trivia使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Trivia类属于com.sonar.sslr.api包,在下文中一共展示了Trivia类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visitToken
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public void visitToken(Token token) {
if (token.getType().equals(PuppetTokenType.SINGLE_QUOTED_STRING_LITERAL) || token.getType().equals(PuppetTokenType.DOUBLE_QUOTED_STRING_LITERAL)) {
// case: string literal, including doc string
highlight(token, TypeOfText.STRING);
} else if (token.getType() instanceof PuppetKeyword) {
// case: keyword
highlight(token, TypeOfText.KEYWORD);
}
for (Trivia trivia : token.getTrivia()) {
// case: comment
highlight(trivia.getToken(), TypeOfText.COMMENT);
}
}
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:17,代码来源:PuppetHighlighter.java
示例2: visitToken
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public void visitToken(Token token) {
Iterator iterator = token.getTrivia().iterator();
while (iterator.hasNext()) {
Trivia trivia = (Trivia) iterator.next();
if (trivia.isComment() && pattern.matcher(trivia.getToken().getOriginalValue()).matches()) {
addIssue(trivia.getToken().getLine(), this, "Use starting comment token '#' instead.");
}
}
}
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:11,代码来源:CommentConventionCheck.java
示例3: visitToken
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
public void visitToken(Token token) {
for (Trivia trivia : token.getTrivia()) {
String comment = trivia.getToken().getOriginalValue();
if (StringUtils.containsIgnoreCase(comment, pattern)) {
String[] lines = comment.split("\r\n?|\n");
for (int i = 0; i < lines.length; i++) {
if (StringUtils.containsIgnoreCase(lines[i], pattern) && !isLetterAround(lines[i], pattern)) {
check.addIssue(trivia.getToken().getLine() + i, check, message);
}
}
}
}
}
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:15,代码来源:CommentContainsPatternChecker.java
示例4: afterParse
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public void afterParse(final PostParseEvent<Token.Builder> event)
{
final int length = reader.length();
/*
* We want a match
*/
final ParsingResult<Token.Builder> result = event.getResult();
if (!result.isSuccess())
throw new GrappaException("match failure (consumed: "
+ consumed + " out of " + length + ')');
/*
* Check that we did consume all the text
*/
if (consumed != length)
throw new GrappaException("was expecting to fully match, but only "
+ consumed + " chars were matched out of " + length);
final ValueStack<Token.Builder> stack = result.getValueStack();
final URI uri = lexer.getURI();
final int size = stack.size();
Token token;
for (int index = size - 1; index >= 0; index--) {
token = stack.peek(index).setURI(uri).build();
if (token.getType() == GenericTokenType.COMMENT)
lexer.addTrivia(Trivia.createComment(token));
else
lexer.addToken(token);
}
}
开发者ID:litesolutions,项目名称:sonar-sslr-grappa,代码行数:37,代码来源:CodeReaderListener.java
示例5: createTerminal
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public Object createTerminal(Input input, int startIndex, int endIndex, List<Trivia> trivias, TokenType type) {
char[] fileChars = input.input();
boolean hasByteOrderMark = fileChars.length > 0 && fileChars[0] == BYTE_ORDER_MARK;
boolean isEof = GenericTokenType.EOF.equals(type);
LineColumnValue lineColumnValue = tokenPosition(input, startIndex, endIndex);
return new InternalSyntaxToken(
lineColumnValue.line,
column(hasByteOrderMark, lineColumnValue.line, lineColumnValue.column),
lineColumnValue.value,
isEof,
isByteOrderMark(input, startIndex, endIndex));
}
开发者ID:racodond,项目名称:sonar-json-plugin,代码行数:14,代码来源:JSONNodeBuilder.java
示例6: visitToken
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
public void visitToken(Token token) {
if (token.getType().equals(GenericTokenType.EOF)) {
return;
}
linesOfCode.add(token.getLine());
List<Trivia> trivias = token.getTrivia();
for (Trivia trivia : trivias) {
if (trivia.isComment()) {
linesOfComments.add(trivia.getToken().getLine());
}
}
}
开发者ID:Ne0s,项目名称:sonar-plsql,代码行数:14,代码来源:FileLinesVisitor.java
示例7: visitToken
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public void visitToken(Token token) {
if (token.getType().equals(GenericTokenType.EOF)) {
return;
}
linesOfCode.add(token.getLine());
List<Trivia> trivias = token.getTrivia();
for (Trivia trivia : trivias) {
if (trivia.isComment()) {
linesOfComments.add(trivia.getToken().getLine());
}
}
}
开发者ID:SonarQubeCommunity,项目名称:sonar-lua,代码行数:15,代码来源:FileLinesVisitor.java
示例8: visitFile
import com.sonar.sslr.api.Trivia; //导入依赖的package包/类
@Override
public void visitFile(@Nullable AstNode astNode) {
NewHighlighting highlighting = context.newHighlighting();
File file = getContext().getFile();
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().is(file));
highlighting.onFile(inputFile);
NewCpdTokens cpdTokens = context.newCpdTokens();
cpdTokens.onFile(inputFile);
Iterator<Token> iterator = lexer.lex(file).iterator();
while (iterator.hasNext()) {
Token token = iterator.next();
TokenType tokenType = token.getType();
if (!tokenType.equals(GenericTokenType.EOF)) {
TokenLocation tokenLocation = new TokenLocation(token);
cpdTokens.addToken(tokenLocation.startLine(), tokenLocation.startCharacter(), tokenLocation.endLine(), tokenLocation.endCharacter(), getTokenImage(token));
}
if (tokenType.equals(LuaTokenType.NUMBER)) {
highlight(highlighting, token, TypeOfText.CONSTANT);
} else if (tokenType.equals(GenericTokenType.LITERAL)) {
highlight(highlighting, token, TypeOfText.STRING);
} else if (KEYWORDS.contains(tokenType)) {
highlight(highlighting, token, TypeOfText.KEYWORD);
}
for (Trivia trivia : token.getTrivia()) {
highlight(highlighting, trivia.getToken(), TypeOfText.COMMENT);
}
}
highlighting.save();
cpdTokens.save();
}
开发者ID:SonarQubeCommunity,项目名称:sonar-lua,代码行数:37,代码来源:LuaTokensVisitor.java
注:本文中的com.sonar.sslr.api.Trivia类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论