use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class AnyRuleIssueFilter method filteredLines.
private static Set<Integer> filteredLines(Tree tree) {
SyntaxToken firstSyntaxToken = tree.firstToken();
SyntaxToken lastSyntaxToken = tree.lastToken();
if (firstSyntaxToken != null && lastSyntaxToken != null) {
int startLine = firstSyntaxToken.line();
int endLine = lastSyntaxToken.line();
// includes trivia on top of first syntax token.
List<SyntaxTrivia> trivias = firstSyntaxToken.trivias();
if (!trivias.isEmpty()) {
startLine = trivias.get(0).startLine();
}
return ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers());
}
return new HashSet<>();
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ArrayDesignatorOnVariableCheck method visitNode.
@Override
public void visitNode(Tree tree) {
VariableTree variableTree = (VariableTree) tree;
TypeTree type = variableTree.type();
SyntaxToken identifierToken = variableTree.simpleName().identifierToken();
while (type.is(Tree.Kind.ARRAY_TYPE)) {
ArrayTypeTree arrayTypeTree = (ArrayTypeTree) type;
SyntaxToken arrayDesignatorToken = arrayTypeTree.ellipsisToken();
if (arrayDesignatorToken == null) {
arrayDesignatorToken = arrayTypeTree.openBracketToken();
}
if (isInvalidPosition(arrayDesignatorToken, identifierToken)) {
reportIssue(arrayDesignatorToken, "Move the array designator from the variable to the type.");
break;
}
type = arrayTypeTree.type();
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class LeftCurlyBraceBaseTreeVisitor method visitClass.
@Override
public void visitClass(ClassTree tree) {
SyntaxToken lastToken = getLastTokenFromSignature(tree);
if (lastToken != null) {
checkTokens(lastToken, tree.openBraceToken());
}
super.visitClass(tree);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class LeftCurlyBraceBaseTreeVisitor method visitTryStatement.
@Override
public void visitTryStatement(TryStatementTree tree) {
SyntaxToken closeParenToken = tree.closeParenToken();
if (closeParenToken != null) {
checkBlock(closeParenToken, tree.block());
} else {
checkBlock(tree.tryKeyword(), tree.block());
}
SyntaxToken finallyKeyword = tree.finallyKeyword();
if (finallyKeyword != null) {
checkBlock(finallyKeyword, tree.finallyBlock());
}
super.visitTryStatement(tree);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class LeftCurlyBraceBaseTreeVisitor method visitEnumConstant.
@Override
public void visitEnumConstant(EnumConstantTree tree) {
NewClassTree initializer = tree.initializer();
ClassTree classBody = initializer.classBody();
if (classBody != null) {
SyntaxToken openBraceToken = classBody.openBraceToken();
if (initializer.arguments().closeParenToken() != null) {
checkTokens(initializer.arguments().closeParenToken(), openBraceToken);
} else {
checkTokens(tree.simpleName().identifierToken(), openBraceToken);
}
}
super.visitEnumConstant(tree);
}
Aggregations