use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ReassignmentFinder method getClosestReassignment.
@CheckForNull
private static Tree getClosestReassignment(SyntaxToken startToken, List<AssignmentExpressionTree> reassignments) {
Tree result = null;
List<Tree> assignmentsBeforeStartToken = reassignments.stream().sorted(ReassignmentFinder::isBefore).filter(a -> isBefore(startToken, a) > 0).collect(Collectors.toList());
if (!assignmentsBeforeStartToken.isEmpty()) {
return assignmentsBeforeStartToken.get(assignmentsBeforeStartToken.size() - 1);
}
return result;
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class UnconditionalJumpStatementCheck method visitNode.
@Override
public void visitNode(Tree tree) {
Tree parent = tree.parent();
while (parent.is(Tree.Kind.BLOCK)) {
parent = parent.parent();
}
if (!parent.is(LOOP_KINDS)) {
return;
}
if (tree.is(Tree.Kind.CONTINUE_STATEMENT) || (!isWhileNextElementLoop(parent) && !isEmptyConditionLoop(parent) && executeUnconditionnally(parent))) {
SyntaxToken jumpKeyword = jumpKeyword(tree);
reportIssue(jumpKeyword, String.format("Remove this \"%s\" statement or make it conditional.", jumpKeyword.text()));
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class WrongAssignmentOperatorCheck method visitNode.
@Override
public void visitNode(Tree tree) {
AssignmentExpressionTree aeTree = (AssignmentExpressionTree) tree;
SyntaxToken operatorToken = aeTree.operatorToken();
SyntaxToken expressionFirstToken = aeTree.expression().firstToken();
SyntaxToken variableLastToken = aeTree.variable().lastToken();
if (isSuspiciousToken(expressionFirstToken) && noSpacingBetween(operatorToken, expressionFirstToken) && !noSpacingBetween(variableLastToken, operatorToken)) {
reportIssue(operatorToken, expressionFirstToken, getMessage(expressionFirstToken, aeTree));
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class BaseTreeVisitorIssueFilter method computeFilteredLinesForRule.
private void computeFilteredLinesForRule(@Nullable Tree tree, Class<? extends JavaCheck> filteredRule, boolean excludeLine) {
if (tree == null) {
return;
}
SyntaxToken firstSyntaxToken = tree.firstToken();
SyntaxToken lastSyntaxToken = tree.lastToken();
if (firstSyntaxToken != null && lastSyntaxToken != null) {
Set<Integer> filteredlines = ContiguousSet.create(Range.closed(firstSyntaxToken.line(), lastSyntaxToken.line()), DiscreteDomain.integers());
computeFilteredLinesForRule(filteredlines, rulesKeysByRulesClass.get(filteredRule), excludeLine);
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ArrayDesignatorAfterTypeCheck method visitNode.
@Override
public void visitNode(Tree tree) {
MethodTree methodTree = (MethodTree) tree;
TypeTree returnType = methodTree.returnType();
SyntaxToken identifierToken = methodTree.simpleName().identifierToken();
while (returnType.is(Tree.Kind.ARRAY_TYPE)) {
ArrayTypeTree arrayTypeTree = (ArrayTypeTree) returnType;
SyntaxToken openBracketToken = arrayTypeTree.openBracketToken();
if (isInvalidPosition(openBracketToken, identifierToken)) {
reportIssue(openBracketToken, "Move the array designators \"[]\" to the end of the return type.");
break;
}
returnType = arrayTypeTree.type();
}
}
Aggregations