GrMethod (PsiField field) { Project project = field.getProject(); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); String name = field.getName(); boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); VariableKind kind = codeStyleManager.getVariableKind(field); String propertyName = codeStyleManager.variableNameToPropertyName(name, kind); String setName = getSetterName(field.getName()); final PsiClass containingClass = field.getContainingClass(); try { GrMethod setMethod = factory.createMethod(setName, PsiTypes.voidType()); String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER); final PsiType type = field instanceof GrField ? ((GrField)field).getDeclaredType() : field.getType(); GrParameter param = factory.createParameter(parameterName, type); annotateWithNullableStuff(field, param); setMethod.getParameterList().add(param); PsiUtil.setModifierProperty(setMethod, PsiModifier.STATIC, isStatic); @NonNls StringBuilder builder = new StringBuilder(); if (name.equals(parameterName)) { if (!isStatic) { builder.append("this."); } else { String className = containingClass.getName(); if (className != null) { builder.append(className); builder.append("."); } } } builder.append(name); builder.append("="); builder.append(parameterName); builder.append("\n"); GrCodeBlock body = factory.createMethodBodyFromText(builder.toString()); setMethod.getBlock().replace(body); return setMethod; } catch (IncorrectOperationException e) { LOG.error(e); return null; } }