public static @NotNull Collection<FileTargetContext> prepareTargetContexts(@NotNull Project project,
                                                                    @NotNull VirtualFile file,
                                                                    @NotNull Collection<FileTargetContext> targetContexts) {
    // here we try to sort target locations depending on src/test origin
    if (targetContexts.size() <= 1) {
      return targetContexts;
    }

    ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project);
    boolean isInSources = projectFileIndex.isInSourceContent(file)
                          && !projectFileIndex.isInTestSourceContent(file);

    List<FileTargetContextWrapper> targetContextWrappers = ContainerUtil.filter(findSourceRootTypes(targetContexts), tc -> {
      if (isInSources) {
        // exclude test directories for sources options
        if (tc.getSourceRootType() != null
            && tc.getSourceRootType().isForTests()) {
          return false;
        }
      }

      return !tc.isInGeneratedSource();
    });

    // sort only if we have different source root types
    if (!hasEqualSourceRootTypes(targetContextWrappers)) {
      // if file is under sources root then src/resources directories at the top
      // if file is under test sources root then test/resources directories at the top
      if (projectFileIndex.isInTestSourceContent(file)) {
        targetContextWrappers = ContainerUtil.sorted(targetContextWrappers, JpsFileTargetContextUtils::compareTargetsForTests);
      }
      else {
        // it could be a file from web resource root, it is not in source content, thus we do not check isInSourceContent(file)
        targetContextWrappers = ContainerUtil.sorted(targetContextWrappers, JpsFileTargetContextUtils::compareTargetsForProduction);
      }
    }

    return ContainerUtil.map(targetContextWrappers, FileTargetContextWrapper::getTargetContext);
  }
public static @NotNull Collection<FileTargetContext> prepareTargetContexts(@NotNull Project project,
                                                                    @NotNull VirtualFile file,
                                                                    @NotNull Collection<FileTargetContext> targetContexts)