@Override
 @NotNull
 public Map<String, Void> map(final FileContent inputData) {
   final String className = getControllerClassName(inputData.getContentAsText().toString());
   if (className != null) {
     return Collections.singletonMap(className, null);
   }
   return Collections.emptyMap();
 }
 @NotNull
 @Override
 public Map<String, Void> map(@NotNull FileContent inputData) {
   final VirtualFile file = inputData.getFile();
   final String name = file.getName();
   if (PyNames.INIT_DOT_PY.equals(name)) {
     final VirtualFile parent = file.getParent();
     if (parent != null && parent.isDirectory()) {
       return Collections.singletonMap(parent.getName(), null);
     }
   } else {
     return Collections.singletonMap(FileUtil.getNameWithoutExtension(name), null);
   }
   return Collections.emptyMap();
 }
 @Override
 public void clear() throws StorageException {
   final StubIndexImpl stubIndex = StubIndexImpl.getInstanceOrInvalidate();
   final Collection<StubIndexKey> allStubIndexKeys =
       stubIndex != null
           ? stubIndex.getAllStubIndexKeys()
           : Collections.<StubIndexKey>emptyList();
   try {
     for (StubIndexKey key : allStubIndexKeys) {
       //noinspection ConstantConditions
       stubIndex.getWriteLock(key).lock();
     }
     getWriteLock().lock();
     if (stubIndex != null) {
       stubIndex.clearAllIndices();
     }
     super.clear();
   } finally {
     getWriteLock().unlock();
     for (StubIndexKey key : allStubIndexKeys) {
       //noinspection ConstantConditions
       stubIndex.getWriteLock(key).unlock();
     }
   }
 }
  private static void updateStubIndices(
      @NotNull final Collection<StubIndexKey> indexKeys,
      final int inputId,
      @NotNull final Map<StubIndexKey, Map<Object, int[]>> oldStubTree,
      @NotNull final Map<StubIndexKey, Map<Object, int[]>> newStubTree) {
    final StubIndexImpl stubIndex = (StubIndexImpl) StubIndex.getInstance();
    for (StubIndexKey key : indexKeys) {
      final Map<Object, int[]> oldMap = oldStubTree.get(key);
      final Map<Object, int[]> newMap = newStubTree.get(key);

      final Map<Object, int[]> _oldMap =
          oldMap != null ? oldMap : Collections.<Object, int[]>emptyMap();
      final Map<Object, int[]> _newMap =
          newMap != null ? newMap : Collections.<Object, int[]>emptyMap();

      stubIndex.updateIndex(key, inputId, _oldMap, _newMap);
    }
  }
 private static Map<StubIndexKey, Map<Object, int[]>> getStubTree(
     @NotNull final Map<Integer, SerializedStubTree> data) {
   final Map<StubIndexKey, Map<Object, int[]>> stubTree;
   if (!data.isEmpty()) {
     final SerializedStubTree stub = data.values().iterator().next();
     stubTree = new StubTree((PsiFileStub) stub.getStub(true), false).indexStubTree();
   } else {
     stubTree = Collections.emptyMap();
   }
   return stubTree;
 }
  private void dropUnregisteredIndices() {
    final Set<String> indicesToDrop =
        new HashSet<String>(
            myPreviouslyRegistered != null
                ? myPreviouslyRegistered.registeredIndices
                : Collections.<String>emptyList());
    for (ID<?, ?> key : myIndices.keySet()) {
      indicesToDrop.remove(key.toString());
    }

    for (String s : indicesToDrop) {
      FileUtil.delete(IndexInfrastructure.getIndexRootDir(ID.create(s)));
    }
  }
  @Override
  public <K> Collection<K> getAllKeys(final StubIndexKey<K, ?> indexKey, @NotNull Project project) {
    FileBasedIndex.getInstance()
        .ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, GlobalSearchScope.allScope(project));

    final MyIndex<K> index = (MyIndex<K>) myIndices.get(indexKey);
    try {
      return index.getAllKeys();
    } catch (StorageException e) {
      forceRebuild(e);
    } catch (RuntimeException e) {
      final Throwable cause = e.getCause();
      if (cause instanceof IOException || cause instanceof StorageException) {
        forceRebuild(e);
      }
      throw e;
    }
    return Collections.emptyList();
  }
 public Collection<StubIndexKey> getAllStubIndexKeys() {
   return Collections.<StubIndexKey>unmodifiableCollection(myIndices.keySet());
 }