private static @Nullable @NonNls String getCollectionsAddAllText(PsiForStatement forStatement) {
      final PsiExpression expression = forStatement.getCondition();
      final PsiBinaryExpression condition = tryCast(PsiUtil.skipParenthesizedExprDown(expression), PsiBinaryExpression.class);
      if (condition == null) return null;
      final PsiDeclarationStatement declaration = tryCast(forStatement.getInitialization(), PsiDeclarationStatement.class);
      if (declaration == null) return null;
      final PsiElement[] declaredElements = declaration.getDeclaredElements();
      if (declaredElements.length != 1) return null;
      final PsiLocalVariable variable = tryCast(declaredElements[0], PsiLocalVariable.class);
      if (variable == null) return null;
      final String collectionText = buildCollectionText(forStatement);
      final PsiArrayAccessExpression arrayAccessExpression = getArrayAccessExpression(forStatement);
      if (arrayAccessExpression == null) return null;

      final PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression();
      final String arrayText = arrayExpression.getText();
      final PsiExpression indexExpression = arrayAccessExpression.getIndexExpression();
      final String indexOffset = getIndexOffset(indexExpression, variable);
      if (indexOffset == null) return null;
      final String fromOffsetText = addIndexOffset(variable.getInitializer(), indexOffset, false);
      if (fromOffsetText == null) return null;
      final IElementType tokenType = condition.getOperationTokenType();
      final PsiExpression limit =
        tokenType == JavaTokenType.LT || tokenType == JavaTokenType.LE ? condition.getROperand() : condition.getLOperand();

      final String toOffsetText = addIndexOffset(limit, indexOffset, tokenType == JavaTokenType.LE || tokenType == JavaTokenType.GE);
      if (toOffsetText == null) return null;

      if (fromOffsetText.equals("0") && toOffsetText.equals(arrayText + ".length") && PsiUtil.isLanguageLevel5OrHigher(forStatement)) {
        return "java.util.Collections.addAll(" + collectionText + ',' + arrayText + ");";
      }
      else {
        @NonNls final StringBuilder buffer = new StringBuilder();
        buffer.append(collectionText);
        buffer.append('.');
        buffer.append("addAll(java.util.Arrays.asList(");
        buffer.append(arrayText);
        buffer.append(')');
        if (!fromOffsetText.equals("0") || !toOffsetText.equals(arrayText + ".length")) {
          buffer.append(".subList(");
          buffer.append(fromOffsetText);
          buffer.append(", ");
          buffer.append(toOffsetText);
          buffer.append(')');
        }
        buffer.append(");");
        return buffer.toString();
      }
    }
private static @Nullable @NonNls String getCollectionsAddAllText(PsiForStatement forStatement)