protected HoldingContainer generateEvalBody(
      ClassGenerator<?> g, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars) {

    // g.getBlock().directStatement(String.format("//---- start of eval portion of %s function.
    // ----//", functionName));

    JBlock sub = new JBlock(true, true);
    JBlock topSub = sub;
    HoldingContainer out = null;
    MajorType returnValueType = returnValue.type;

    // add outside null handling if it is defined.
    if (nullHandling == NullHandling.NULL_IF_NULL) {
      JExpression e = null;
      for (HoldingContainer v : inputVariables) {
        if (v.isOptional()) {
          if (e == null) {
            e = v.getIsSet();
          } else {
            e = e.mul(v.getIsSet());
          }
        }
      }

      if (e != null) {
        // if at least one expression must be checked, set up the conditional.
        returnValueType = returnValue.type.toBuilder().setMode(DataMode.OPTIONAL).build();
        out = g.declare(returnValueType);
        e = e.eq(JExpr.lit(0));
        JConditional jc = sub._if(e);
        jc._then().assign(out.getIsSet(), JExpr.lit(0));
        sub = jc._else();
      }
    }

    if (out == null) out = g.declare(returnValueType);

    // add the subblock after the out declaration.
    g.getEvalBlock().add(topSub);

    JVar internalOutput =
        sub.decl(
            JMod.FINAL,
            g.getHolderType(returnValueType),
            returnValue.name,
            JExpr._new(g.getHolderType(returnValueType)));
    addProtectedBlock(g, sub, body, inputVariables, workspaceJVars, false);
    if (sub != topSub)
      sub.assign(internalOutput.ref("isSet"), JExpr.lit(1)); // Assign null if NULL_IF_NULL mode
    sub.assign(out.getHolder(), internalOutput);
    if (sub != topSub)
      sub.assign(internalOutput.ref("isSet"), JExpr.lit(1)); // Assign null if NULL_IF_NULL mode
    return out;
  }
Ejemplo n.º 2
0
 @Override
 public JExpression testExpr(JCodeModel codeModel, JVar sexpVariable, JvmMethod.Argument formal) {
   JExpression vectorTest = super.testExpr(codeModel, sexpVariable, formal);
   if (formal.isAnnotatedWith(CoerceLanguageToString.class)) {
     return vectorTest
         .cor(sexpVariable._instanceof(codeModel.ref(FunctionCall.class)))
         .cor(sexpVariable._instanceof(codeModel.ref(Symbol.class)));
   } else {
     return vectorTest;
   }
 }
Ejemplo n.º 3
0
  @Override
  public void buildLayoutCall(JDefinedClass definedClass, JBlock block) {

    try {
      Map<InjectionNode, TypedExpression> expressionMap =
          injectionFragmentGenerator.buildFragment(block, definedClass, layoutHandlerInjectionNode);

      // LayoutHandlerDelegate.invokeLayout()
      JExpression layoutHandlerDelegate =
          expressionMap.get(layoutHandlerInjectionNode).getExpression();

      block.add(layoutHandlerDelegate.invoke(LayoutHandlerDelegate.INVOKE_LAYOUT_METHOD));

    } catch (ClassNotFoundException e) {
      logger.error("ClassNotFoundException while trying to generate LayoutHandler", e);
    } catch (JClassAlreadyExistsException e) {
      logger.error("JClassAlreadyExistsException while trying to generate LayoutHandler", e);
    }
  }
  @Override
  public JStatement buildWriter(JExpression extras, String name, JVar extraParam) {
    JInvocation wrappedParcel =
        generationUtil
            .ref(IntentFactoryStrategyGenerator.PARCELS_NAME)
            .staticInvoke(IntentFactoryStrategyGenerator.WRAP_METHOD)
            .arg(extraParam);

    return extras.invoke("putParcelable").arg(name).arg(wrappedParcel);
  }
  public TypedExpression buildVariable(
      InjectionBuilderContext injectionBuilderContext, InjectionNode injectionNode) {

    // build provider
    JDefinedClass providerClass = providerGenerator.generateProvider(injectionNode, true);
    JExpression provider = JExpr._new(providerClass).arg(injectionBuilderContext.getScopeVar());

    // build scope call
    // <T> T getScopedObject(Class<T> clazz, Provider<T> provider);
    TypedExpression contextScopeHolderExpression =
        injectionExpressionBuilder.buildVariable(injectionBuilderContext, this.contextScopeHolder);

    JExpression cast =
        invocationHelper.coerceType(ContextScopeHolder.class, contextScopeHolderExpression);
    JExpression scopeVar = cast.invoke(ContextScopeHolder.GET_SCOPE);

    JExpression expression =
        scopeVar.invoke(Scope.GET_SCOPED_OBJECT).arg(buildScopeKey(injectionNode)).arg(provider);

    return typedExpressionFactory.build(injectionNode.getASTType(), expression);
  }
Ejemplo n.º 6
0
 public JExpression wrapCondifiton(JExpression source) {
   return source.ne(JExpr._null());
 }
Ejemplo n.º 7
0
 @Override
 public JExpression unwrapCondifiton(JExpression source) {
   return source._instanceof(codeModel.ref(String.class));
 }