boolean (PsiStatement statement, PsiVariable variable) { if (statement instanceof PsiExpressionStatement expressionStatement) { final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiMethodCallExpression methodCallExpression)) { return false; } return isResourceClose(methodCallExpression, variable); } if (statement instanceof PsiTryStatement tryStatement) { final PsiCodeBlock tryBlock = tryStatement.getTryBlock(); if (isResourceClose(ControlFlowUtils.getFirstStatementInBlock(tryBlock), variable)) { return true; } } else if (statement instanceof PsiIfStatement ifStatement) { final PsiExpression condition = ifStatement.getCondition(); if (!(condition instanceof PsiBinaryExpression binaryExpression)) { return false; } final IElementType tokenType = binaryExpression.getOperationTokenType(); if (JavaTokenType.NE != tokenType) { return false; } final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if (rhs == null) { return false; } if (PsiTypes.nullType().equals(lhs.getType())) { if (!(rhs instanceof PsiReferenceExpression referenceExpression)) { return false; } final PsiElement target = referenceExpression.resolve(); if (!variable.equals(target)) { return false; } } else if (PsiTypes.nullType().equals(rhs.getType())) { if (!(lhs instanceof PsiReferenceExpression referenceExpression)) { return false; } final PsiElement target = referenceExpression.resolve(); if (!variable.equals(target)) { return false; } } final PsiStatement thenBranch = ifStatement.getThenBranch(); return isResourceClose(thenBranch, variable); } else if (statement instanceof PsiBlockStatement blockStatement) { final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); return isResourceClose(ControlFlowUtils.getFirstStatementInBlock(codeBlock), variable); } return false; }