コード例 #1
0
    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
 /**
  * 指定のシャッフル値から特定セグメントの値を設定する。
  *
  * @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);
   }
 }