private static PsiVariable createField(@NotNull Project project,
                                         @NotNull PsiClass targetClass,
                                         @NotNull GrMethod method,
                                         @NotNull PsiParameter myParameter,
                                         PsiType type,
                                         @NotNull String fieldName,
                                         boolean methodStatic,
                                         boolean isFinal) {
    GrOpenBlock block = method.getBlock();
    if (block == null) return null;

    GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
    GrAssignmentExpression assignment = createAssignment(targetClass, myParameter, fieldName, methodStatic, factory);
    GrStatement anchor = getAnchor(block);

    GrStatement statement = block.addStatementBefore(assignment, anchor);
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(statement);

    if (targetClass.findFieldByName(fieldName, false) == null) {
      String[] modifiers = getModifiers(methodStatic, isFinal);
      GrVariableDeclaration fieldDeclaration = factory.createFieldDeclaration(modifiers, fieldName, null, type);
      GrVariableDeclaration inserted = (GrVariableDeclaration)targetClass.add(fieldDeclaration);
      JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted);
      return inserted.getVariables()[0];
    }
    return null;
  }
private static PsiVariable createField(@NotNull Project project,
                                         @NotNull PsiClass targetClass,
                                         @NotNull GrMethod method,
                                         @NotNull PsiParameter myParameter,
                                         PsiType type,
                                         @NotNull String fieldName,
                                         boolean methodStatic,
                                         boolean isFinal)