コード例 #1
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);
 }
コード例 #2
0
    private MethodDeclaration createGetRendezvous() {
      Map<FlowElement, SimpleName> fragments = Maps.create();
      for (Map.Entry<Fragment, SimpleName> entry : rendezvousNames.entrySet()) {
        fragments.put(entry.getKey().getFactors().get(0).getElement(), entry.getValue());
      }

      List<Statement> cases = Lists.create();
      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 = Lists.create();
      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);
    }
コード例 #3
0
ファイル: GeneratorUtil.java プロジェクト: ashigeru/asakusafw
 /**
  * Returns the type model for the specified type.
  *
  * @param type the target type
  * @return the type model
  * @throws IllegalArgumentException if the parameter is {@code null}
  */
 public final Type t(TypeElement type) {
   Precondition.checkMustNotBeNull(type, "type"); // $NON-NLS-1$
   DeclaredType t = environment.getTypeUtils().getDeclaredType(type);
   return importer.resolve(new Jsr269(factory).convert(t));
 }
コード例 #4
0
ファイル: GeneratorUtil.java プロジェクト: ashigeru/asakusafw
 /**
  * Returns the type model for the specified type.
  *
  * @param type the target type
  * @return the type model
  * @throws IllegalArgumentException if the parameter is {@code null}
  */
 public final Type t(TypeMirror type) {
   Precondition.checkMustNotBeNull(type, "type"); // $NON-NLS-1$
   return importer.resolve(new Jsr269(factory).convert(type));
 }
コード例 #5
0
 private Type t(java.lang.reflect.Type type) {
   return importer.resolve(Models.toType(factory, type));
 }