@Override public void leaveNode(Tree tree) { if (!tree.is(Kind.YIELD_EXPRESSION)) { boolean hasYield = hasYieldStack.removeLast(); if (!hasYield) { addIssue(new PreciseIssue(this, getPrimaryLocation(tree))); } } }
private void raiseIssue(FunctionTree tree, List<Tree> complexityTrees) { int complexity = complexityTrees.size(); String message = String.format(MESSAGE, complexity, maximumFunctionComplexityThreshold); IssueLocation primaryIssueLocation = new IssueLocation(tree.firstToken(), tree.parameterClause(), message); PreciseIssue issue = addIssue(new PreciseIssue(this, primaryIssueLocation)); for (Tree complexityTree : complexityTrees) { issue.secondary(complexityTree, "+1"); } issue.cost((double) complexity - maximumFunctionComplexityThreshold); }
private <T1 extends Tree, T2 extends Tree> void checkExpression( T1 tree, ExpressionTree symbolTree, Map<Symbol, T2> otherTypeUsageMap, Map<Symbol, T1> thisTypeUsageMap, String tail ) { Symbol symbol = getSymbol(symbolTree); if (symbol == null || symbol.external()) { return; } T2 otherTypeUsage = otherTypeUsageMap.get(symbol); if (otherTypeUsage != null && !hasIssue.contains(symbol)) { String message = String.format(MESSAGE, otherTypeUsage.firstToken().line(), tail); String secondaryMessage = String.format(SECONDARY_MESSAGE, tail); addIssue(new PreciseIssue(this, issueLocation(tree, message))) .secondary(issueLocation(otherTypeUsage, secondaryMessage)); hasIssue.add(symbol); } else { thisTypeUsageMap.put(symbol, tree); } }
private void checkCommentGroup(List<SyntaxTrivia> commentGroup) { String uncommentedText = uncomment(commentGroup); if (isRawExclusion(uncommentedText)) { return; } uncommentedText = injectMissingBraces(uncommentedText); try { ScriptTree parsedUncommentedText = (ScriptTree) PARSER.parse(uncommentedText); if (isExclusion(parsedUncommentedText)) { return; } IssueLocation primaryLocation = new IssueLocation(commentGroup.get(0), commentGroup.get(commentGroup.size() - 1), MESSAGE); addIssue(new PreciseIssue(this, primaryLocation)); } catch (RecognitionException e) { // do nothing, it's just a comment } }
private void raiseIssue(AccessorMethodDeclarationTree tree, String message) { addIssue(new PreciseIssue(this, new IssueLocation(tree, tree.name(), message))); }
private void checkFunction(FunctionTree functionTree) { JavaScriptTree body = (JavaScriptTree) functionTree.body(); int firstLine = body.firstToken().line(); int lastLine = body.lastToken().endLine(); int nbLines = lastLine - firstLine + 1; if (nbLines > max) { String message = String.format(MESSAGE, nbLines, max); IssueLocation primaryLocation = new IssueLocation(functionTree.firstToken(), functionTree.parameterClause(), message); addIssue(new PreciseIssue(this, primaryLocation)); } } }
private void issueIfLineMismatch(SyntaxToken curlyBrace, SyntaxToken target) { CodeLine curlyBraceLine = new CodeLine(curlyBrace.line()); if (curlyBraceLine.isJustBelow(target.line())) { addIssue(new PreciseIssue(this, new IssueLocation(curlyBrace, "Move this open curly brace to the end of the previous line."))); } else if (curlyBraceLine.isFarBelow(target.line())) { addIssue(new PreciseIssue(this, new IssueLocation(curlyBrace, "Move this open curly brace to the end of line " + target.line() + "."))); } }
@Override public void visitIfStatement(IfStatementTree tree) { if (tree.elseClause() == null) { IfStatementTree innerIfStatement = getCollapsibleIfStatement(tree.statement()); if (innerIfStatement != null) { IssueLocation primaryLocation = issueLocation(tree, MESSAGE); IssueLocation secondaryLocation = issueLocation(innerIfStatement, SECONDARY_MESSAGE); addIssue(new PreciseIssue(this, primaryLocation).secondary(secondaryLocation)); } } super.visitIfStatement(tree); }
@Override public void visitNewExpression(NewExpressionTree tree) { if (isFunctionConstructorWithPossibleInjection(tree.expression(), tree.argumentClause())) { addIssue(new PreciseIssue(this, new IssueLocation(tree.newKeyword(), tree.expression(), MESSAGE))); } super.visitNewExpression(tree); }
@Override public void visitNode(Tree tree) { AssignmentExpressionTree assignment = (AssignmentExpressionTree) tree; ExpressionTree expression = assignment.expression(); if (expression.is(Kind.UNARY_PLUS, Kind.UNARY_MINUS, Kind.LOGICAL_COMPLEMENT)) { UnaryExpressionTree unaryExpression = (UnaryExpressionTree) expression; SyntaxToken assignmentOperator = assignment.operatorToken(); SyntaxToken expressionOperator = unaryExpression.operatorToken(); if (areAdjacent(assignmentOperator, expressionOperator) && !areAdjacent(expressionOperator, unaryExpression.expression())) { String message = String.format(MESSAGE, unaryExpression.operatorToken()); addIssue(new PreciseIssue(this, new IssueLocation(assignmentOperator, expressionOperator, message))); } } super.visitNode(tree); }
@Override public void visitElseClause(ElseClauseTree tree) { if (tree.statement().is(Kind.IF_STATEMENT)) { IfStatementTreeImpl ifStmt = (IfStatementTreeImpl) tree.statement(); if (!ifStmt.hasElse()) { addIssue(new PreciseIssue(this, new IssueLocation(tree.elseKeyword(), ifStmt.ifKeyword(), MESSAGE))); } } super.visitElseClause(tree); }