com.sonar.sslr.api.Token.getLine()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中com.sonar.sslr.api.Token.getLine()方法的一些代码示例,展示了Token.getLine()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.getLine()方法的具体详情如下:
包路径:com.sonar.sslr.api.Token
类名称:Token
方法名:getLine

Token.getLine介绍

暂无

代码示例

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet.csharp/csharp-squid

private static void addTokenLinesToSet(Set<Integer> set, Token token) {
 int currentLine = token.getLine();
 for (String line : token.getOriginalValue().split("\r\n?+|\n", -1)) {
  set.add(currentLine);
  currentLine++;
 }
}

代码示例来源:origin: org.sonarsource.sonar-plugins.javascript/javascript-squid

public int startOffset(Token token) {
 int lineStartOffset = lineStartOffsets.get(token.getLine() - 1);
 int column = token.getColumn();
 return lineStartOffset + column;
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-checks

@Override
public void leaveNode(Tree tree) {
 expectedLevel -= indentationLevel;
 isBlockAlreadyReported = false;
 lastCheckedLine = ((JavaTree) tree).getLastToken().getLine();
 if (isClassTree(tree)) {
  isInAnonymousClass.pop();
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.python/python-checks

private void checkBranch(List<AstNode> branches, int index) {
 for (int j = 0; j < index; j++) {
  if (CheckUtils.equalNodes(branches.get(j), branches.get(index))) {
   String message = String.format(MESSAGE, branches.get(j).getToken().getLine() + 1);
   getContext().createLineViolation(this, message, branches.get(index).getToken().getLine() + 1);
   return;
  }
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.python/python-checks

private void checkName(Token token) {
 String name = token.getValue();
 if (!pattern.matcher(name).matches()) {
  getContext().createLineViolation(this, String.format(MESSAGE, name, format), token.getLine());
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.python/python-checks

private void checkName(Token token, String type) {
 String name = token.getValue();
 if (!pattern.matcher(name).matches()) {
  getContext().createLineViolation(this, String.format(MESSAGE, type, name, format), token.getLine());
 }
}

代码示例来源:origin: org.sonarsource.sslr/sslr-core

private static Pos getTokenStart(Token token) {
 Pos pos = new Pos();
 pos.line = token.getLine();
 pos.column = token.getColumn();
 return pos;
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-checks

@Override
public void visitToken(Token token) {
 if (lastTokenIsRightCurlyBrace && lastTokenLine != token.getLine() && NEXT_BLOCKS.contains(token.getValue())) {
  getContext().createLineViolation(this, "Move this \"" + token.getValue() + "\" on the same line that the previous closing curly brace.", token);
 }
 lastTokenIsRightCurlyBrace = "}".equals(token.getValue());
 lastTokenLine = token.getLine();
}

代码示例来源:origin: org.codehaus.sonar.sslr/sslr-devkit

public int getEndOffset(Token token) {
 String[] tokenLines = token.getOriginalValue().split("(\r)?\n", -1);
 int tokenLastLine = token.getLine() + tokenLines.length - 1;
 int tokenLastLineColumn = (tokenLines.length > 1 ? 0 : token.getColumn()) + tokenLines[tokenLines.length - 1].length();
 return getOffset(tokenLastLine, tokenLastLineColumn);
}

代码示例来源:origin: SonarSource/sslr

public int getEndOffset(Token token) {
 String[] tokenLines = token.getOriginalValue().split(NEWLINE_REGEX, -1);
 int tokenLastLine = token.getLine() + tokenLines.length - 1;
 int tokenLastLineColumn = (tokenLines.length > 1 ? 0 : token.getColumn()) + tokenLines[tokenLines.length - 1].length();
 return getOffset(tokenLastLine, tokenLastLineColumn);
}

代码示例来源:origin: racodond/sonar-css-plugin

private static List<SyntaxTrivia> createTrivias(List<Trivia> trivias, boolean hasByteOrderMark) {
 List<SyntaxTrivia> result = Lists.newArrayList();
 for (Trivia trivia : trivias) {
  Token trivialToken = trivia.getToken();
  int column = column(hasByteOrderMark, trivialToken.getLine(), trivialToken.getColumn());
  result.add(InternalSyntaxTrivia.create(trivialToken.getValue(), trivialToken.getLine(), column));
 }
 return result;
}

代码示例来源:origin: SonarSource/sonar-java

private static List<SyntaxTrivia> createTrivias(List<Trivia> trivias) {
 List<SyntaxTrivia> result = Lists.newArrayList();
 for (Trivia trivia : trivias) {
  Token trivialToken = trivia.getToken();
  result.add(InternalSyntaxTrivia.create(trivialToken.getValue(), trivialToken.getLine(), trivialToken.getColumn()));
 }
 return result;
}

代码示例来源:origin: org.codehaus.sonar-plugins.php/php-checks

@Override
public void visitNode(AstNode astNode) {
 Token token = astNode.getToken();
 if (token.getColumn() != 0 || token.getLine() != 1 || !OPENING_TAG.matcher(token.getOriginalValue()).matches()) {
  getContext().createLineViolation(this, "Remove the extra characters before the open tag.", astNode);
 }
}

代码示例来源:origin: org.sonarsource.flex/flex-checks

private void checkParameters(AstNode functionDef) {
 for (AstNode paramIdentifier : Function.getParametersIdentifiers(functionDef)) {
  String paramName = paramIdentifier.getTokenValue();
  AstNode field = classStack.peek().getFieldNamed(paramName);
  if (field != null) {
   addIssue(MessageFormat.format(MESSAGE, paramName, field.getToken().getLine()), paramIdentifier);
  }
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-checks

private void checkIndentation(List<? extends Tree> trees) {
 for (Tree tree : trees) {
  int column = getColumn(tree);
  if (column != expectedLevel && !isExcluded(tree)) {
   addIssue(tree, "Make this line start at column " + (expectedLevel + 1) + ".");
   isBlockAlreadyReported = true;
  }
  lastCheckedLine = ((JavaTree) tree).getLastToken().getLine();
 }
}

代码示例来源:origin: org.codehaus.sonar.sslr-squid-bridge/sslr-squid-bridge

@Override
public void visitToken(Token token) {
 for (Trivia trivia : token.getTrivia()) {
  if (trivia.isComment() && trivia.getToken().getLine() < token.getLine()) {
   String comment = trivia.getToken().getOriginalValue();
   if (!comment.startsWith(getSingleLineCommentSyntaxPrefix()) && !StringUtils.containsAny(comment, "\r\n")) {
    getContext().createLineViolation(this, "This single line comment should use the single line comment syntax \"{0}\"", trivia.getToken(),
     getSingleLineCommentSyntaxPrefix());
   }
  }
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.css/css-squid

@Override
public void visitToken(Token token) {
 for (Trivia trivia : token.getTrivia()) {
  if (trivia.isComment()) {
   Token triviaToken = trivia.getToken();
   int offset = getOffset(triviaToken.getLine(), triviaToken.getColumn());
   highlighting.highlight(offset, offset + triviaToken.getValue().length(), "cppd");
  }
 }
}

代码示例来源:origin: org.sonarsource.flex/flex-checks

@Override
public void visitToken(Token token) {
 for (Trivia trivia : token.getTrivia()) {
  String[] lines = regexpToDivideStringByLine.split(FlexCommentAnalyser.getContents(trivia.getToken().getOriginalValue()));
  for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) {
   if (codeRecognizer.isLineOfCode(lines[lineOffset])) {
    addIssueAtLine("Sections of code should not be \"commented out\".", trivia.getToken().getLine() + lineOffset);
    break;
   }
  }
 }
}

代码示例来源:origin: octo-technology/sonar-objective-c

public void tokenize(SourceCode source, Tokens cpdTokens) throws IOException {
  Lexer lexer = ObjectiveCLexer.create(new ObjectiveCConfiguration(charset));
  String fileName = source.getFileName();
  List<Token> tokens = lexer.lex(new File(fileName));
  for (Token token : tokens) {
    TokenEntry cpdToken = new TokenEntry(getTokenImage(token), fileName, token.getLine());
    cpdTokens.add(cpdToken);
  }
  cpdTokens.add(TokenEntry.getEOF());
}

代码示例来源:origin: org.codehaus.sonar-plugins.erlang/erlang-squid

@Override
 public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) {
  String className = astNode.getFirstDescendant(ErlangGrammarImpl.moduleAttr).getFirstChild(ErlangGrammarImpl.atom).getTokenValue();
  SourceClass cls = new SourceClass(className + ":"
   + astNode.getToken().getLine());
  cls.setStartAtLine(astNode.getTokenLine());
  return cls;
 }
}, ErlangGrammarImpl.module));

相关文章