/**
   * Gets all the values of the entries that include the module specified.
   *
   * @param index - index to use.
   * @param module - module.
   * @return map from module to the list of entries defined in that module
   */
  public static Map<IModule, List<IncludePHPEntryValue>> getIncludes(
      IElementsIndex index, IModule module) {
    Map<IModule, List<IncludePHPEntryValue>> candidates =
        new HashMap<IModule, List<IncludePHPEntryValue>>();

    String moduleShortName = module.getShortName();

    // collecting initial candidates
    Set<IModule> modules = index.getModules();
    for (IModule currentModule : modules) {
      List<IElementEntry> moduleEntries = index.getModuleEntries(currentModule);
      for (IElementEntry entry : moduleEntries) {
        Object entryValue = entry.getValue();
        if (entryValue instanceof IncludePHPEntryValue) {
          IncludePHPEntryValue includeValue = (IncludePHPEntryValue) entryValue;
          if (includeValue.getIncludePath().endsWith(moduleShortName)) {
            List<IncludePHPEntryValue> moduleValues = candidates.get(currentModule);
            if (moduleValues == null) {
              moduleValues = new ArrayList<IncludePHPEntryValue>(1);
              candidates.put(currentModule, moduleValues);
            }

            moduleValues.add(includeValue);
          }
        }
      }
    }

    Map<IModule, List<IncludePHPEntryValue>> result =
        new HashMap<IModule, List<IncludePHPEntryValue>>();

    // filtering candidates
    for (Entry<IModule, List<IncludePHPEntryValue>> entry : candidates.entrySet()) {
      IModule currentModule = entry.getKey();
      List<IncludePHPEntryValue> values = entry.getValue();
      for (IncludePHPEntryValue value : values) {
        String includePathString = value.getIncludePath();
        IPath includePath = new Path(includePathString);
        IModule resolvedModule =
            currentModule.getBuildPath().resolveRelativePath(currentModule, includePath);
        if (resolvedModule != null && resolvedModule.equals(module)) {
          List<IncludePHPEntryValue> moduleValues = result.get(currentModule);
          if (moduleValues == null) {
            moduleValues = new ArrayList<IncludePHPEntryValue>(1);
            result.put(currentModule, moduleValues);
          }

          moduleValues.add(value);
        }
      }
    }

    return result;
  }
  /**
   * Gets module includes.
   *
   * @param module - module
   * @param index - index to use.
   * @return module includes list
   */
  public static List<IncludePHPEntryValue> getModuleIncludes(IModule module, IElementsIndex index) {
    List<IncludePHPEntryValue> result = new ArrayList<IncludePHPEntryValue>();

    List<IElementEntry> moduleEntries = index.getModuleEntries(module);
    for (IElementEntry entry : moduleEntries) {
      Object entryValue = entry.getValue();
      if (entryValue instanceof IncludePHPEntryValue) {
        result.add((IncludePHPEntryValue) entryValue);
      }
    }

    return result;
  }