Пример #1
0
 private void checkModifiers(List<SyntaxToken> modifiers) {
   if (modifiers.size() > 1) {
     int i = 0;
     for (SyntaxToken modifier : modifiers) {
       String normalizedModifier = modifier.text().toLowerCase(Locale.ENGLISH);
       while (i < EXPECTED_ORDER.length && !EXPECTED_ORDER[i].equals(normalizedModifier)) {
         i++;
       }
     }
     if (i == EXPECTED_ORDER.length) {
       context().newIssue(this, MESSAGE).tree(modifiers.get(0));
     }
   }
 }
 @Override
 public void visitToken(SyntaxToken token) {
   if (token.is(Kind.INLINE_HTML_TOKEN)) {
     inlineHTMLCounter++;
     isOnlyClosingTag = CheckUtils.isClosingTag(token);
     lastInlineHTMLToken = token;
   }
 }
  /**
   * Check that there is exactly one space between a control structure keyword and a opening
   * parenthesis or curly brace.
   */
  private void checkSpaceBetweenKeywordAndNextNode(SyntaxToken keyword, SyntaxToken nextToken) {
    if (TokenUtils.isType(nextToken, PHPPunctuator.LCURLYBRACE, PHPPunctuator.LPARENTHESIS)
        && TokenUtils.isOnSameLine(keyword, nextToken)) {
      int nbSpace = TokenUtils.getNbSpaceBetween(keyword, nextToken);

      if (nbSpace != 1) {
        String endMessage =
            String.format(
                CONTROL_STRUCTURES_KEYWORD_MESSAGE,
                keyword.text(),
                TokenUtils.isType(nextToken, PHPPunctuator.LPARENTHESIS)
                    ? "parenthesis."
                    : "curly brace.");
        check.reportIssue(TokenUtils.buildIssueMsg(nbSpace, endMessage), keyword);
      }
    }
  }
Пример #4
0
  @Override
  public void visitToken(SyntaxToken token) {
    for (SyntaxTrivia trivia : token.trivias()) {

      String[] commentLines = getContents(trivia.text()).split("(\r)?\n|\r", -1);
      int line = trivia.line();
      for (String commentLine : commentLines) {
        if (commentLine.contains("NOSONAR")) {
          noSonarLines.add(line);
        } else if (!isBlank(commentLine)) {
          comments.add(line);
        }
        line++;
      }
    }

    super.visitToken(token);
  }
 private <T extends Tree> void check(
     List<T> statements, @Nullable SyntaxToken lastToken, Tree issueTree) {
   if (statements.isEmpty() && lastToken != null && lastToken.trivias().isEmpty()) {
     context().newIssue(this, MESSAGE).tree(issueTree);
   }
 }