@NotNull
  private static AbstractGradleDependency buildDependency(
      @NotNull GradleModule ownerModule,
      @NotNull IdeaModuleDependency dependency,
      @NotNull GradleProject intellijProject)
      throws IllegalStateException {
    IdeaModule module = dependency.getDependencyModule();
    if (module == null) {
      throw new IllegalStateException(
          String.format(
              "Can't parse gradle module dependency '%s'. Reason: referenced module is null",
              dependency));
    }

    String moduleName = module.getName();
    if (moduleName == null) {
      throw new IllegalStateException(
          String.format(
              "Can't parse gradle module dependency '%s'. Reason: referenced module name is undefined (module: '%s') ",
              dependency, module));
    }

    Set<String> registeredModuleNames = new HashSet<String>();
    for (GradleModule gradleModule : intellijProject.getModules()) {
      registeredModuleNames.add(gradleModule.getName());
      if (gradleModule.getName().equals(moduleName)) {
        return new GradleModuleDependency(ownerModule, gradleModule);
      }
    }
    throw new IllegalStateException(
        String.format(
            "Can't parse gradle module dependency '%s'. Reason: no module with such name (%s) is found. Registered modules: %s",
            dependency, moduleName, registeredModuleNames));
  }
  @Override
  public void calculate(
      @NotNull GradleProject gradleEntity,
      @NotNull Project intellijEntity,
      @NotNull GradleChangesCalculationContext context) {
    calculateProjectChanges(gradleEntity, intellijEntity, context.getCurrentChanges());

    final Set<? extends GradleModule> gradleSubEntities = gradleEntity.getModules();
    final Collection<Module> intellijSubEntities = myPlatformFacade.getModules(intellijEntity);
    GradleDiffUtil.calculate(
        myModuleChangesCalculator, gradleSubEntities, intellijSubEntities, context);

    LibraryTable libraryTable = myPlatformFacade.getProjectLibraryTable(intellijEntity);
    GradleDiffUtil.calculate(
        myLibraryChangesCalculator,
        gradleEntity.getLibraries(),
        Arrays.asList(libraryTable.getLibraries()),
        context);
  }