package org.mustbe.consulo.csharp.lang.psi.impl.source.resolve.type;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mustbe.consulo.csharp.lang.psi.impl.CSharpTypeUtil;
import org.mustbe.consulo.csharp.lang.psi.impl.msil.CSharpTransform;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclaration;
import org.mustbe.consulo.dotnet.resolve.DotNetPsiSearcher;
import org.mustbe.consulo.dotnet.resolve.DotNetTypeRef;
import org.mustbe.consulo.dotnet.resolve.DotNetTypeResolveResult;
import org.mustbe.consulo.dotnet.resolve.SimpleTypeResolveResult;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;

/**
 * @author VISTALL
 * @since 26.10.14
 */
public class CSharpTypeRefByQName extends DotNetTypeRef.Adapter
{
	@NotNull
	private final String myQualifiedName;
	private final Boolean myNullable;

	public CSharpTypeRefByQName(@NotNull String qualifiedName)
	{
		this(qualifiedName, null);
	}

	public CSharpTypeRefByQName(@NotNull String qualifiedName, @Nullable Boolean nullable)
	{
		myQualifiedName = qualifiedName;
		myNullable = nullable;
	}

	@NotNull
	@Override
	public String getQualifiedText()
	{
		return myQualifiedName;
	}

	@NotNull
	@Override
	public String getPresentableText()
	{
		String shortName = StringUtil.getShortName(myQualifiedName);
		if(myNullable == Boolean.TRUE)
		{
			shortName += "?";
		}
		return shortName;
	}

	@NotNull
	@Override
	public DotNetTypeResolveResult resolve(@NotNull PsiElement scope)
	{
		DotNetTypeDeclaration type = DotNetPsiSearcher.getInstance(scope.getProject()).findType(myQualifiedName, scope.getResolveScope(),
				DotNetPsiSearcher.TypeResoleKind.UNKNOWN, CSharpTransform.INSTANCE);

		if(type == null)
		{
			return DotNetTypeResolveResult.EMPTY;
		}

		return new SimpleTypeResolveResult(type, myNullable == Boolean.TRUE || CSharpTypeUtil.isElementIsNullable(type));
	}
}

@@ -280,16 +280,80 @@
 nsform;%0A
+import org.mustbe.consulo.dotnet.lang.psi.impl.stub.MsilHelper;%0A
 import o
@@ -1254,16 +1254,44 @@
 %09return 
+MsilHelper.cutGenericMarker(
 myQualif
@@ -1293,24 +1293,25 @@
 ualifiedName
+)
 ;%0A%09%7D%0A%0A%09@NotN
@@ -1409,18 +1409,19 @@
 ortName(
-my
+get
 Qualifie
@@ -1417,28 +1417,30 @@
 getQualified
-Name
+Text()
 );%0A%09%09if(myNu

cut `1