private MethodDeclaration createGetter(Segment segment) {
      assert segment != null;
      String methodName = Naming.getShuffleValueGetter(segment.getPortId());

      List<Statement> statements = new ArrayList<Statement>();
      statements.add(
          factory.newIfStatement(
              new ExpressionBuilder(factory, factory.newThis())
                  .field(SEGMENT_ID_FIELD_NAME)
                  .apply(InfixOperator.NOT_EQUALS, v(segment.getPortId()))
                  .toExpression(),
              new TypeBuilder(factory, t(AssertionError.class)).newObject().toThrowStatement(),
              null));

      statements.add(
          new ExpressionBuilder(factory, factory.newThis())
              .field(createPropertyName(segment))
              .toReturnStatement());

      return factory.newMethodDeclaration(
          new JavadocBuilder(factory)
              .text(
                  "{0}#{1}のモデルオブジェクトを返す。",
                  segment.getPort().getOwner().getDescription().getName(),
                  segment.getPort().getDescription().getName())
              .toJavadoc(),
          new AttributeBuilder(factory).Public().toAttributes(),
          t(segment.getTarget().getType()),
          factory.newSimpleName(methodName),
          Collections.<FormalParameterDeclaration>emptyList(),
          statements);
    }
Пример #2
0
 private TypeDeclaration createType() {
   SimpleName name = factory.newSimpleName(Naming.getCombineClass());
   importer.resolvePackageMember(name);
   List<TypeBodyDeclaration> members = Lists.create();
   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);
 }
 /**
  * 指定のシャッフル値から特定セグメントの値を設定する。
  *
  * @param segment 対象のセグメント
  * @param value 対象のシャッフル値
  * @return セグメントの値
  */
 protected Object getShuffleValue(Segment segment, SegmentedWritable value) {
   String name = Naming.getShuffleValueGetter(segment.getPortId());
   try {
     Method method = value.getClass().getMethod(name);
     return method.invoke(value);
   } catch (Exception e) {
     throw new AssertionError(e);
   }
 }
 /**
  * 指定のシャッフルキーに値を設定する。
  *
  * @param segment 対象のセグメント
  * @param key キー
  * @param toSet 設定する値
  */
 protected void setShuffleKey(Segment segment, SegmentedWritable key, Object toSet) {
   String name = Naming.getShuffleKeySetter(segment.getPortId());
   try {
     Method method = key.getClass().getMethod(name, toSet.getClass());
     method.invoke(key, toSet);
   } catch (Exception e) {
     throw new AssertionError(e);
   }
 }
 private TypeDeclaration createType() {
   SimpleName name = factory.newSimpleName(Naming.getReduceClass());
   importer.resolvePackageMember(name);
   return factory.newClassDeclaration(
       new JavadocBuilder(factory).text("エピローグ用のレデューサー。").toJavadoc(),
       new AttributeBuilder(factory).Public().toAttributes(),
       name,
       Collections.<TypeParameterDeclaration>emptyList(),
       importer.toType(SlotSorter.class),
       Collections.<Type>emptyList(),
       Arrays.asList(createSlotNames(), createSlotObjects()));
 }
 private TypeDeclaration createType() {
   SimpleName name = factory.newSimpleName(Naming.getShuffleValueClass());
   importer.resolvePackageMember(name);
   List<TypeBodyDeclaration> members = new ArrayList<TypeBodyDeclaration>();
   members.addAll(createSegmentDistinction());
   members.addAll(createProperties());
   members.addAll(createAccessors());
   members.addAll(createWritables());
   return factory.newClassDeclaration(
       createJavadoc(),
       new AttributeBuilder(factory)
           .annotation(t(SuppressWarnings.class), v("deprecation"))
           .Public()
           .Final()
           .toAttributes(),
       name,
       Collections.<TypeParameterDeclaration>emptyList(),
       null,
       Collections.singletonList(t(SegmentedWritable.class)),
       members);
 }
 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);
 }
Пример #8
0
    private MethodDeclaration createSetter(Segment segment) {
      assert segment != null;
      String methodName = Naming.getShuffleValueSetter(segment.getPortId());
      DataClass type = segment.getTarget();

      SimpleName argument = factory.newSimpleName("model"); // $NON-NLS-1$

      List<Statement> statements = Lists.create();
      statements.add(
          new ExpressionBuilder(factory, factory.newThis())
              .field(factory.newSimpleName(SEGMENT_ID_FIELD_NAME))
              .assignFrom(v(segment.getPortId()))
              .toStatement());
      statements.add(
          type.assign(
              new ExpressionBuilder(factory, factory.newThis())
                  .field(createPropertyName(segment))
                  .toExpression(),
              argument));

      return factory.newMethodDeclaration(
          new JavadocBuilder(factory)
              .text(
                  "Sets a data model object for " //$NON-NLS-1$
                      + "the successing operator input <code>{0}#{1}</code>.", //$NON-NLS-1$
                  segment.getPort().getOwner().getDescription().getName(),
                  segment.getPort().getDescription().getName())
              .param(argument)
              .text("the target data model object") // $NON-NLS-1$
              .toJavadoc(),
          new AttributeBuilder(factory).Public().toAttributes(),
          t(void.class),
          factory.newSimpleName(methodName),
          Collections.singletonList(
              factory.newFormalParameterDeclaration(t(type.getType()), argument)),
          statements);
    }
    private MethodDeclaration createSetter(Segment segment) {
      assert segment != null;
      String methodName = Naming.getShuffleValueSetter(segment.getPortId());
      DataClass type = segment.getTarget();

      SimpleName argument = factory.newSimpleName("model");

      List<Statement> statements = new ArrayList<Statement>();
      statements.add(
          new ExpressionBuilder(factory, factory.newThis())
              .field(factory.newSimpleName(SEGMENT_ID_FIELD_NAME))
              .assignFrom(v(segment.getPortId()))
              .toStatement());
      statements.add(
          type.assign(
              new ExpressionBuilder(factory, factory.newThis())
                  .field(createPropertyName(segment))
                  .toExpression(),
              argument));

      return factory.newMethodDeclaration(
          new JavadocBuilder(factory)
              .text(
                  "{0}#{1}で使用するモデルオブジェクトを設定する。",
                  segment.getPort().getOwner().getDescription().getName(),
                  segment.getPort().getDescription().getName())
              .param(argument)
              .text("設定するモデルオブジェクト")
              .toJavadoc(),
          new AttributeBuilder(factory).Public().toAttributes(),
          t(void.class),
          factory.newSimpleName(methodName),
          Collections.singletonList(
              factory.newFormalParameterDeclaration(t(type.getType()), argument)),
          statements);
    }