void (@NotNull PsiElement element, @NotNull ActionContext context, @NotNull ModPsiUpdater updater) { GrMethod method = (GrMethod)element.getParent(); GrOpenBlock block = method.getBlock(); if (block == null) return; GrStatement statement = block.getStatements()[0]; GrExpression value; if (statement instanceof GrReturnStatement) { value = ((GrReturnStatement)statement).getReturnValue(); } else { value = (GrExpression)statement; } String fieldName = GroovyPropertyUtils.getPropertyNameByGetter(method); if (fieldName == null) return; PsiClass aClass = method.getContainingClass(); if (aClass == null) return; List<String> modifiers = new ArrayList<>(); for (String modifier : MODIFIERS_TO_CHECK) { if (method.hasModifierProperty(modifier)) modifiers.add(modifier); } modifiers.add(PsiModifier.FINAL); GrTypeElement returnTypeElement = method.getReturnTypeElementGroovy(); PsiType returnType = returnTypeElement == null ? null : returnTypeElement.getType(); GrVariableDeclaration declaration = GroovyPsiElementFactory.getInstance(context.project()).createFieldDeclaration( ArrayUtilRt.toStringArray(modifiers), fieldName, value, returnType ); PsiElement replaced = method.replace(declaration); JavaCodeStyleManager.getInstance(context.project()).shortenClassReferences(replaced); }