private MethodDeclaration createSlotObjects() { SimpleName resultName = factory.newSimpleName("results"); List<Statement> statements = Lists.create(); statements.add( new TypeBuilder(factory, importer.toType(Writable.class)) .array(1) .newArray(getSlotCount()) .toLocalVariableDeclaration(importer.toType(Writable[].class), resultName)); for (ResolvedSlot slot : slots) { Expression object; if (slot.getSortProperties().isEmpty() && ParallelSortClientEmitter.legacy(environment) == false) { object = Models.toNullLiteral(factory); } else { DataClass slotClass = slot.getValueClass(); object = slotClass.createNewInstance(importer.toType(slotClass.getType())); } statements.add( new ExpressionBuilder(factory, resultName) .array(slot.getSlotNumber()) .assignFrom(object) .toStatement()); } statements.add(new ExpressionBuilder(factory, resultName).toReturnStatement()); return factory.newMethodDeclaration( null, new AttributeBuilder(factory) .annotation(importer.toType(Override.class)) .Protected() .toAttributes(), importer.toType(Writable[].class), factory.newSimpleName(SlotSorter.NAME_CREATE_SLOT_OBJECTS), Collections.<FormalParameterDeclaration>emptyList(), statements); }
private FieldDeclaration createProperty(Segment segment) { assert segment != null; String name = createPropertyName(segment); DataClass target = segment.getTarget(); return factory.newFieldDeclaration( new JavadocBuilder(factory) .text( "{0}#{1}が利用するモデル ({2})。", segment.getPort().getOwner().getDescription().getName(), segment.getPort().getDescription().getName(), segment.getPortId()) .toJavadoc(), new AttributeBuilder(factory).Public().toAttributes(), t(target.getType()), factory.newSimpleName(name), target.createNewInstance(t(target.getType()))); }
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); }