PsiType (@Nullable PsiType type, PsiElement context) { if (!(type instanceof PsiClassType)) return null; final GroovyResolveResult[] candidates = ResolveUtil.getMethodCandidates(type, "iterator", context, PsiType.EMPTY_ARRAY); final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(candidates); final PsiElement element = candidate.getElement(); if (!(element instanceof PsiMethod)) return null; final PsiType returnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod)element); final PsiType iteratorType = candidate.getSubstitutor().substitute(returnType); return PsiUtil.substituteTypeParameter(iteratorType, JAVA_UTIL_ITERATOR, 0, false); }