コード例 #1
0
ファイル: ViewAnalyzer.java プロジェクト: sugiii8/asakusafw
  private List<View> sort() {
    Map<Name, View> map = new HashMap<Name, View>();
    Graph<Name> dependencies = Graphs.newInstance();
    for (View view : added) {
      Name name = view.ast.name;
      map.put(name, view);
      for (Name dependTo : view.ast.getDependencies()) {
        dependencies.addEdge(name, dependTo);
      }
    }

    // 依存関係の循環を指摘
    Set<Set<Name>> circuit = Graphs.findCircuit(dependencies);
    if (circuit.isEmpty() == false) {
      throw new IllegalStateException(MessageFormat.format("ビューの参照関係に循環が存在します: {0}", circuit));
    }

    // 依存関係の逆順に整列
    List<Name> sorted = Graphs.sortPostOrder(dependencies);

    List<View> results = new ArrayList<View>();
    for (Name name : sorted) {
      // 外部参照でないものについてのみ結果に残す
      View view = map.get(name);
      if (view != null) {
        results.add(view);
      }
    }
    return results;
  }
コード例 #2
0
  /** generic method. */
  @Test
  public void generics() {
    add("com.example.Generic");
    ClassLoader loader = start(new FoldOperatorProcessor());

    Object factory = create(loader, "com.example.GenericFactory");

    MockIn<MockHoge> in = MockIn.of(MockHoge.class, "in");
    MockOut<MockHoge> out = MockOut.of(MockHoge.class, "out");
    Object fold = invoke(factory, "example", in, 100);
    out.add(output(MockHoge.class, fold, "out"));

    Graph<String> graph = toGraph(in);
    assertThat(graph.getConnected("in"), isJust("Generic.example"));
    assertThat(graph.getConnected("Generic.example"), isJust("out"));
  }
コード例 #3
0
  /** ジェネリックメソッド。 */
  @Test
  public void generics() {
    add("com.example.Generic");
    add("com.example.ExampleEnum");
    ClassLoader loader = start(new BranchOperatorProcessor());

    Object factory = create(loader, "com.example.GenericFactory");

    MockIn<MockHoge> in = MockIn.of(MockHoge.class, "in");
    MockOut<MockHoge> high = MockOut.of(MockHoge.class, "high");
    MockOut<MockHoge> middle = MockOut.of(MockHoge.class, "middle");
    MockOut<MockHoge> low = MockOut.of(MockHoge.class, "low");
    Object branch = invoke(factory, "example", in);
    high.add(output(MockHoge.class, branch, "high"));
    middle.add(output(MockHoge.class, branch, "middle"));
    low.add(output(MockHoge.class, branch, "low"));

    Graph<String> graph = toGraph(in);
    assertThat(graph.getConnected("in"), isJust("Generic.example"));
    assertThat(graph.getConnected("Generic.example"), isJust("high", "middle", "low"));
  }