当前位置: 首页>>代码示例>>Java>>正文


Java MutableGraph类代码示例

本文整理汇总了Java中com.google.common.graph.MutableGraph的典型用法代码示例。如果您正苦于以下问题:Java MutableGraph类的具体用法?Java MutableGraph怎么用?Java MutableGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MutableGraph类属于com.google.common.graph包,在下文中一共展示了MutableGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: depsForSingleFileComponentsInDifferentPackage

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests dependency behavior when a single file depends on a file in another package/directory.
 * Behavior should not differ from when they were in the same directory.
 */
@Test
public void depsForSingleFileComponentsInDifferentPackage() {
  MutableGraph<BuildRule> buildRuleGraph = newGraph();
  ProjectBuildRule src =
      newProjectBuildRule("/workspace/java/package/", "/workspace/java/package/Example.java");
  ProjectBuildRule dst =
      newProjectBuildRule("/workspace/java/other/", "/workspace/java/other/Other.java");

  buildRuleGraph.putEdge(src, dst);

  ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
  assertThat(actual)
      .containsExactly(
          "new java_library Example|//java/package:__pkg__",
          "add srcs Example.java|//java/package:Example",
          "new java_library Other|//java/other:__pkg__",
          "add srcs Other.java|//java/other:Other",
          "add deps //java/other:Other|//java/package:Example");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:24,代码来源:BuildozerCommandCreatorTest.java

示例2: map

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Converts the class file dependency graph into the source file dependency graph, by
 * consolidating classes from the same source file. Given as input:
 *
 * <p>ul>
 * <li>a directed graph where the nodes are classes (both inner and outer) and edges are
 *     dependencies between said classes
 * <li>a mapping between outer class files and source files.
 * </ul>
 *
 * This function outputs a directed graph where the nodes are source files and the edges are
 * dependencies between said source files.
 */
// TODO(bazel-team): Migrate this function into Guava graph library
public static ImmutableGraph<Path> map(
    Graph<String> classGraph, Map<String, Path> classToSourceFileMap) {
  MutableGraph<Path> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
  for (String sourceNode : classGraph.nodes()) {
    if (isInnerClass(sourceNode)) {
      throw new GraphProcessorException(
          String.format("Found inner class %s when mapping classes to source files", sourceNode));
    }
    Path sourcePath = classToSourceFileMap.get(sourceNode);
    graph.addNode(sourcePath);
    for (String successorNode : classGraph.successors(sourceNode)) {
      Path successorPath = classToSourceFileMap.get(successorNode);
      if (!sourcePath.equals(successorPath)) {
        graph.putEdge(sourcePath, successorPath);
      }
    }
  }
  return ImmutableGraph.copyOf(graph);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:34,代码来源:ClassToSourceGraphConsolidator.java

示例3: trimClassGraph

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Removes all outgoing edges from classes that are not white listed. */
private static ImmutableGraph<String> trimClassGraph(
    ImmutableGraph<String> classGraph, Pattern whiteList, Pattern blackList) {
  MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
  for (String src : classGraph.nodes()) {
    if (!whiteList.matcher(src).find() || blackList.matcher(src).find()) {
      continue;
    }
    graph.addNode(src);
    for (String dst : classGraph.successors(src)) {
      if (blackList.matcher(dst).find()) {
        continue;
      }
      graph.putEdge(src, dst);
    }
  }
  return ImmutableGraph.copyOf(graph);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessor.java

示例4: collapseInnerClasses

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Collapses inner classes into their top level parent class */
private static ImmutableGraph<String> collapseInnerClasses(ImmutableGraph<String> classGraph) {
  MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
  for (String src : classGraph.nodes()) {
    String outerSrc = getOuterClassName(src);
    graph.addNode(outerSrc);
    for (String dst : classGraph.successors(src)) {
      String outerDst = getOuterClassName(dst);
      if (outerSrc.equals(outerDst)) {
        continue;
      }
      graph.putEdge(outerSrc, outerDst);
    }
  }
  return ImmutableGraph.copyOf(graph);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:ClassGraphPreprocessor.java

示例5: createBuildRuleDAG

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Creates the build rule DAG using provided resolvers. Each resolver maps a top level class name
 * to a build rule. We combine the resolvers to create one huge Map from class to rule.
 *
 * <p>We make the following stipulations. First, a class must not map to more than one build rule.
 * Otherwise, we throw an error. However, a class need not map to any rule. In which case we will
 * not include it in the resulting build rule Graph. Second, the resulting graph must not have
 * cycles.
 *
 * <p>TODO(bazel-team) Report/Crash if the resulting graph has cycles.
 */
ImmutableGraph<BuildRule> createBuildRuleDAG(Iterable<ClassToRuleResolver> resolvers) {
  ImmutableMap<String, BuildRule> ruleMap = createClassToRuleMap(resolvers);
  MutableGraph<BuildRule> buildRuleDAG = GraphBuilder.directed().allowsSelfLoops(false).build();
  for (String className : classGraph.nodes()) {
    BuildRule srcRule = ruleMap.get(className);
    if (srcRule == null) {
      continue;
    }
    buildRuleDAG.addNode(srcRule);
    for (String successor : classGraph.successors(className)) {
      BuildRule dstRule = ruleMap.get(successor);
      if (dstRule == null || srcRule.equals(dstRule)) {
        continue;
      }
      buildRuleDAG.putEdge(srcRule, dstRule);
    }
  }
  return ImmutableGraph.copyOf(buildRuleDAG);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:31,代码来源:GraphProcessor.java

示例6: bijectiveClassRuleMapping

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Tests behavior of graph processor when each class is mapped to its own build rule. */
@Test
public void bijectiveClassRuleMapping() {
  MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");

  GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));

  String packagePath = "/java/com/";
  BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
  BuildRule ruleB = newBuildRule(packagePath, "/java/com/B.java");
  BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
  ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
  when(resolver.resolve(classgraph.nodes()))
      .thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleB, "com.C", ruleC));

  Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));

  MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
  expected.putEdge(ruleA, ruleB);
  expected.putEdge(ruleB, ruleC);

  assertThatGraphsEqual(actual, expected);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:GraphProcessorTest.java

示例7: manyClassesToOneRuleNoSelfLoop

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior when multiple classes map to the same build rule. Ensures that the resulting
 * build rule graph has no self loops.
 */
@Test
public void manyClassesToOneRuleNoSelfLoop() {
  MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");

  GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));

  String packagePath = "/java/com/";
  BuildRule ruleA = newBuildRule(packagePath, "/java/com/A.java");
  BuildRule ruleC = newBuildRule(packagePath, "/java/com/C.java");
  ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
  when(resolver.resolve(classgraph.nodes()))
      .thenReturn(ImmutableMap.of("com.A", ruleA, "com.B", ruleA, "com.C", ruleC));

  Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
  assertThat(actual.edges()).doesNotContain(EndpointPair.ordered(ruleA, ruleA));

  MutableGraph<BuildRule> expected = GraphBuilder.directed().allowsSelfLoops(false).build();
  expected.putEdge(ruleA, ruleC);

  assertThatGraphsEqual(actual, expected);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:28,代码来源:GraphProcessorTest.java

示例8: doesNotSupportInnerClassNames

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Ensures that given an inner class, the graph processor throws an illegal state exception. */
@Test
public void doesNotSupportInnerClassNames() {
  MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
  classgraph.putEdge("com.A", "com.A$InnerClass");

  try {
    new GraphProcessor(ImmutableGraph.copyOf(classgraph));
    fail("Expected an exception, but nothing was thrown.");
  } catch (IllegalStateException e) {
    assertThat(e)
        .hasMessageThat()
        .isEqualTo(
            "Argument contained inner class name com.A$InnerClass but expected no inner classes");
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:17,代码来源:GraphProcessorTest.java

示例9: emptyMapping

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior of graph processor when no classes are mapped to build rules. The resulting DAG
 * should be empty.
 */
@Test
public void emptyMapping() {
  MutableGraph<String> classgraph = GraphBuilder.directed().allowsSelfLoops(false).build();
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");
  classgraph.putEdge("com.C", "com.D");

  GraphProcessor processor = new GraphProcessor(ImmutableGraph.copyOf(classgraph));

  ClassToRuleResolver resolver = mock(ClassToRuleResolver.class);
  when(resolver.resolve(classgraph.nodes())).thenReturn(ImmutableMap.of());

  Graph<BuildRule> actual = processor.createBuildRuleDAG(ImmutableList.of(resolver));
  assertThat(actual.nodes()).isEmpty();
  assertThat(actual.edges()).isEmpty();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:21,代码来源:GraphProcessorTest.java

示例10: filteredDAGWithUniqueTargets

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior of resolver on a graph where each class is uniquely mapped to a target, AND only
 * a subset of classes have been asked to be resolved. Resulting map should have each class, in
 * the provided list, uniquely mapped to a build rule.
 */
@Test
public void filteredDAGWithUniqueTargets() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A", "com.B");

  ProjectClassToRuleResolver resolver =
      newResolver(
          classgraph,
          WHITELIST_DEFAULT,
          ImmutableMap.of(
              "com.A",
              workspace.resolve("java/com/A.java"),
              "com.B",
              workspace.resolve("java/com/B.java")));

  ImmutableMap<String, BuildRule> actual = resolver.resolve(ImmutableSet.of("com.A"));

  String packagePath = "/src/java/com/";
  assertThat(actual).containsExactly("com.A", buildRule(packagePath, "/src/java/com/A.java"));
  assertThat(actual).doesNotContainKey("com.B");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:27,代码来源:ProjectClassToRuleResolverTest.java

示例11: graphWithOnlyOneTarget

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior of resolver on a graph where all classes map to the same target. Resulting map
 * should have each class map to the same build rule.
 */
@Test
public void graphWithOnlyOneTarget() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");
  classgraph.putEdge("com.C", "com.A");

  ProjectClassToRuleResolver resolver =
      newResolver(
          classgraph,
          WHITELIST_DEFAULT,
          ImmutableMap.of(
              "com.A",
              workspace.resolve("java/com/A.java"),
              "com.B",
              workspace.resolve("java/com/B.java"),
              "com.C",
              workspace.resolve("java/com/C.java")));

  ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
  assertThat(actual).containsKey("com.A");
  assertThat(actual.get("com.A")).isEqualTo(actual.get("com.B"));
  assertThat(actual.get("com.B")).isEqualTo(actual.get("com.C"));
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:29,代码来源:ProjectClassToRuleResolverTest.java

示例12: graphWithInnerClass

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior of resolver on a graph when an inner class is provided. Resolver should throw an
 * Illegal State Exception in this event.
 */
@Test
public void graphWithInnerClass() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A$hello", "com.B");

  try {
    newResolver(classgraph, WHITELIST_DEFAULT, ImmutableMap.of());
    fail("Expected an exception, but nothing was thrown.");
  } catch (IllegalStateException e) {
    assertThat(e)
        .hasMessageThat()
        .isEqualTo(
            "Argument contained inner class name com.A$hello but expected no inner classes");
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:20,代码来源:ProjectClassToRuleResolverTest.java

示例13: noMatchingClassNames

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * Tests behavior of resolver when there are no classes that match white list pattern. The
 * resulting map should contain no entries.
 */
@Test
public void noMatchingClassNames() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");

  ProjectClassToRuleResolver resolver =
      newResolver(
          classgraph,
          Pattern.compile("com.hello.*"),
          ImmutableMap.of(
              "com.A",
              workspace.resolve("java/com/A.java"),
              "com.B",
              workspace.resolve("java/com/B.java"),
              "com.C",
              workspace.resolve("java/com/C.java")));

  ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
  assertThat(actual).isEmpty();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:ProjectClassToRuleResolverTest.java

示例14: ignoresUnresolvedClass_smallerThanThreshold

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/**
 * If a class's source file cannot be found, then that class name should not be in the ensuing
 * class. Since less than the default threshold are unresolved, BFG should NOT error out.
 */
@Test
public void ignoresUnresolvedClass_smallerThanThreshold() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A", "com.DoesNotExist");

  ProjectClassToRuleResolver resolver =
      newResolver(
          classgraph,
          WHITELIST_DEFAULT,
          ImmutableMap.of("com.A", workspace.resolve("java/com/A.java")));
  ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
  assertThat(actual)
      .containsExactly("com.A", buildRule("/src/java/com/", "/src/java/com/A.java"));
  assertThat(actual).doesNotContainKey("com.DoesNotExist");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:20,代码来源:ProjectClassToRuleResolverTest.java

示例15: trimRemovesBlackListedClasses

import com.google.common.graph.MutableGraph; //导入依赖的package包/类
/** Tests whether the black listed class names are removed from the class graph. */
@Test
public void trimRemovesBlackListedClasses() {
  MutableGraph<String> graph = newGraph();
  graph.putEdge("com.BlackList", "com.WhiteList");
  graph.putEdge("com.WhiteList", "com.BlackList");

  Pattern blackList = Pattern.compile("BlackList");

  Graph<String> actual =
      preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, blackList);

  MutableGraph<String> expected = newGraph();
  expected.addNode("com.WhiteList");

  assertEquivalent(actual, expected);
  assertThat(actual.nodes()).doesNotContain("com.BlackList");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessorTest.java


注:本文中的com.google.common.graph.MutableGraph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。