PsiMethodCallExpression (@NotNull PsiVariable targetBuilder, @NotNull PsiIfStatement ifStatement) { if (ifStatement.getElseBranch() != null) return null; PsiStatement block = ifStatement.getThenBranch(); PsiStatement[] thenBranch = ControlFlowUtils.unwrapBlock(block); if (thenBranch.length != 1) return null; PsiExpressionStatement expressionStatement = tryCast(thenBranch[0], PsiExpressionStatement.class); if(expressionStatement == null) return null; PsiMethodCallExpression call = tryCast(expressionStatement.getExpression(), PsiMethodCallExpression.class); if (!SET_LENGTH.test(call)) return null; PsiLocalVariable localVariable = resolveLocalVariable(call.getMethodExpression().getQualifierExpression()); if (!targetBuilder.equals(localVariable)) return null; return call; }