@Override
 public void leaveNode(Tree tree) {
   if (tree.is(Tree.Kind.CATCH)) {
     CatchTree catchTree = (CatchTree) tree;
     caughtVariables.remove(catchTree.parameter().simpleName().name());
   }
 }
 @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)) {
     addIssue(
         ((InstanceOfTree) tree).instanceofKeyword(),
         "Replace the usage of the \"instanceof\" operator by a catch block.");
   }
 }
コード例 #3
0
 @Override
 public void visitCatch(CatchTree tree) {
   if (!isExcludedType(tree.parameter().type())) {
     Symbol exception = tree.parameter().symbol();
     validUsagesStack.addFirst(exception.usages());
     super.visitCatch(tree);
     Collection<IdentifierTree> usages = validUsagesStack.pop();
     if (usages.isEmpty()) {
       context.reportIssue(this, tree.parameter(), "Either log or rethrow this exception.");
     }
   }
 }