List<ClosureParameterInfo> (InsertionContext context, PsiMethod method, PsiSubstitutor substitutor, PsiElement place) { final String name = method.getName(); if (!"eachWithIndex".equals(name)) return null; if (method instanceof GrGdkMethod) method = ((GrGdkMethod)method).getStaticMethod(); final PsiClass containingClass = method.getContainingClass(); if (containingClass == null) return null; final String qname = containingClass.getQualifiedName(); if (!GroovyCommonClassNames.DEFAULT_GROOVY_METHODS.equals(qname)) return null; final PsiParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length != 2) return null; final PsiType type = parameters[0].getType(); final PsiType collection = substitutor.substitute(type); final PsiType iterable = getIteratedType(place, collection); if (iterable != null) { return Arrays.asList( new ClosureParameterInfo(iterable.getCanonicalText(), "entry"), new ClosureParameterInfo("int", "i") ); } if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_MAP)) { final PsiType[] typeParams = ((PsiClassType)collection).getParameters(); final Project project = context.getProject(); final PsiClass entry = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_UTIL_MAP_ENTRY, place.getResolveScope()); if (entry == null) return null; final PsiClassType entryType = JavaPsiFacade.getElementFactory(project).createType(entry, typeParams); return Arrays.asList(new ClosureParameterInfo(entryType.getCanonicalText(), "entry"), new ClosureParameterInfo("int", "i")); } return Arrays.asList(new ClosureParameterInfo(collection.getCanonicalText(), "entry"), new ClosureParameterInfo("int", "i")); }