use of org.sonar.plugins.java.api.tree.BlockTree in project sonar-java by SonarSource.
the class ReturnInFinallyCheck method visitTryStatement.
@Override
public void visitTryStatement(TryStatementTree tree) {
scan(tree.resourceList());
scan(tree.block());
scan(tree.catches());
BlockTree finallyBlock = tree.finallyBlock();
if (finallyBlock != null) {
treeKindStack.push(finallyBlock.kind());
scan(finallyBlock);
treeKindStack.pop();
}
}
use of org.sonar.plugins.java.api.tree.BlockTree in project sonar-java by SonarSource.
the class RightCurlyBraceStartLineCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.BLOCK, Tree.Kind.STATIC_INITIALIZER, Tree.Kind.INITIALIZER)) {
BlockTree blockTree = (BlockTree) tree;
checkBlockBody(blockTree.openBraceToken(), blockTree.closeBraceToken(), blockTree.body());
} else {
ClassTree classTree = (ClassTree) tree;
checkBlockBody(classTree.openBraceToken(), classTree.closeBraceToken(), classTree.members());
}
}
use of org.sonar.plugins.java.api.tree.BlockTree in project sonar-java by SonarSource.
the class SelectorMethodArgumentCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
MethodTree methodTree = (MethodTree) tree;
if (Boolean.TRUE.equals(methodTree.isOverriding())) {
return;
}
List<Symbol> booleanParameterSymbols = getBooleanParametersAsSymbol(methodTree.parameters());
BlockTree blockTree = methodTree.block();
if (isPublic(methodTree) && blockTree != null && !booleanParameterSymbols.isEmpty()) {
for (Symbol variable : booleanParameterSymbols) {
Collection<IdentifierTree> usages = variable.usages();
if (usages.size() == 1) {
blockTree.accept(new ConditionalStatementVisitor(variable.name(), Iterables.get(usages, 0), methodTree));
}
}
}
}
use of org.sonar.plugins.java.api.tree.BlockTree in project sonar-java by SonarSource.
the class RightCurlyBraceToNextBlockAbstractVisitor method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.IF_STATEMENT)) {
IfStatementTree ifStatementTree = (IfStatementTree) tree;
StatementTree thenStatement = ifStatementTree.thenStatement();
if (ifStatementTree.elseKeyword() != null && thenStatement.is(Tree.Kind.BLOCK)) {
checkTokenPosition(ifStatementTree.elseKeyword(), (BlockTree) thenStatement);
}
} else {
TryStatementTree tryStatementTree = (TryStatementTree) tree;
BlockTree block = tryStatementTree.block();
for (CatchTree catchTree : tryStatementTree.catches()) {
checkTokenPosition(catchTree.catchKeyword(), block);
block = catchTree.block();
}
SyntaxToken finallyKeyword = tryStatementTree.finallyKeyword();
if (finallyKeyword != null) {
checkTokenPosition(finallyKeyword, block);
}
}
}
use of org.sonar.plugins.java.api.tree.BlockTree in project sonar-java by SonarSource.
the class RedundantThrowsDeclarationCheck method hasTryWithResourceInBody.
private static boolean hasTryWithResourceInBody(MethodTree methodTree) {
BlockTree block = methodTree.block();
if (block == null) {
return false;
}
TryWithResourcesVisitor visitor = new TryWithResourcesVisitor();
block.accept(visitor);
return visitor.hasTryWithResource;
}
Aggregations