boolean (@NotNull PsiExpression resourceCreationExpression) { if (resourceCreationExpression instanceof PsiCallExpression) { PsiExpressionList argumentList = ((PsiCallExpression)resourceCreationExpression).getArgumentList(); if (argumentList != null && ContainerUtil.or(argumentList.getExpressions(), this::canTakeOwnership)) { // resource was created from other, potentially leaking resource return true; } if (resourceCreationExpression instanceof PsiMethodCallExpression call) { PsiExpression qualifier = call.getMethodExpression().getQualifierExpression(); if (qualifier != null && isResourceCreation(qualifier)) { return true; } } } return false; }