use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class NestedIfStatementsCheck method visitTryStatement.
@Override
public void visitTryStatement(TryStatementTree tree) {
SyntaxToken tryKeyword = tree.tryKeyword();
checkNesting(tryKeyword);
nestingLevel.push(tryKeyword);
scan(tree.block());
nestingLevel.pop();
scan(tree.resourceList());
scan(tree.catches());
scan(tree.finallyBlock());
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class EnumConstantTreeImpl method children.
@Override
public Iterable<Tree> children() {
ImmutableList.Builder<Tree> iteratorBuilder = ImmutableList.builder();
// the identifierTree simpleName is also present in initializer
iteratorBuilder.add(modifiers(), initializer());
SyntaxToken endToken = endToken();
if (endToken != null) {
iteratorBuilder.add(endToken);
}
return iteratorBuilder.build();
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class IndentationCheck method checkIndentation.
private void checkIndentation(Tree tree, int expectedLevel) {
SyntaxToken firstSyntaxToken = tree.firstToken();
String line = fileLines.get(firstSyntaxToken.line() - 1);
int level = firstSyntaxToken.column();
for (int i = 0; i < firstSyntaxToken.column(); i++) {
if (line.charAt(i) == '\t') {
level += indentationLevel - 1;
}
}
if (level != expectedLevel && !isExcluded(tree, firstSyntaxToken.line())) {
context.addIssue(((JavaTree) tree).getLine(), this, "Make this line start at column " + (expectedLevel + 1) + ".");
isBlockAlreadyReported = true;
}
excludeIssueAtLine = tree.lastToken().line();
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ConditionalOnNewLineCheck method visitNode.
@Override
public void visitNode(Tree tree) {
IfStatementTree ifStatementTree = (IfStatementTree) tree;
SyntaxToken lastToken = ifStatementTree.thenStatement().lastToken();
if (ifStatementTree.elseKeyword() == null) {
if (previousToken != null && isOnSameLineAsPreviousIf(ifStatementTree)) {
reportIssue(ifStatementTree.ifKeyword(), "Move this \"if\" to a new line or add the missing \"else\".", Collections.singletonList(new JavaFileScannerContext.Location("", previousToken)), null);
}
previousToken = lastToken;
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class DoubleCheckedLockingCheck method ifSynchronizedIfPattern.
private void ifSynchronizedIfPattern(IfFieldEqNull parentIf, IfStatementTree nestedIf) {
if (thenStmtInitializeField(nestedIf.thenStatement(), parentIf.field) && !parentIf.field.isVolatile() && !methodIsSynchronized) {
SyntaxToken synchronizedKeyword = synchronizedStmtStack.peek().synchronizedTree.synchronizedKeyword();
reportIssue(synchronizedKeyword, "Remove this dangerous instance of double-checked locking.", createFlow(parentIf.ifTree, nestedIf), null);
}
}
Aggregations