private static PsiType getIteratedType(PsiElement parent, PsiType collection) {
    if (parent instanceof GrReferenceExpression) {
      final GrExpression qualifier = ((GrReferenceExpression)parent).getQualifier();
      if (qualifier != null) {
        return ClosureParameterEnhancer.findTypeForIteration(qualifier, parent);
      }
    }

    final PsiType iterable = PsiUtil.extractIterableTypeParameter(collection, true);
    if (iterable != null && parent instanceof GrExpression) {
      return PsiImplUtil.normalizeWildcardTypeByPosition(iterable, (GrExpression)parent);
    }
    else {
      return iterable;
    }
  }
private static PsiType getIteratedType(PsiElement parent, PsiType collection)