package org.mustbe.consulo.csharp.ide.highlight.check.impl;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mustbe.consulo.csharp.ide.highlight.check.CompilerCheck;
import org.mustbe.consulo.csharp.lang.psi.impl.source.CSharpArrayTypeImpl;
import org.mustbe.consulo.csharp.module.extension.CSharpLanguageVersion;
import org.mustbe.consulo.dotnet.psi.DotNetGenericParameterListOwner;
import org.mustbe.consulo.dotnet.psi.DotNetType;
import org.mustbe.consulo.dotnet.psi.DotNetTypeWithTypeArguments;
import org.mustbe.consulo.dotnet.resolve.DotNetTypeResolveResult;
import com.intellij.psi.PsiElement;

/**
 * @author VISTALL
 * @since 23.10.14
 */
public class CS0305 extends CompilerCheck<DotNetType>
{
	@Nullable
	@Override
	public CompilerCheckResult checkImpl(@NotNull CSharpLanguageVersion languageVersion, @NotNull DotNetType type)
	{
		if(type.getParent() instanceof DotNetTypeWithTypeArguments)
		{
			return null;
		}

		int foundCount = 0;
		DotNetType innerType = type;
		if(type instanceof DotNetTypeWithTypeArguments)
		{
			innerType = ((DotNetTypeWithTypeArguments) type).getInnerType();
			foundCount = ((DotNetTypeWithTypeArguments) type).getArguments().length;
		}
		else if(type instanceof CSharpArrayTypeImpl)
		{
			innerType = ((CSharpArrayTypeImpl) type).getInnerType();
			foundCount = 1;
		}

		DotNetTypeResolveResult typeResolveResult = type.toTypeRef().resolve(type);

		int expectedCount = 0;
		PsiElement resolvedElement = typeResolveResult.getElement();
		if(resolvedElement == null)
		{
			return null;
		}
		if(resolvedElement instanceof DotNetGenericParameterListOwner)
		{
			expectedCount = ((DotNetGenericParameterListOwner) resolvedElement).getGenericParametersCount();
		}

		if(expectedCount != foundCount)
		{
			return result(innerType, formatElement(resolvedElement), String.valueOf(expectedCount));
		}
		return null;
	}
}

@@ -207,16 +207,88 @@
 rCheck;%0A
+import org.mustbe.consulo.csharp.lang.psi.CSharpConstructorDeclaration;%0A
 import o
@@ -1652,16 +1652,138 @@
 ll;%0A%09%09%7D%0A
+%0A%09%09if(resolvedElement instanceof CSharpConstructorDeclaration)%0A%09%09%7B%0A%09%09%09resolvedElement = resolvedElement.getParent();%0A%09%09%7D%0A%0A
 %09%09if(res

update CS0305