use of org.sonar.plugins.java.api.tree.CatchTree in project sonar-java by SonarSource.
the class CatchIllegalMonitorStateExceptionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
CatchTree catchTree = (CatchTree) tree;
TypeTree parameterTypeTree = catchTree.parameter().type();
if (parameterTypeTree.is(Kind.UNION_TYPE)) {
UnionTypeTree unionTypeTree = (UnionTypeTree) parameterTypeTree;
for (TypeTree exceptionTypeTree : unionTypeTree.typeAlternatives()) {
checkExceptionType(exceptionTypeTree);
}
} else {
checkExceptionType(parameterTypeTree);
}
}
use of org.sonar.plugins.java.api.tree.CatchTree in project sonar-java by SonarSource.
the class CatchNPECheck method visitCatch.
@Override
public void visitCatch(CatchTree tree) {
super.visitCatch(tree);
Tree typeTree = tree.parameter().type();
if (typeTree.is(Kind.UNION_TYPE)) {
((UnionTypeTree) typeTree).typeAlternatives().forEach(this::checkType);
} else {
checkType(typeTree);
}
}
use of org.sonar.plugins.java.api.tree.CatchTree in project sonar-java by SonarSource.
the class InstanceofUsedOnExceptionCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.CATCH)) {
CatchTree catchTree = (CatchTree) tree;
caughtVariables.add(catchTree.parameter().simpleName().name());
} else if (isLeftOperandAnException((InstanceOfTree) tree)) {
reportIssue(((InstanceOfTree) tree).instanceofKeyword(), "Replace the usage of the \"instanceof\" operator by a catch block.");
}
}
use of org.sonar.plugins.java.api.tree.CatchTree in project sonar-java by SonarSource.
the class InstanceofUsedOnExceptionCheck method leaveNode.
@Override
public void leaveNode(Tree tree) {
if (tree.is(Tree.Kind.CATCH)) {
CatchTree catchTree = (CatchTree) tree;
caughtVariables.remove(catchTree.parameter().simpleName().name());
}
}
Aggregations