Exemplo n.º 1
0
 private TypeDeclaration createType() {
   SimpleName name = factory.newSimpleName(Naming.getCombineClass());
   importer.resolvePackageMember(name);
   List<TypeBodyDeclaration> members = new ArrayList<TypeBodyDeclaration>();
   members.addAll(prepareFields());
   members.add(createSetup());
   members.add(createCleanup());
   members.add(createGetRendezvous());
   return factory.newClassDeclaration(
       new JavadocBuilder(factory)
           .text("ステージ{0}の処理を担当するコンバイナープログラム。", shuffle.getStageBlock().getStageNumber())
           .toJavadoc(),
       new AttributeBuilder(factory)
           .annotation(t(SuppressWarnings.class), v("deprecation"))
           .Public()
           .Final()
           .toAttributes(),
       name,
       Collections.<TypeParameterDeclaration>emptyList(),
       importer.resolve(
           factory.newParameterizedType(
               Models.toType(factory, SegmentedCombiner.class),
               Arrays.asList(
                   importer.toType(shuffle.getCompiled().getKeyTypeName()),
                   importer.toType(shuffle.getCompiled().getValueTypeName())))),
       Collections.<Type>emptyList(),
       members);
 }
Exemplo n.º 2
0
    private MethodDeclaration createGetRendezvous() {
      Map<FlowElement, SimpleName> fragments = new HashMap<FlowElement, SimpleName>();
      for (Map.Entry<Fragment, SimpleName> entry : rendezvousNames.entrySet()) {
        fragments.put(entry.getKey().getFactors().get(0).getElement(), entry.getValue());
      }

      List<Statement> cases = new ArrayList<Statement>();
      for (List<ShuffleModel.Segment> group : ShuffleEmiterUtil.groupByElement(shuffle)) {
        for (ShuffleModel.Segment segment : group) {
          cases.add(factory.newSwitchCaseLabel(v(segment.getPortId())));
        }
        FlowElement element = group.get(0).getPort().getOwner();
        SimpleName rendezvousName = fragments.get(element);
        if (rendezvousName == null) {
          cases.add(
              new ExpressionBuilder(factory, Models.toNullLiteral(factory)).toReturnStatement());
        } else {
          cases.add(
              new ExpressionBuilder(factory, factory.newThis())
                  .field(rendezvousName)
                  .toReturnStatement());
        }
      }
      cases.add(factory.newSwitchDefaultLabel());
      cases.add(new TypeBuilder(factory, t(AssertionError.class)).newObject().toThrowStatement());

      SimpleName argument = names.create("nextKey");
      List<Statement> statements = new ArrayList<Statement>();
      statements.add(
          factory.newSwitchStatement(
              new ExpressionBuilder(factory, argument)
                  .method(SegmentedWritable.ID_GETTER)
                  .toExpression(),
              cases));

      return factory.newMethodDeclaration(
          null,
          new AttributeBuilder(factory).annotation(t(Override.class)).Protected().toAttributes(),
          importer.resolve(
              factory.newParameterizedType(
                  Models.toType(factory, Rendezvous.class),
                  importer.toType(shuffle.getCompiled().getValueTypeName()))),
          factory.newSimpleName(SegmentedReducer.GET_RENDEZVOUS),
          Collections.singletonList(
              factory.newFormalParameterDeclaration(
                  importer.toType(shuffle.getCompiled().getKeyTypeName()), argument)),
          statements);
    }
 private Type t(java.lang.reflect.Type type) {
   return importer.resolve(Models.toType(factory, type));
 }