/** * Create all the modules we are capable of representing in IntelliJ from the supplied graph. * * @param targetGraph graph whose nodes will be converted to {@link IjModule}s. * @return map which for every BuildTarget points to the corresponding IjModule. Multiple * BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which can't be * prepresented in IntelliJ are missing from this mapping. */ public static ImmutableMap<BuildTarget, IjModule> createModules( TargetGraph targetGraph, IjModuleFactory moduleFactory) { ImmutableSet<TargetNode<?>> supportedTargets = FluentIterable.from(targetGraph.getNodes()) .filter(IjModuleFactory.SUPPORTED_MODULE_TYPES_PREDICATE) .toSet(); ImmutableListMultimap<Path, TargetNode<?>> baseTargetPathMultimap = FluentIterable.from(supportedTargets) .index( new Function<TargetNode<?>, Path>() { @Override public Path apply(TargetNode<?> input) { return input.getBuildTarget().getBasePath(); } }); ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>(); for (Path baseTargetPath : baseTargetPathMultimap.keySet()) { ImmutableSet<TargetNode<?>> targets = FluentIterable.from(baseTargetPathMultimap.get(baseTargetPath)).toSet(); IjModule module = moduleFactory.createModule(baseTargetPath, targets); for (TargetNode<?> target : targets) { moduleMapBuilder.put(target.getBuildTarget(), module); } } return moduleMapBuilder.build(); }
/** * Create all the modules we are capable of representing in IntelliJ from the supplied graph. * * @param targetGraph graph whose nodes will be converted to {@link IjModule}s. * @return map which for every BuildTarget points to the corresponding IjModule. Multiple * BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which can't be * prepresented in IntelliJ are missing from this mapping. */ private static ImmutableMap<BuildTarget, IjModule> createModules( TargetGraph targetGraph, IjModuleFactory moduleFactory, final Function<Path, Path> basePathTransform) { ImmutableSet<TargetNode<?>> supportedTargets = FluentIterable.from(targetGraph.getNodes()) .filter(IjModuleFactory.SUPPORTED_MODULE_TYPES_PREDICATE) .toSet(); ImmutableListMultimap<Path, TargetNode<?>> baseTargetPathMultimap = FluentIterable.from(supportedTargets) .index( new Function<TargetNode<?>, Path>() { @Override public Path apply(TargetNode<?> input) { if (!(input.getConstructorArg() instanceof AndroidResourceDescription.Arg)) { return basePathTransform.apply(input.getBuildTarget().getBasePath()); } return input.getBuildTarget().getBasePath(); } }); ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>(); for (Path baseTargetPath : baseTargetPathMultimap.keySet()) { ImmutableSet<TargetNode<?>> targets = FluentIterable.from(baseTargetPathMultimap.get(baseTargetPath)).toSet(); IjModule module = moduleFactory.createModule(baseTargetPath, targets); for (TargetNode<?> target : targets) { moduleMapBuilder.put(target.getBuildTarget(), module); } } return moduleMapBuilder.build(); }