void (String newName) { PsiNamedElement elementToRename = getVariable(); if (elementToRename instanceof ClosureSyntheticParameter && !"it".equals(newName)) { final GrClosableBlock closure = ((ClosureSyntheticParameter)elementToRename).getClosure(); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject); final PsiType type = ((ClosureSyntheticParameter)elementToRename).getTypeGroovy(); final GrParameter newParam = factory.createParameter(newName, TypesUtil.unboxPrimitiveTypeWrapper(type)); final GrParameter added = closure.addParameter(newParam); JavaCodeStyleManager.getInstance(added.getProject()).shortenClassReferences(added); } }