コード例 #1
0
 private static TryStatementTree getEnclosingTryStatement(Tree syntaxNode) {
   Tree parent = syntaxNode.parent();
   while (parent != null) {
     if (parent.is(Tree.Kind.TRY_STATEMENT)) {
       return (TryStatementTree) parent;
     }
     parent = parent.parent();
   }
   return null;
 }
コード例 #2
0
 private static MethodTree getParentMethod(Tree tree) {
   Tree result = tree;
   while (!result.is(Tree.Kind.METHOD)) {
     result = result.parent();
   }
   return (MethodTree) result;
 }
コード例 #3
0
 private static boolean isWithinTryHeader(Tree syntaxNode) {
   final Tree parent = syntaxNode.parent();
   if (parent.is(Tree.Kind.VARIABLE)) {
     return isTryStatementResource((VariableTree) parent);
   }
   return false;
 }
コード例 #4
0
 @Override
 protected void onMethodInvocationFound(MethodInvocationTree mit) {
   Tree parent = mit.parent();
   while (parent != null && !parent.is(Tree.Kind.METHOD)) {
     parent = parent.parent();
   }
   if (parent != null && THREAD_RUN_METHOD_MATCHER.matches((MethodTree) parent)) {
     return;
   }
   reportIssue(
       MethodsHelper.methodName(mit),
       "Call the method Thread.start() to execute the content of the run() method in a dedicated thread.");
 }
コード例 #5
0
 @Override
 public void visitNode(Tree tree) {
   NewClassTree newClassTree = (NewClassTree) tree;
   TypeTree newTypeTree = newClassTree.identifier();
   if (newClassTree.classBody() == null && isParameterizedType(newTypeTree)) {
     TypeTree type = getTypeFromExpression(tree.parent());
     if (type != null && isParameterizedType(type)) {
       reportIssue(
           ((ParameterizedTypeTree) newTypeTree).typeArguments(),
           "Replace the type specification in this constructor call with the diamond operator (\"<>\")."
               + JavaVersionHelper.java7CompatibilityMessage(context.getJavaVersion()));
     }
   }
 }