/*
 * Copyright 2013-2015 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 consulo.dotnet.resolve;

import java.util.Collection;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import com.intellij.util.indexing.IdFilter;
import consulo.dotnet.psi.DotNetTypeDeclaration;

/**
 * @author VISTALL
 * @since 08.07.2015
 */
public abstract class DotNetShortNameSearcher
{
	@NotNull
	public static DotNetShortNameSearcher getInstance(@NotNull Project project)
	{
		return ServiceManager.getService(project, DotNetShortNameSearcher.class);
	}

	protected final Project myProject;

	public DotNetShortNameSearcher(Project project)
	{
		myProject = project;
	}

	@NotNull
	public Collection<String> getTypeNames(@NotNull GlobalSearchScope scope, @Nullable IdFilter filter)
	{
		CommonProcessors.CollectProcessor<String> collectProcessor = new CommonProcessors.CollectProcessor<String>();
		collectTypeNames(collectProcessor, scope, filter);
		return collectProcessor.getResults();
	}


	public abstract void collectTypeNames(@NotNull Processor<String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter);

	public abstract void collectTypes(@NotNull String key, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter, @NotNull Processor<DotNetTypeDeclaration> processor);

	@NotNull
	public Collection<DotNetTypeDeclaration> getTypes(@NotNull String key, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter)
	{
		CommonProcessors.CollectProcessor<DotNetTypeDeclaration> collectProcessor = new CommonProcessors.CollectProcessor<DotNetTypeDeclaration>();
		collectTypes(key, scope, filter, collectProcessor);
		return collectProcessor.getResults();
	}
}

@@ -634,28 +634,78 @@
 ort 
-java.util.Collection
+gnu.trove.THashSet;%0A%0Aimport java.util.Collection;%0Aimport java.util.Set
 ;%0A%0Ai
@@ -963,22 +963,16 @@
 ij.util.
-Common
 Processo
@@ -972,17 +972,16 @@
 rocessor
-s
 ;%0Aimport
@@ -1000,32 +1000,33 @@
 j.util.Processor
+s
 ;%0Aimport com.int
@@ -1607,113 +1607,41 @@
 %7B%0A%09%09
-CommonProcessors.CollectProcessor%3CString%3E collectProcessor = new CommonProcessors.CollectProcessor%3CString
+Set%3CString%3E types = new THashSet%3C
 %3E();
@@ -1660,17 +1660,38 @@
 peNames(
-c
+Processors.cancelableC
 ollectPr
@@ -1697,16 +1697,23 @@
 rocessor
+(types)
 , scope,
@@ -1735,37 +1735,13 @@
 urn 
-collectProcessor.getResults()
+types
 ;%0A%09%7D
@@ -2207,143 +2207,56 @@
 %7B%0A%09%09
-CommonProcessors.CollectProcessor%3CDotNetTypeDeclaration%3E collectProcessor = new CommonProcessors.CollectProcessor%3CDotNetTypeDeclaration
+Set%3CDotNetTypeDeclaration%3E types = new THashSet%3C
 %3E();
@@ -2291,23 +2291,16 @@
 filter, 
-collect
 Processo
@@ -2304,21 +2304,21 @@
 ssor
-);%0A%09%09return c
+s.cancelableC
 olle
@@ -2332,21 +2332,32 @@
 ssor
-.getResults()
+(types));%0A%09%09return types
 ;%0A%09%7D

change processor