private void generateCount() { count = cls().method(JMod.PUBLIC, cm.INT, "count"); count().body().decl(cm.INT, "rc", lit(amqpFields.size())); for ( int i = amqpFields.size(); i > 0; i-- ) { JConditional _if = count().body()._if(amqpFields.get(i - 1).attribute.eq(_null())); _if._then().assign(ref("rc"), ref("rc").minus(lit(1))); _if._else()._return(ref("rc")); } count().body()._return(ref("rc")); }
private void generateComparisons(final ClassGenerator<?> g, final VectorAccessible batch) throws SchemaChangeException { g.setMappingSet(mainMapping); for (final Ordering od : config.getOrderings()) { // first, we rewrite the evaluation stack for each side of the comparison. final LogicalExpression expr = context.getClassProducer().materialize(od.getExpr(), batch); g.setMappingSet(leftMapping); final HoldingContainer left = g.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE); g.setMappingSet(rightMapping); final HoldingContainer right = g.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE); g.setMappingSet(mainMapping); // next we wrap the two comparison sides and add the expression block for the comparison. final LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getClassProducer()); final HoldingContainer out = g.addExpr(fh, ClassGenerator.BlockCreateMode.MERGE); final JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); if (od.getDirection() == Direction.ASCENDING) { jc._then()._return(out.getValue()); } else { jc._then()._return(out.getValue().minus()); } } g.getEvalBlock()._return(JExpr.lit(0)); }
static void generateComparisons(ClassGenerator<?> g, VectorAccessible batch, Iterable<Ordering> orderings, ClassProducer producer) throws SchemaChangeException { final MappingSet mainMappingSet = new MappingSet( (String) null, null, ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP); final MappingSet leftMappingSet = new MappingSet("leftIndex", null, ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP); final MappingSet rightMappingSet = new MappingSet("rightIndex", null, ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP); g.setMappingSet(mainMappingSet); for (Ordering od : orderings) { // first, we rewrite the evaluation stack for each side of the comparison. final LogicalExpression expr = producer.materialize(od.getExpr(), batch); g.setMappingSet(leftMappingSet); HoldingContainer left = g.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE); g.setMappingSet(rightMappingSet); HoldingContainer right = g.addExpr(expr, ClassGenerator.BlockCreateMode.MERGE); g.setMappingSet(mainMappingSet); // next we wrap the two comparison sides and add the expression block for the comparison. LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, producer); HoldingContainer out = g.addExpr(fh, ClassGenerator.BlockCreateMode.MERGE); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); if (od.getDirection() == Direction.ASCENDING) { jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus()); } g.rotateBlock(); } g.rotateBlock(); g.getEvalBlock()._return(JExpr.lit(0)); }
source.ref( "length" ).minus( JExpr.lit( 1 ) ) );
private void generateComparisons(final ClassGenerator<?> g, final VectorAccessible batch) throws SchemaChangeException { g.setMappingSet(MAIN_MAPPING); for (final Ordering od : popConfig.getOrderings()) { // first, we rewrite the evaluation stack for each side of the comparison. final ErrorCollector collector = new ErrorCollectorImpl(); final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector,context.getFunctionRegistry()); if (collector.hasErrors()) { throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString()); } g.setMappingSet(LEFT_MAPPING); final HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE); g.setMappingSet(RIGHT_MAPPING); final HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE); g.setMappingSet(MAIN_MAPPING); // next we wrap the two comparison sides and add the expression block for the comparison. final LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFunctionRegistry()); final HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE); final JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); if (od.getDirection() == Direction.ASCENDING) { jc._then()._return(out.getValue()); } else { jc._then()._return(out.getValue().minus()); } } g.getEvalBlock()._return(JExpr.lit(0)); }
jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus());
private void generateComparisons(ClassGenerator<?> g, VectorAccessible batch) throws SchemaChangeException { g.setMappingSet(MAIN_MAPPING); for (Ordering od : popConfig.getOrderings()) { // first, we rewrite the evaluation stack for each side of the comparison. ErrorCollector collector = new ErrorCollectorImpl(); final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector,context.getFunctionRegistry()); if (collector.hasErrors()) { throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString()); } g.setMappingSet(LEFT_MAPPING); HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE); g.setMappingSet(RIGHT_MAPPING); HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE); g.setMappingSet(MAIN_MAPPING); // next we wrap the two comparison sides and add the expression block for the comparison. LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); if (od.getDirection() == Direction.ASCENDING) { jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus()); } g.rotateBlock(); } g.rotateBlock(); g.getEvalBlock()._return(JExpr.lit(0)); }
private void fillInReadMethod() { if ( isComposite() ) { read().body().decl(cm.LONG, "count", cm.ref(generator.getMarshaller() + ".DescribedTypeSupport").staticInvoke("readListHeader").arg(ref("in"))); } Log.info("Filling in read method for %s", type.getName()); for ( Attribute attribute : amqpFields ) { Log.info("%s %s", attribute.type, attribute.attribute.name()); if ( isComposite() ) { read().body().assign(ref("count"), ref("count").minus(lit(1))); JBlock ifBody = read().body()._if(ref("count").gte(lit(0)))._then(); addFieldRead(attribute, ifBody); } else { addFieldRead(attribute, read().body()); } } if ( isComposite() ) { for ( Attribute attribute : amqpFields ) { if ( attribute.required ) { read().body()._if(attribute.attribute.eq(_null()))._then()._throw(_new(cm.ref(RuntimeException.class)).arg("No value specified for mandatory attribute " + attribute.attribute.name())); } } } }
jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus());
jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus());
jc._then()._return(out.getValue()); } else { jc._then()._return(out.getValue().minus());
jc._then()._return(out.getValue()); } else { jc._then()._return(out.getValue().minus());
jc._then()._return(out.getValue()); } else { jc._then()._return(out.getValue().minus());
final JForLoop forEachItem = arrayNotNull._then()._for(); final JVar i = forEachItem.init( fieldOutline.parent().parent().getCodeModel().INT, "i", a.ref( "length" ).minus( JExpr.lit( 1 ) ) );
jc._then()._return(out.getValue()); }else{ jc._then()._return(out.getValue().minus());
private void fillInSizeMethod() { size().body()._return(invoke("sizeOfConstructor").plus(invoke("sizeOfBody"))); sizeOfConstructor().body()._return(ref("CONSTRUCTOR").invoke("size")); JMethod sizeOfFields = cls().method(JMod.PRIVATE, cm.LONG, "sizeOfFields"); sizeOfFields.body().decl(cm.LONG, "fieldSize", lit(0L)); if ( isComposite() ) { sizeOfFields.body().decl(cm.INT, "count", _this().invoke(count)); } for ( Attribute attribute : amqpFields ) { if ( isComposite() ) { sizeOfFields.body().assign(ref("count"), ref("count").minus(lit(1))); JBlock ifBody = sizeOfFields.body()._if(ref("count").gte(lit(0)))._then(); addFieldSize(attribute, ifBody); } else { addFieldSize(attribute, sizeOfFields.body()); } } sizeOfFields.body()._return(ref("fieldSize")); if ( isComposite() ) { sizeOfBody().body()._return(cm.ref(generator.getMarshaller() + ".DescribedTypeSupport").staticInvoke("fullSizeOfList").arg(_this().invoke("sizeOfFields")).arg(_this().invoke("count"))); } else { sizeOfBody().body()._return(_this().invoke("sizeOfFields")); } }
private void fillInWriteMethod() { writeConstructor().body().block().invoke(ref("CONSTRUCTOR"), "write").arg(ref("out")); writeConstructor().body()._return(cast(cm.BYTE, lit(0))); write().body().invoke("writeConstructor").arg(ref("out")); write().body().invoke("writeBody").arg(cast(cm.BYTE, lit((byte) 0))).arg(ref("out")); if ( isComposite() ) { writeBody().body().decl(cm.LONG, "fieldSize", _this().invoke("sizeOfFields")); writeBody().body().decl(cm.INT, "count", _this().invoke("count")); writeBody().body().staticInvoke(cm.ref(generator.getMarshaller() + ".DescribedTypeSupport"), "writeListHeader").arg(ref("fieldSize")).arg(ref("count")).arg(ref("out")); } for ( Attribute attribute : amqpFields ) { if ( isComposite() ) { writeBody().body().assign(ref("count"), ref("count").minus(lit(1))); JBlock ifBody = writeBody().body()._if(ref("count").gte(lit(0)))._then(); addFieldWrite(attribute, ifBody); } else { addFieldWrite(attribute, writeBody().body()); } } }