package com.jetbrains.lang.dart.ide;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.ArrayUtil;
import com.jetbrains.lang.dart.ide.index.DartClassIndex;
import com.jetbrains.lang.dart.psi.DartComponentName;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* @author: Fedor.Korotkov
*/
public class DartClassContributor implements ChooseByNameContributor {
@NotNull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems) {
final Collection<String> result = DartClassIndex.getNames(project);
return ArrayUtil.toStringArray(result);
}
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
final Collection<DartComponentName> result = DartClassIndex.getItemsByName(name, project, scope);
if (result.size() == 0) {
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
}
return result.toArray(new NavigationItem[result.size()]);
}
}