// Path: src/org/emberjs/index/EmberSymbolIndex.java
// public class EmberSymbolIndex extends EmberIndexBase {
//     public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index");
// 
//     @NotNull
//     @Override
//     public ID<String, Void> getName() {
//         return INDEX_ID;
//     }
// }
// 
// Path: src/org/emberjs/index/EmberIndexUtil.java
// public class EmberIndexUtil {
//     public static final int BASE_VERSION = 17;
//     private static final EmberKeysProvider PROVIDER = new EmberKeysProvider();
//     // Not sure what this is used for
//     private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>();
// 
//     public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) {
//         JSNamedElementProxy result = null;
//         final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project);
//         final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
//         for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) {
//             final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope);
//             final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null;
//             if (resolve != null) {
//                 result = resolve;
//                 if (result.canNavigate()) break;
//             }
//         }
//         return result;
//     }
// 
//     // TODO: Determine is this project has ember.js available, which means looking into package.json I guess?
//     // Perhaps should be renamed to hasEmberCli
//     public static boolean hasEmberJS(final Project project) {
//         if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false;
//         return getEmberJSVersion(project) > 0;
//     }
// 
//     private static int getEmberJSVersion(final Project project) {
//         if (DumbService.isDumb(project)) return -1;
//         return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() {
//             @Nullable
//             @Override
//             public Result<Integer> compute() {
//                 int version = -1;
//                 // TODO: Find version of Ember used somehow!
// //                if (resolve(project, EmberIndex.INDEX_ID, "") != null) {
// //                    version = 18;
// //                }
//                 return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
//             }
//         });
//     }
// 
//     public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) {
//         final String indexId = index.toString();
//         final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId));
//         return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index));
//     }
// 
//     private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> {
//         @Nullable
//         @Override
//         public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) {
//             final Set<String> allKeys = new THashSet<String>();
//             final FileBasedIndex index = FileBasedIndex.getInstance();
//             final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first);
//             final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) {
//                 @Override
//                 protected boolean accept(String key) {
//                     return true;
//                 }
//             };
//             index.processAllKeys(projectAndIndex.second, processor, scope, null);
//             return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() {
//                 @Override
//                 public boolean value(String key) {
//                     return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() {
//                         @Override
//                         public boolean process(VirtualFile file, Void value) {
//                             return false;
//                         }
//                     }, scope);
//                 }
//             }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker());
//         }
//     }
// }


import org.emberjs.index.EmberSymbolIndex;
import com.intellij.lang.javascript.index.JSNamedElementProxy;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import com.intellij.util.ArrayUtil;
import org.emberjs.index.EmberIndexUtil;
import org.jetbrains.annotations.NotNull;
package org.emberjs.navigation;


/**
 * @author Kristian Mandrup
 */
public class EmberGotoSymbolContributor implements ChooseByNameContributor {
    @NotNull
    @Override
    public String[] getNames(Project project, boolean includeNonProjectItems) {
        return ArrayUtil.toStringArray(EmberIndexUtil.getAllKeys(EmberSymbolIndex.INDEX_ID, project));
    }

    @NotNull
    @Override
    public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
// Path: src/org/emberjs/index/EmberSymbolIndex.java
// public class EmberSymbolIndex extends EmberIndexBase {
//     public static final ID<String, Void> INDEX_ID = ID.create("emberjs.symbol.index");
// 
//     @NotNull
//     @Override
//     public ID<String, Void> getName() {
//         return INDEX_ID;
//     }
// }
// 
// Path: src/org/emberjs/index/EmberIndexUtil.java
// public class EmberIndexUtil {
//     public static final int BASE_VERSION = 17;
//     private static final EmberKeysProvider PROVIDER = new EmberKeysProvider();
//     // Not sure what this is used for
//     private static final ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>> ourCacheKeys = new ConcurrentHashMap<String, Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>>();
// 
//     public static JSNamedElementProxy resolve(final Project project, final ID<String, Void> index, final String lookupKey) {
//         JSNamedElementProxy result = null;
//         final JavaScriptIndex jsIndex = JavaScriptIndex.getInstance(project);
//         final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
//         for (VirtualFile file : FileBasedIndex.getInstance().getContainingFiles(index, lookupKey, scope)) {
//             final JSIndexEntry entry = jsIndex.getEntryForFile(file, scope);
//             final JSNamedElementProxy resolve = entry != null ? entry.resolveAdditionalData(jsIndex, index.toString(), lookupKey) : null;
//             if (resolve != null) {
//                 result = resolve;
//                 if (result.canNavigate()) break;
//             }
//         }
//         return result;
//     }
// 
//     // TODO: Determine is this project has ember.js available, which means looking into package.json I guess?
//     // Perhaps should be renamed to hasEmberCli
//     public static boolean hasEmberJS(final Project project) {
//         if (ApplicationManager.getApplication().isUnitTestMode() && "disabled".equals(System.getProperty("ember.js"))) return false;
//         return getEmberJSVersion(project) > 0;
//     }
// 
//     private static int getEmberJSVersion(final Project project) {
//         if (DumbService.isDumb(project)) return -1;
//         return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<Integer>() {
//             @Nullable
//             @Override
//             public Result<Integer> compute() {
//                 int version = -1;
//                 // TODO: Find version of Ember used somehow!
// //                if (resolve(project, EmberIndex.INDEX_ID, "") != null) {
// //                    version = 18;
// //                }
//                 return Result.create(version, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
//             }
//         });
//     }
// 
//     public static Collection<String> getAllKeys(final ID<String, Void> index, final Project project) {
//         final String indexId = index.toString();
//         final Key<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>> key = ConcurrencyUtil.cacheOrGet(ourCacheKeys, indexId, Key.<ParameterizedCachedValue<List<String>, Pair<Project, ID<String, Void>>>>create("angularjs.index." + indexId));
//         return CachedValuesManager.getManager(project).getParameterizedCachedValue(project, key, PROVIDER, false, Pair.create(project, index));
//     }
// 
//     private static class EmberKeysProvider implements ParameterizedCachedValueProvider<List<String>, Pair<Project, ID<String, Void>>> {
//         @Nullable
//         @Override
//         public CachedValueProvider.Result<List<String>> compute(final Pair<Project, ID<String, Void>> projectAndIndex) {
//             final Set<String> allKeys = new THashSet<String>();
//             final FileBasedIndex index = FileBasedIndex.getInstance();
//             final GlobalSearchScope scope = GlobalSearchScope.allScope(projectAndIndex.first);
//             final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(allKeys) {
//                 @Override
//                 protected boolean accept(String key) {
//                     return true;
//                 }
//             };
//             index.processAllKeys(projectAndIndex.second, processor, scope, null);
//             return CachedValueProvider.Result.create(ContainerUtil.filter(allKeys, new Condition<String>() {
//                 @Override
//                 public boolean value(String key) {
//                     return !index.processValues(projectAndIndex.second, key, null, new FileBasedIndex.ValueProcessor<Void>() {
//                         @Override
//                         public boolean process(VirtualFile file, Void value) {
//                             return false;
//                         }
//                     }, scope);
//                 }
//             }), PsiManager.getInstance(projectAndIndex.first).getModificationTracker());
//         }
//     }
// }


// Path: src/org/emberjs/navigation/EmberGotoSymbolContributor.java
import org.emberjs.index.EmberSymbolIndex;
import com.intellij.lang.javascript.index.JSNamedElementProxy;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import com.intellij.util.ArrayUtil;
import org.emberjs.index.EmberIndexUtil;
import org.jetbrains.annotations.NotNull;

package org.emberjs.navigation;


/**
 * @author Kristian Mandrup
 */
public class EmberGotoSymbolContributor implements ChooseByNameContributor {
    @NotNull
    @Override
    public String[] getNames(Project project, boolean includeNonProjectItems) {
        return ArrayUtil.toStringArray(EmberIndexUtil.getAllKeys(EmberSymbolIndex.INDEX_ID, project));
    }

    @NotNull
    @Override
    public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
        final JSNamedElementProxy item = EmberIndexUtil.resolve(project, EmberSymbolIndex.INDEX_ID, name);