private synchronized void initializeChunks(@NotNull CompileContext context) {
    if (myTargetChunks != null) {
      return;
    }

    Tracer.Span chunksInitSpan = Tracer.start("BuildTargetIndexImpl.initializeChunks");
    List<BuildTarget<?>> allTargets = getAllTargets();
    TargetOutputIndex outputIndex = new TargetOutputIndexImpl(allTargets, context);
    Map<BuildTarget<?>, Collection<BuildTarget<?>>> dummyTargetDependencies = new HashMap<>();
    final List<BuildTarget<?>> realTargets = new ArrayList<>(allTargets.size());
    for (BuildTarget<?> target : allTargets) {
      if (isDummy(target)) {
        dummyTargetDependencies.put(target, target.computeDependencies(myRegistry, outputIndex));
      }
      else {
        realTargets.add(target);
      }
    }

    for (BuildTarget<?> target : realTargets) {
      Collection<BuildTarget<?>> dependencies = target.computeDependencies(this, outputIndex);
      Collection<BuildTarget<?>> realDependencies;
      if (!ContainerUtil.intersects(dependencies, dummyTargetDependencies.keySet())) {
        realDependencies = dependencies;
      }
      else {
        realDependencies = includeTransitiveDependenciesOfDummyTargets(dependencies, dummyTargetDependencies);
      }
      myDependencies.put(target, realDependencies);
    }

    Graph<BuildTarget<?>> graph = GraphGenerator.generate(new InboundSemiGraph<BuildTarget<?>>() {
      @Override
      public @NotNull Collection<BuildTarget<?>> getNodes() {
        return allTargets;
      }

      @Override
      public @NotNull Iterator<BuildTarget<?>> getIn(BuildTarget<?> n) {
        Collection<BuildTarget<?>> deps = myDependencies.get(n);
        return deps != null ? deps.iterator() : Collections.emptyIterator();
      }
    });

    DFSTBuilder<BuildTarget<?>> builder = new DFSTBuilder<>(graph);
    Collection<Collection<BuildTarget<?>>> components = builder.getComponents();
    myTargetChunks = new ArrayList<>(components.size());
    for (Collection<BuildTarget<?>> component : components) {
      myTargetChunks.add(new BuildTargetChunk(new LinkedHashSet<>(component)));
    }
    chunksInitSpan.complete();
  }
private synchronized void initializeChunks(@NotNull CompileContext context)