package com.jetbrains.python.codeInsight.override;

import com.intellij.codeInsight.generation.ClassMember;
import com.intellij.codeInsight.generation.MemberChooserObject;
import com.intellij.codeInsight.generation.PsiElementMemberChooserObject;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.SimpleColoredComponent;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyElement;
import com.jetbrains.python.psi.PyFunction;

import javax.swing.*;

/**
 * @author Alexey.Ivanov
 */
public class PyMethodMember extends PsiElementMemberChooserObject implements ClassMember {
  private final String myFullName;
  private static String buildNameFor(final PyElement element) {
    if (element instanceof PyFunction) {
      return element.getName() + ((PyFunction)element).getParameterList().getText();
    }
    if (element instanceof PyClass && PyNames.FAKE_OLD_BASE.equals(element.getName())) {
      return "<old-style class>";
    }
    return element.getName();
  }

  public PyMethodMember(final PyElement element) {
    super(element, trimUnderscores(buildNameFor(element)), element.getIcon(0));
    myFullName = buildNameFor(element);
  }

  public static String trimUnderscores(String s) {
    return StringUtil.trimStart(StringUtil.trimStart(s, "_"), "_");
  }

  public MemberChooserObject getParentNodeDelegate() {
    final PyElement element = (PyElement)getPsiElement();
    final PyClass parent = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
    assert (parent != null);
    return new PyMethodMember(parent);
  }

  @Override
  public void renderTreeNode(SimpleColoredComponent component, JTree tree) {
    component.append(myFullName, getTextAttributes(tree));
    component.setIcon(getPsiElement().getIcon(0));
  }
}

@@ -374,24 +374,59 @@
 dComponent;%0A
+import com.intellij.util.Function;%0A
 import com.j
@@ -486,58 +486,9 @@
 psi.
-PyClass;%0Aimport com.jetbrains.python.psi.PyElement
+*
 ;%0Aim
@@ -517,26 +517,37 @@
 hon.psi.
-PyFunction
+types.TypeEvalContext
 ;%0A%0Aimpor
@@ -562,16 +562,39 @@
 swing.*;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -861,85 +861,458 @@
     
-return element.getName() + ((PyFunction)element).getParameterList().getText()
+final TypeEvalContext context = TypeEvalContext.userInitiated(element.getContainingFile());%0A      final List%3CPyParameter%3E parameters = PyUtil.getParameters((PyFunction)element, context);%0A      return element.getName() + %22(%22 + StringUtil.join(parameters, new Function%3CPyParameter, String%3E() %7B%0A        @Override%0A        public String fun(PyParameter parameter) %7B%0A          return PyUtil.getReadableRepr(parameter, false);%0A        %7D%0A      %7D, %22, %22) + %22)%22
 ;%0A  

Use parameters provided by function type in override methods list