Java Code Examples for com.sun.codemodel.JVar#ref()

The following examples show how to use com.sun.codemodel.JVar#ref() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassGenerator.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Adds local variable declaration based on given name and type.
 *
 * @param t major type
 * @param name variable name
 * @param includeNewInstance whether to create new instance
 * @return holder instance
 */
public HoldingContainer declare(MajorType t, String name, boolean includeNewInstance) {
  JType holderType = getHolderType(t);
  JVar var;
  if (includeNewInstance) {
    var = getEvalBlock().decl(holderType, name + index, JExpr._new(holderType));
  } else {
    var = getEvalBlock().decl(holderType, name + index);
  }
  JFieldRef outputSet = null;
  if (t.getMode() == DataMode.OPTIONAL) {
    outputSet = var.ref("isSet");
  }
  index++;
  return new HoldingContainer(t, var, var.ref("value"), outputSet);
}
 
Example 2
Source File: EvaluationVisitor.java    From Bats with Apache License 2.0 5 votes vote down vote up
private HoldingContainer getHoldingContainer(ClassGenerator<?> generator,
                                             MajorType majorType,
                                             Function<DrillBuf, ? extends ValueHolder> function) {
  JType holderType = generator.getHolderType(majorType);
  Pair<Integer, JVar> depthVar = generator.declareClassConstField("const", holderType, function);
  JFieldRef outputSet = null;
  JVar var = depthVar.getValue();
  if (majorType.getMode() == TypeProtos.DataMode.OPTIONAL) {
    outputSet = var.ref("isSet");
  }
  return new HoldingContainer(majorType, var, var.ref("value"), outputSet);
}
 
Example 3
Source File: EvaluationVisitor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public HoldingContainer visitQuotedStringConstant(QuotedString e, ClassGenerator<?> generator)
    throws RuntimeException {
  CompleteType completeType = CompleteType.VARCHAR;
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = CodeModelArrowHelper.getHolderType(completeType, generator.getModel());
  JVar var = generator.declareClassField("string", holderType);
  JExpression stringLiteral = JExpr.lit(e.value);
  JExpression buffer = JExpr.direct("context").invoke("getManagedBuffer");
  setup.assign(var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getNullableVarCharHolder").arg(buffer).arg(stringLiteral));
  return new HoldingContainer((completeType), var, var.ref("value"), var.ref("isSet"));
}
 
Example 4
Source File: EvaluationVisitor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public HoldingContainer visitIntervalDayConstant(IntervalDayExpression e, ClassGenerator<?> generator)
    throws RuntimeException {
  CompleteType completeType = CompleteType.INTERVAL_DAY_SECONDS;
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = CodeModelArrowHelper.getHolderType(completeType, generator.getModel());
  JVar var = generator.declareClassField("intervalday", holderType);
  JExpression dayLiteral = JExpr.lit(e.getIntervalDay());
  JExpression millisLiteral = JExpr.lit(e.getIntervalMillis());
  setup.assign(
      var,
      generator.getModel().ref(ValueHolderHelper.class).staticInvoke("getNullableIntervalDayHolder").arg(dayLiteral)
          .arg(millisLiteral));
  return new HoldingContainer(completeType, var, var.ref("value"), var.ref("isSet"));
}
 
Example 5
Source File: EvaluationVisitor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public HoldingContainer visitDecimalConstant(DecimalExpression e, ClassGenerator<?> generator)
  throws RuntimeException {
  CompleteType completeType = CompleteType.fromDecimalPrecisionScale(e.getPrecision(), e.getScale());
  JBlock setup = generator.getBlock(BlockType.SETUP);
  JType holderType = CodeModelArrowHelper.getHolderType(completeType, generator.getModel());
  JVar var = generator.declareClassField("dec38", holderType);
  JExpression decimal = JExpr.lit(e.getDecimal().toString());
  JExpression buffer = JExpr.direct("context").invoke("getManagedBuffer");
  setup.assign(var, generator.getModel().ref(ValueHolderHelper.class).staticInvoke
    ("getNullableDecimalHolder").arg(buffer).arg(decimal));
  return new HoldingContainer(completeType, var, var.ref("value"), var.ref("isSet"));
}
 
Example 6
Source File: ClassGenerator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public HoldingContainer declare(CompleteType t, boolean includeNewInstance) {
  JType holderType = CodeModelArrowHelper.getHolderType(t, model);
  JVar var;
  if (includeNewInstance) {
    var = getEvalBlock().decl(holderType, "out" + index, JExpr._new(holderType));
  } else {
    var = getEvalBlock().decl(holderType, "out" + index);
  }
  index++;
  return new HoldingContainer(t, var, var.ref("value"), var.ref("isSet"));
}