@Override
  public void visitAssignmentExpression(AssignmentExpressionTree tree) {
    super.visitAssignmentExpression(tree);

    if (tree.is(Kind.ASSIGNMENT, Kind.ASSIGNMENT_BY_REFERENCE)) {
      check(tree.variable(), tree.value());
    }
  }
 @Override
 public void visitParameterList(ParameterListTree parameterList) {
   List<ParameterTree> parametersToMove = getParametersToMove(parameterList);
   if (!parametersToMove.isEmpty() && !isVariableLengthParameterList(parameterList)) {
     context()
         .newIssue(this, String.format(MESSAGE, getNameListString(parametersToMove)))
         .tree(parameterList);
   }
   super.visitParameterList(parameterList);
 }
  @Override
  public void visitCompilationUnit(CompilationUnitTree tree) {
    initScan();

    super.visitCompilationUnit(tree);

    if (inlineHTMLCounter == 1 && isOnlyClosingTag) {
      context().newIssue(this, MESSAGE).tree(lastInlineHTMLToken);
    }
  }
 @Override
 public void visitBinaryExpression(BinaryExpressionTree tree) {
   if (tree.is(
       Kind.CONDITIONAL_AND,
       Kind.CONDITIONAL_OR,
       Kind.ALTERNATIVE_CONDITIONAL_AND,
       Kind.ALTERNATIVE_CONDITIONAL_OR)) {
     incrementComplexity();
   }
   super.visitBinaryExpression(tree);
 }
  @Override
  public void visitIfStatement(IfStatementTree tree) {
    super.visitIfStatement(tree);

    List<ElseifClauseTree> elseifClauses = tree.elseifClauses();

    if (!elseifClauses.isEmpty() && tree.elseClause() == null) {
      ElseifClauseTree lastElseIf = elseifClauses.get(elseifClauses.size() - 1);
      context().newIssue(this, lastElseIf.elseifToken(), MESSAGE);
    }
  }
  @Override
  public void visitElseClause(ElseClauseTree tree) {
    super.visitElseClause(tree);

    if (tree.is(Kind.ELSE_CLAUSE) && tree.statements().get(0).is(Kind.IF_STATEMENT)) {
      IfStatementTree nestedIf = (IfStatementTree) tree.statements().get(0);

      if (nestedIf.elseClause() == null && nestedIf.elseifClauses().isEmpty()) {
        context().newIssue(this, tree.elseToken(), nestedIf.ifToken(), MESSAGE);
      }
    }
  }
  @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);
  }
 @Override
 public void visitReturnStatement(ReturnStatementTree tree) {
   incrementComplexity();
   super.visitReturnStatement(tree);
 }
 @Override
 public void visitThrowStatement(ThrowStatementTree tree) {
   incrementComplexity();
   super.visitThrowStatement(tree);
 }
 @Override
 public void visitForEachStatement(ForEachStatementTree tree) {
   incrementComplexity();
   super.visitForEachStatement(tree);
 }
 @Override
 public void visitDoWhileStatement(DoWhileStatementTree tree) {
   incrementComplexity();
   super.visitDoWhileStatement(tree);
 }
 @Override
 public void visitCaseClause(CaseClauseTree tree) {
   incrementComplexity();
   super.visitCaseClause(tree);
 }
 @Override
 public void visitFunctionExpression(FunctionExpressionTree tree) {
   processFunction(tree);
   super.visitFunctionExpression(tree);
 }
 @Override
 public void visitFunctionDeclaration(FunctionDeclarationTree tree) {
   processFunction(tree);
   super.visitFunctionDeclaration(tree);
 }
 @Override
 public void visitMethodDeclaration(MethodDeclarationTree tree) {
   if (tree.body().is(Tree.Kind.BLOCK)) {
     super.visitBlock((BlockTree) tree.body());
   }
 }
 @Override
 public void visitCatchBlock(CatchBlockTree tree) {
   incrementComplexity();
   super.visitCatchBlock(tree);
 }
 @Override
 public void visitFunctionDeclaration(FunctionDeclarationTree tree) {
   super.visitBlock(tree.body());
 }
 @Override
 public void visitUseTraitDeclaration(UseTraitDeclarationTree tree) {
   super.visitUseTraitDeclaration(tree);
   check(tree.adaptations(), tree.closeCurlyBraceToken(), tree.openCurlyBraceToken());
 }
 @Override
 public void visitSwitchStatement(SwitchStatementTree tree) {
   super.visitSwitchStatement(tree);
   check(tree.cases(), tree.closeCurlyBraceToken(), tree.openCurlyBraceToken());
 }
 @Override
 public void visitBlock(BlockTree tree) {
   super.visitBlock(tree);
   check(tree.statements(), tree.closeCurlyBraceToken(), tree);
 }
 @Override
 public void visitConditionalExpression(ConditionalExpressionTree tree) {
   incrementComplexity();
   super.visitConditionalExpression(tree);
 }
Esempio n. 22
0
 public CommentLineVisitor(CompilationUnitTree tree) {
   super.visitCompilationUnit(tree);
 }