package com.wishtack.pysynthetic.psi;

import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.impl.PyNamedParameterImpl;
import com.jetbrains.python.psi.impl.PyNoneLiteralExpressionImpl;
import com.jetbrains.python.psi.impl.stubs.PyNamedParameterStubImpl;
import com.jetbrains.python.psi.stubs.PyNamedParameterStub;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
import com.wishtack.pysynthetic.SyntheticMemberInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * Created by Jean Hominal on 2016-11-06.
 */
public class SyntheticInitParameter extends PyNamedParameterImpl {

    private static final PyExpression NONE_MINIMAL_EXPRESSION =
            new PyNoneLiteralExpressionImpl(new LeafPsiElement(PyElementTypes.NONE_LITERAL_EXPRESSION, "None"));

    @NotNull
    private static PyNamedParameterStub createVirtualStub(@NotNull SyntheticMemberInfo syntheticMemberInfo) {
        return new PyNamedParameterStubImpl(syntheticMemberInfo.getName(), false, false, true, null, null, PyElementTypes.NAMED_PARAMETER);
    }

    @NotNull
    private final SyntheticMemberInfo myMemberInfo;

    public SyntheticInitParameter(@NotNull SyntheticMemberInfo syntheticMemberInfo) {
        super(createVirtualStub(syntheticMemberInfo));
        myMemberInfo = syntheticMemberInfo;
    }

    @Override
    public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
        return myMemberInfo.getMemberType();
    }

    @Nullable
    @Override
    public PyExpression getDefaultValue() {
        PyExpression defaultValue = myMemberInfo.getDefaultValue();
        return defaultValue != null ? defaultValue : NONE_MINIMAL_EXPRESSION;
    }

    @Override
    public PsiElement getParent() {
        return null;
    }
}

@@ -72,65 +72,8 @@
 nt;%0A
-import com.intellij.psi.impl.source.tree.LeafPsiElement;%0A
 impo
@@ -112,16 +112,16 @@
 tTypes;%0A
+
 import c
@@ -221,74 +221,8 @@
 pl;%0A
-import com.jetbrains.python.psi.impl.PyNoneLiteralExpressionImpl;%0A
 impo
@@ -708,186 +708,8 @@
  %7B%0A%0A
-    private static final PyExpression NONE_MINIMAL_EXPRESSION =%0A            new PyNoneLiteralExpressionImpl(new LeafPsiElement(PyElementTypes.NONE_LITERAL_EXPRESSION, %22None%22));%0A%0A
     
@@ -1478,35 +1478,14 @@
     
-PyExpression defaultValue =
+return
  myM
@@ -1517,86 +1517,8 @@
 ();%0A
-        return defaultValue != null ? defaultValue : NONE_MINIMAL_EXPRESSION;%0A
     

Remove '=None' in Parameter Info tooltip when default is not set in the decorator