PyFunction ( @NotNull final PyStatementList destStatementList, @NotNull final PyFunction method) { boolean methodIsInit = PyNames.INIT.equals(method.getName()); if (!methodIsInit) { //Not init method could be inserted in the bottom return (PyFunction)destStatementList.add(method); } //We should find appropriate place for init for (final PsiElement element : destStatementList.getChildren()) { final boolean elementComment = element instanceof PyExpressionStatement; final boolean elementClassField = element instanceof PyAssignmentStatement; if (!(elementComment || elementClassField)) { return (PyFunction)destStatementList.addBefore(method, element); } } return (PyFunction)destStatementList.add(method); }