ASTNode (int caret, ASTNode astNode) { if (BasicJavaAstTreeUtil.is(astNode, BASIC_TRY_STATEMENT)) { ASTNode tryBlock = BasicJavaAstTreeUtil.getCodeBlock(astNode); if (tryBlock != null && caret < tryBlock.getTextRange().getEndOffset()) return tryBlock; for (ASTNode catchBlock : BasicJavaAstTreeUtil.getCatchBlocks(astNode)) { if (catchBlock != null && caret < catchBlock.getTextRange().getEndOffset()) return catchBlock; } return BasicJavaAstTreeUtil.getFinallyBlock(astNode); } if (BasicJavaAstTreeUtil.is(astNode, BASIC_SYNCHRONIZED_STATEMENT)) { return BasicJavaAstTreeUtil.getCodeBlock(astNode); } if (BasicJavaAstTreeUtil.is(astNode, BASIC_METHOD)) { ASTNode methodBody = BasicJavaAstTreeUtil.getCodeBlock(astNode); if (methodBody != null) return methodBody; } if (BasicJavaAstTreeUtil.is(astNode, BASIC_SWITCH_STATEMENT)) { return BasicJavaAstTreeUtil.getCodeBlock(astNode); } ASTNode body = null; if (BasicJavaAstTreeUtil.is(astNode, BASIC_IF_STATEMENT)) { body = BasicJavaAstTreeUtil.getThenBranch(astNode); if (body != null && caret > body.getTextRange().getEndOffset()) { body = BasicJavaAstTreeUtil.getElseBranch(astNode); } } else if (BasicJavaAstTreeUtil.is(astNode, BASIC_WHILE_STATEMENT)) { body = BasicJavaAstTreeUtil.getBlock(astNode); } else if (BasicJavaAstTreeUtil.is(astNode, BASIC_FOR_STATEMENT)) { body = BasicJavaAstTreeUtil.getForBody(astNode); } else if (BasicJavaAstTreeUtil.is(astNode, BASIC_FOREACH_STATEMENT)) { body = BasicJavaAstTreeUtil.getBlock(astNode); } else if (BasicJavaAstTreeUtil.is(astNode, BASIC_DO_WHILE_STATEMENT)) { body = BasicJavaAstTreeUtil.getDoWhileBody(astNode); } return BasicJavaAstTreeUtil.is(body, BASIC_BLOCK_STATEMENT) ? BasicJavaAstTreeUtil.getCodeBlock(body) : null; }