Example #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);
 }
Example #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 void emit() throws IOException {
   ClassDeclaration decl =
       f.newClassDeclaration(
           new JavadocBuilder(f)
               .text("TSVファイルなどのレコードを表すファイルを入力として<code>{0}</code>を読み出す", model.getName())
               .toJavadoc(),
           new AttributeBuilder(f).Public().Final().toAttributes(),
           context.getTypeName(),
           Collections.<TypeParameterDeclaration>emptyList(),
           null,
           Collections.singletonList(
               f.newParameterizedType(
                   context.resolve(ModelInput.class), context.resolve(model.getSymbol()))),
           createMembers());
   context.emit(decl);
 }
 private TypeDeclaration createType() {
   SimpleName name = factory.newSimpleName(Naming.getShuffleGroupingComparatorClass());
   importer.resolvePackageMember(name);
   List<TypeBodyDeclaration> members = new ArrayList<TypeBodyDeclaration>();
   members.add(createCompareBytes());
   members.add(createCompareObjects());
   members.add(ShuffleEmiterUtil.createCompareInts(factory));
   members.add(ShuffleEmiterUtil.createPortToElement(factory, model));
   return factory.newClassDeclaration(
       createJavadoc(),
       new AttributeBuilder(factory)
           .annotation(t(SuppressWarnings.class), v("rawtypes"))
           .Public()
           .toAttributes(),
       name,
       Collections.<TypeParameterDeclaration>emptyList(),
       null,
       Collections.singletonList(
           importer.resolve(
               factory.newParameterizedType(
                   t(RawComparator.class), Collections.singletonList(keyType)))),
       members);
 }