Example #1
0
 private MethodDeclaration createCleanup() {
   List<Statement> statements = new ArrayList<Statement>();
   for (SimpleName name : shuffleNames.values()) {
     statements.add(
         new ExpressionBuilder(factory, factory.newThis())
             .field(name)
             .assignFrom(Models.toNullLiteral(factory))
             .toStatement());
   }
   for (SimpleName name : rendezvousNames.values()) {
     statements.add(
         new ExpressionBuilder(factory, factory.newThis())
             .field(name)
             .assignFrom(Models.toNullLiteral(factory))
             .toStatement());
   }
   return factory.newMethodDeclaration(
       null,
       new AttributeBuilder(factory).annotation(t(Override.class)).Public().toAttributes(),
       Collections.<TypeParameterDeclaration>emptyList(),
       t(void.class),
       factory.newSimpleName("cleanup"),
       Collections.singletonList(
           factory.newFormalParameterDeclaration(
               factory.newNamedType(factory.newSimpleName("Context")), context)),
       0,
       Arrays.asList(t(IOException.class), t(InterruptedException.class)),
       factory.newBlock(statements));
 }
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);
    }
Example #3
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);
 }
 private List<Statement> createConstructorBody() {
   List<Statement> results = new ArrayList<Statement>();
   results.add(
       f.newIfStatement(
           new ExpressionBuilder(f, createParserFieldName())
               .apply(InfixOperator.EQUALS, Models.toNullLiteral(f))
               .toExpression(),
           f.newBlock(
               new TypeBuilder(f, context.resolve(IllegalArgumentException.class))
                   .newObject(Models.toLiteral(f, createParserFieldName().getToken()))
                   .toThrowStatement())));
   results.add(
       new ExpressionBuilder(f, f.newThis(null))
           .field(createParserFieldName())
           .assignFrom(createParserFieldName())
           .toStatement());
   return results;
 }
 @Override
 protected List<? extends TypeBodyDeclaration> override(Context context) {
   ImplementationBuilder builder = new ImplementationBuilder(context);
   ModelFactory f = context.environment.getFactory();
   builder.addStatement(
       new TypeBuilder(f, context.importer.toType(UnsupportedOperationException.class))
           .newObject(Models.toLiteral(f, "単純集計演算子は組み込みの方法で処理されます"))
           .toThrowStatement());
   return builder.toImplementation();
 }
    private List<Statement> createReaderBody() {
      List<Statement> results = new ArrayList<Statement>();

      results.add(
          f.newIfStatement(
              new ExpressionBuilder(f, createParserFieldName())
                  .method("next")
                  .apply(InfixOperator.EQUALS, Models.toLiteral(f, false))
                  .toExpression(),
              f.newBlock(
                  new ExpressionBuilder(f, Models.toLiteral(f, false)).toReturnStatement())));

      for (PropertyDeclaration property : model.getDeclaredProperties()) {
        results.add(createReaderStatement(property));
      }
      results.add(createEndRecordStatement());
      results.add(f.newReturnStatement(Models.toLiteral(f, true)));
      return results;
    }
 /**
  * Initializes the test.
  *
  * @throws Exception if some errors were occurred
  */
 @Before
 public void setUp() throws Exception {
   packager = new VolatilePackager();
   FlowCompilerConfiguration config = new FlowCompilerConfiguration();
   config.setBatchId("batch");
   config.setFlowId("flow");
   config.setFactory(Models.getModelFactory());
   config.setProcessors(new SpiFlowElementProcessorRepository());
   config.setExternals(new SpiExternalIoDescriptionProcessorRepository());
   config.setDataClasses(new SpiDataClassRepository());
   config.setGraphRewriters(new SpiFlowGraphRewriterRepository());
   config.setPackager(packager);
   config.setRootPackageName("com.example");
   config.setRootLocation(Location.fromPath("com/example", '/'));
   config.setServiceClassLoader(getClass().getClassLoader());
   config.setOptions(new FlowCompilerOptions());
   environment = new FlowCompilingEnvironment(config);
   environment.bless();
 }
 private Expression v(Object value) {
   return Models.toLiteral(factory, value);
 }
 private Type t(java.lang.reflect.Type type) {
   return importer.resolve(Models.toType(factory, type));
 }