/*
 * Copyright 2013 must-be.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mustbe.consulo.csharp.ide.findUsage;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mustbe.consulo.csharp.lang.lexer.CSharpLexer;
import org.mustbe.consulo.csharp.lang.psi.CSharpTokenSets;
import org.mustbe.consulo.csharp.lang.psi.CSharpTokens;
import org.mustbe.consulo.csharp.lang.psi.impl.CSharpNamespaceAsElement;
import org.mustbe.consulo.dotnet.psi.DotNetMethodDeclaration;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclaration;
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
import com.intellij.lang.cacheBuilder.WordsScanner;
import com.intellij.lang.findUsages.FindUsagesProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.TokenSet;

/**
 * @author VISTALL
 * @since 21.12.13.
 */
public class CSharpFindUsagesProvider implements FindUsagesProvider
{
	@Nullable
	@Override
	public WordsScanner getWordsScanner()
	{
		return new DefaultWordsScanner(new CSharpLexer(), TokenSet.create(CSharpTokens.IDENTIFIER), CSharpTokenSets.COMMENTS, CSharpTokenSets.LITERALS);
	}

	@Override
	public boolean canFindUsagesFor(@NotNull PsiElement element)
	{
		return true;
	}

	@Nullable
	@Override
	public String getHelpId(@NotNull PsiElement element)
	{
		return null;
	}

	@NotNull
	@Override
	public String getType(@NotNull PsiElement element)
	{
		if(element instanceof DotNetTypeDeclaration)
		{
			return "type";
		}
		else if(element instanceof DotNetMethodDeclaration)
		{
			return "method";
		}
		else if(element instanceof CSharpNamespaceAsElement)
		{
			return "namespace";
		}
		return "getType " + element.getNode().getElementType();
	}

	@NotNull
	@Override
	public String getDescriptiveName(@NotNull PsiElement element)
	{

		return "getDescriptiveName " + element.getNode().getElementType();
	}

	@NotNull
	@Override
	public String getNodeText(@NotNull PsiElement element, boolean b)
	{
		return "getNodeText " + element.getNode().getElementType();
	}
}

@@ -773,24 +773,91 @@
 SharpLexer;%0A
+import org.mustbe.consulo.csharp.lang.psi.CSharpMethodDeclaration;%0A
 import org.m
@@ -1005,87 +1005,250 @@
 psi.
-impl.CSharpNamespaceAsElement;%0Aimport org.mustbe.consulo.dotnet.psi.DotNetMetho
+CSharpTypeDeclaration;%0Aimport org.mustbe.consulo.csharp.lang.psi.impl.CSharpNamespaceAsElement;%0Aimport org.mustbe.consulo.csharp.lang.psi.impl.source.CSharpEventDeclarationImpl;%0Aimport org.mustbe.consulo.csharp.lang.psi.impl.source.CSharpFiel
 dDec
@@ -1247,32 +1247,36 @@
 FieldDeclaration
+Impl
 ;%0Aimport org.mus
@@ -1291,29 +1291,125 @@
 ulo.
-dotnet.psi.DotNetType
+csharp.lang.psi.impl.source.CSharpParameterImpl;%0Aimport org.mustbe.consulo.csharp.lang.psi.impl.source.CSharpProperty
 Decl
@@ -1407,32 +1407,36 @@
 pertyDeclaration
+Impl
 ;%0Aimport com.int
@@ -2289,22 +2289,22 @@
 tanceof 
-DotNet
+CSharp
 TypeDecl
@@ -2371,14 +2371,14 @@
 eof 
-DotNet
+CSharp
 Meth
@@ -2506,16 +2506,356 @@
 e%22;%0A%09%09%7D%0A
+%09%09else if(element instanceof CSharpEventDeclarationImpl)%0A%09%09%7B%0A%09%09%09return %22event%22;%0A%09%09%7D%0A%09%09else if(element instanceof CSharpPropertyDeclarationImpl)%0A%09%09%7B%0A%09%09%09return %22property%22;%0A%09%09%7D%0A%09%09else if(element instanceof CSharpParameterImpl)%0A%09%09%7B%0A%09%09%09return %22parameter%22;%0A%09%09%7D%0A%09%09else if(element instanceof CSharpFieldDeclarationImpl)%0A%09%09%7B%0A%09%09%09return %22field%22;%0A%09%09%7D%0A%0A
 %09%09return

update type text for nodes