private void getIndex(ClassGenerator<StreamingAggregator> g) {
    switch (incoming.getSchema().getSelectionVectorMode()) {
      case FOUR_BYTE:
        {
          JVar var = g.declareClassField("sv4_", g.getModel()._ref(SelectionVector4.class));
          g.getBlock("setupInterior")
              .assign(var, JExpr.direct("incoming").invoke("getSelectionVector4"));
          g.getBlock("getVectorIndex")._return(var.invoke("get").arg(JExpr.direct("recordIndex")));
          ;
          return;
        }
      case NONE:
        {
          g.getBlock("getVectorIndex")._return(JExpr.direct("recordIndex"));
          ;
          return;
        }
      case TWO_BYTE:
        {
          JVar var = g.declareClassField("sv2_", g.getModel()._ref(SelectionVector2.class));
          g.getBlock("setupInterior")
              .assign(var, JExpr.direct("incoming").invoke("getSelectionVector2"));
          g.getBlock("getVectorIndex")
              ._return(var.invoke("getIndex").arg(JExpr.direct("recordIndex")));
          ;
          return;
        }

      default:
        throw new IllegalStateException();
    }
  }
 private void addCreateFromParcel(JDefinedClass jclass, JDefinedClass creatorClass) {
   JMethod createFromParcel = creatorClass.method(JMod.PUBLIC, jclass, "createFromParcel");
   JVar in = createFromParcel.param(Parcel.class, "in");
   JVar instance = createFromParcel.body().decl(jclass, "instance", JExpr._new(jclass));
   suppressWarnings(createFromParcel, "unchecked");
   for (JFieldVar f : jclass.fields().values()) {
     if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
       continue;
     }
     if (f.type().erasure().name().equals("List")) {
       createFromParcel
           .body()
           .invoke(in, "readList")
           .arg(instance.ref(f))
           .arg(JExpr.direct(getGenericType(f.type()) + ".class.getClassLoader()"));
     } else {
       createFromParcel
           .body()
           .assign(
               instance.ref(f),
               JExpr.cast(
                   f.type(),
                   in.invoke("readValue")
                       .arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()"))));
     }
   }
   createFromParcel.body()._return(instance);
 }
  private void addParameter(
      final String name,
      final AbstractParam parameter,
      final Class<? extends Annotation> annotationClass,
      final JMethod method,
      final JDocComment javadoc)
      throws Exception {
    final String argumentName = Names.buildVariableName(name);

    final JVar argumentVariable =
        method.param(types.buildParameterType(parameter, argumentName), argumentName);

    argumentVariable.annotate(annotationClass).param(DEFAULT_ANNOTATION_PARAMETER, name);

    if (parameter.getDefaultValue() != null) {
      argumentVariable
          .annotate(DefaultValue.class)
          .param(DEFAULT_ANNOTATION_PARAMETER, parameter.getDefaultValue());
    }

    if (context.getConfiguration().isUseJsr303Annotations()) {
      addJsr303Annotations(parameter, argumentVariable);
    }

    addParameterJavaDoc(parameter, argumentVariable.name(), javadoc);
  }
  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;
  }
Exemple #5
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;
   }
 }
  private void addActionInOnHandleIntent(
      EIntentServiceHolder holder,
      ExecutableElement executableElement,
      String methodName,
      JFieldVar actionKeyField) {
    // If action match, call the method
    JInvocation actionCondition =
        actionKeyField.invoke("equals").arg(holder.getOnHandleIntentIntentAction());
    JBlock callActionBlock = holder.getOnHandleIntentBody()._if(actionCondition)._then();
    JInvocation callActionInvocation = JExpr._super().invoke(methodName);

    // For each method params, we get back value from extras and put it
    // in super calls
    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    if (methodParameters.size() > 0) {
      // Extras
      JVar extras = callActionBlock.decl(classes().BUNDLE, "extras");
      extras.init(holder.getOnHandleIntentIntent().invoke("getExtras"));
      JBlock extrasNotNullBlock = callActionBlock._if(extras.ne(_null()))._then();

      // Extras params
      for (VariableElement param : methodParameters) {
        String paramName = param.getSimpleName().toString();
        String extraParamName = paramName + "Extra";
        JFieldVar paramVar = getStaticExtraField(holder, paramName);
        JClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType(), holder);
        BundleHelper bundleHelper = new BundleHelper(annotationHelper, param);

        JExpression getExtraExpression =
            JExpr.invoke(extras, bundleHelper.getMethodNameToRestore()).arg(paramVar);
        if (bundleHelper.restoreCallNeedCastStatement()) {
          getExtraExpression = JExpr.cast(extraParamClass, getExtraExpression);

          if (bundleHelper.restoreCallNeedsSuppressWarning()) {
            JMethod onHandleIntentMethod = holder.getOnHandleIntentMethod();
            if (onHandleIntentMethod.annotations().size() == 0) {
              onHandleIntentMethod.annotate(SuppressWarnings.class).param("value", "unchecked");
            }
          }
        }

        JVar extraField =
            extrasNotNullBlock.decl(extraParamClass, extraParamName, getExtraExpression);
        callActionInvocation.arg(extraField);
      }
      extrasNotNullBlock.add(callActionInvocation);
    } else {
      callActionBlock.add(callActionInvocation);
    }
    callActionBlock._return();
  }
 public void run(Set<ClassOutline> sorted, JDefinedClass transformer) {
   for (ClassOutline classOutline : sorted) {
     // skip over abstract classes
     if (!classOutline.target.isAbstract()) {
       // add the accept method to the bean
       JDefinedClass beanImpl = classOutline.implClass;
       JMethod acceptMethod = beanImpl.method(JMod.PUBLIC, Object.class, "accept");
       JTypeVar genericType = acceptMethod.generify("T");
       acceptMethod.type(genericType);
       JVar vizParam = acceptMethod.param(transformer.narrow(genericType), "aTransformer");
       JBlock block = acceptMethod.body();
       block._return(vizParam.invoke("transform").arg(JExpr._this()));
     }
   }
 }
  public void build() {
    declareMethod();

    ExceptionWrapper mainTryBlock = new ExceptionWrapper(codeModel, method.body(), context);
    for (Integer arity : primitive.getArity()) {
      JInvocation invocation = invoke("doApply").arg(context).arg(environment);

      for (int i = 0; i < arity; ++i) {
        invocation.arg(args.component(lit(i)));
      }
      mainTryBlock
          .body()
          ._if(JExpr.direct("args.length").eq(JExpr.lit(arity)))
          ._then()
          ._return(invocation);
    }

    mainTryBlock.catchEvalExceptions();
    mainTryBlock.catchRuntimeExceptions();
    mainTryBlock.catchExceptions();

    method
        .body()
        ._throw(
            JExpr._new(codeModel.ref(EvalException.class))
                .arg(lit(primitive.getName() + ": max arity is " + primitive.getMaxArity())));
  }
  private JDefinedClass addBuilderCls(Feed feed, JDefinedClass cls)
      throws JClassAlreadyExistsException, ClassNotFoundException {
    JDefinedClass bldrCls = cls._class(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, "Builder");
    JVar paramBuilder =
        bldrCls
            .field(JMod.PRIVATE | JMod.FINAL, immutableMapBldr, "params")
            .init(immutableMap.staticInvoke("builder"));

    for (Filter filter : feed.getFilters().getFilter()) {
      if (!Boolean.TRUE.equals(filter.isDeprecated())) {
        addWithersFor(filter, bldrCls, paramBuilder);
      }
    }

    if (feed.getMixins() != null && feed.getMixins().getMixin() != null) {
      JDefinedClass mixinEnum = getMixinEnum(feed);
      for (Mixin mixin : feed.getMixins().getMixin()) {
        String mixinName = mixin.getName().toUpperCase().replace(' ', '_');
        JEnumConstant mixinCnst = mixinEnum.enumConstant(mixinName);
        mixinCnst.arg(JExpr.lit(mixin.getName().replace(' ', '+')));
      }
      JFieldVar field = cls.field(privateStaticFinal, String.class, "MIXIN");
      field.init(JExpr.lit("mixin"));
      JMethod iterWither = bldrCls.method(JMod.PUBLIC, bldrCls, "withMixins");
      JVar param = iterWither.param(iterable(mixinEnum), "mixins");
      JBlock mthdBody = iterWither.body();
      mthdBody.add(
          paramBuilder
              .invoke("put")
              .arg(field)
              .arg(immutableList.staticInvoke("copyOf").arg(param)));
      mthdBody._return(JExpr._this());
      JMethod varArgWither = bldrCls.method(JMod.PUBLIC, bldrCls, "withMixins");
      param = varArgWither.varParam(mixinEnum, "mixins");
      varArgWither
          .body()
          ._return(JExpr.invoke(iterWither).arg(immutableList.staticInvoke("copyOf").arg(param)));
    }

    JMethod bldMthd = bldrCls.method(JMod.PUBLIC, cls, "build");
    bldMthd.body()._return(JExpr._new(cls).arg(paramBuilder.invoke("build")));

    // TODO: add sorts
    return bldrCls;
  }
  private void addEquals(JDefinedClass jclass) {
    Map<String, JFieldVar> fields = jclass.fields();
    if (fields.isEmpty()) {
      return;
    }

    JMethod equals = jclass.method(JMod.PUBLIC, boolean.class, "equals");
    JVar otherObject = equals.param(Object.class, "other");

    Class<?> equalsBuilder =
        ruleFactory.getGenerationConfig().isUseCommonsLang3()
            ? org.apache.commons.lang3.builder.EqualsBuilder.class
            : org.apache.commons.lang.builder.EqualsBuilder.class;

    JBlock body = equals.body();

    body._if(otherObject.eq(JExpr._this()))._then()._return(JExpr.TRUE);
    body._if(otherObject._instanceof(jclass).eq(JExpr.FALSE))._then()._return(JExpr.FALSE);

    JVar rhsVar = body.decl(jclass, "rhs").init(JExpr.cast(jclass, otherObject));
    JClass equalsBuilderClass = jclass.owner().ref(equalsBuilder);
    JInvocation equalsBuilderInvocation = JExpr._new(equalsBuilderClass);

    if (!jclass._extends().name().equals("Object")) {
      equalsBuilderInvocation =
          equalsBuilderInvocation
              .invoke("appendSuper")
              .arg(JExpr._super().invoke("equals").arg(otherObject));
    }

    for (JFieldVar fieldVar : fields.values()) {
      equalsBuilderInvocation =
          equalsBuilderInvocation.invoke("append").arg(fieldVar).arg(rhsVar.ref(fieldVar.name()));
    }

    JInvocation reflectionEquals =
        jclass.owner().ref(equalsBuilder).staticInvoke("reflectionEquals");
    reflectionEquals.arg(JExpr._this());
    reflectionEquals.arg(otherObject);

    body._return(equalsBuilderInvocation.invoke("isEquals"));

    equals.annotate(Override.class);
  }
  private static void processToString(JDefinedClass packetClass, JCodeModel codeModel) {
    JClass string = codeModel.ref(String.class);
    JClass stringBuilder = codeModel.ref(StringBuilder.class);
    JClass arrays = codeModel.ref(Arrays.class);

    JMethod toStringMeth = packetClass.method(JMod.PUBLIC, String.class, "toString");
    toStringMeth.annotate(Override.class);
    JBlock body = toStringMeth.body();

    JVar stringBuilderVar = body.decl(stringBuilder, "sb");
    stringBuilderVar =
        stringBuilderVar.init(JExpr._new(stringBuilder).arg(packetClass.name() + "["));

    JInvocation appendChain = null;

    for (JFieldVar fieldVar : packetClass.fields().values()) {
      if (appendChain != null) {
        // a comma is needed
        appendChain = appendChain.invoke("append").arg("," + fieldVar.name() + "=");
      } else {
        appendChain = stringBuilderVar.invoke("append").arg(fieldVar.name() + "=");
      }

      // now add the field to the toString output
      JExpression expression =
          fieldVar.type().isArray()
              ? arrays.staticInvoke("toString").arg(JExpr._this().ref(fieldVar.name()))
              : fieldVar.type().isReference()
                  ? JExpr._this().ref(fieldVar.name()).invoke("toString")
                  : JExpr._this().ref(fieldVar.name());

      appendChain = appendChain.invoke("append").arg(expression);
    }

    if (appendChain != null) {
      appendChain = appendChain.invoke("append").arg("]");
    } else {
      appendChain = stringBuilderVar.invoke("append").arg("]");
    }

    body.add(appendChain);
    body._return(stringBuilderVar.invoke("toString"));
  }
 private void addWither(
     Filter filter, JDefinedClass bldrCls, JVar paramBuilder, JFieldVar field, JClass paramType)
     throws JClassAlreadyExistsException {
   JMethod method = createWitherMethod(filter, bldrCls);
   if (filter.getTitle() != null) {
     method.javadoc().add(String.format("<p>%s</p>", filter.getTitle()));
   }
   JVar param = addParam(filter, method, paramType);
   JBlock mthdBody = method.body();
   boolean needsNullCheck = true;
   if (filter.getMinValue() != null) {
     mthdBody.add(precs.staticInvoke("checkNotNull").arg(param));
     needsNullCheck = false;
     int min = filter.getMinValue().intValue();
     mthdBody.add(
         precs
             .staticInvoke("checkArgument")
             .arg(JExpr.lit(min).lte(param))
             .arg(JExpr.lit(param.name() + ": %s < " + min))
             .arg(param));
   }
   if (filter.getMaxValue() != null) {
     if (needsNullCheck) {
       mthdBody.add(precs.staticInvoke("checkNotNull").arg(param));
       needsNullCheck = false;
     }
     int max = filter.getMaxValue().intValue();
     mthdBody.add(
         precs
             .staticInvoke("checkArgument")
             .arg(JExpr.lit(max).gte(param))
             .arg(JExpr.lit(param.name() + ": %s > " + max))
             .arg(param));
   }
   JInvocation putIntoMap = paramBuilder.invoke("put").arg(field);
   if (needsNullCheck) {
     putIntoMap.arg(precs.staticInvoke("checkNotNull").arg(param));
   } else {
     putIntoMap.arg(param);
   }
   mthdBody.add(putIntoMap);
   mthdBody._return(JExpr._this());
 }
  private void addJsr303Annotations(final AbstractParam parameter, final JVar argumentVariable) {
    if (isNotBlank(parameter.getPattern())) {
      LOGGER.info(
          "Pattern constraint ignored for parameter: "
              + ToStringBuilder.reflectionToString(parameter, SHORT_PREFIX_STYLE));
    }

    final Integer minLength = parameter.getMinLength();
    final Integer maxLength = parameter.getMaxLength();
    if ((minLength != null) || (maxLength != null)) {
      final JAnnotationUse sizeAnnotation = argumentVariable.annotate(Size.class);

      if (minLength != null) {
        sizeAnnotation.param("min", minLength);
      }

      if (maxLength != null) {
        sizeAnnotation.param("max", maxLength);
      }
    }

    final BigDecimal minimum =
        parameter.getMinimum() == null ? null : BigDecimal.valueOf(parameter.getMinimum());
    if (minimum != null) {
      addMinMaxConstraint(parameter, "minimum", Min.class, minimum, argumentVariable);
    }

    final BigDecimal maximum =
        parameter.getMaximum() == null ? null : BigDecimal.valueOf(parameter.getMaximum());

    if (maximum != null) {
      addMinMaxConstraint(parameter, "maximum", Max.class, maximum, argumentVariable);
    }

    if (parameter.isRequired()) {
      argumentVariable.annotate(NotNull.class);
    }
  }
Exemple #14
0
 private void genInitFields(
     Refs r, Map<Ref, JFieldVar> fieldVarMap, JVar viewVar, Collection<Ref> refs, JBlock body) {
   for (Ref ref : refs) {
     JFieldVar fieldVar = fieldVarMap.get(ref);
     JFieldRef idVar = (ref.isAndroidId ? r.androidRClass : r.rClass).staticRef("id").ref(ref.id);
     if (ref instanceof View) {
       JClass viewType = r.ref(((View) ref).type);
       body.assign(fieldVar, cast(viewType, viewVar.invoke("findViewById").arg(idVar)));
     } else if (ref instanceof Include) {
       JClass includeType = r.ref(getClassName(((Include) ref).layout));
       body.assign(fieldVar, _new(includeType).arg(viewVar));
     }
   }
 }
 private JMethod addIterableWither(
     Filter filter, JDefinedClass bldrCls, JVar paramBuilder, JFieldVar field, JClass paramType)
     throws JClassAlreadyExistsException {
   JMethod method = createWitherMethod(filter, bldrCls);
   if (filter.getTitle() != null) {
     method.javadoc().add(String.format("<p>%s</p>", filter.getTitle()));
   }
   JVar param = addParam(filter, method, iterable(paramType));
   JBlock mthdBody = method.body();
   mthdBody.add(
       paramBuilder.invoke("put").arg(field).arg(immutableList.staticInvoke("copyOf").arg(param)));
   mthdBody._return(JExpr._this());
   return method;
 }
 private void addMinMaxConstraint(
     final AbstractParam parameter,
     final String name,
     final Class<? extends Annotation> clazz,
     final BigDecimal value,
     final JVar argumentVariable) {
   try {
     final long boundary = value.longValueExact();
     argumentVariable.annotate(clazz).param(DEFAULT_ANNOTATION_PARAMETER, boundary);
   } catch (final ArithmeticException ae) {
     LOGGER.info(
         "Non integer "
             + name
             + " constraint ignored for parameter: "
             + ToStringBuilder.reflectionToString(parameter, SHORT_PREFIX_STYLE));
   }
 }
  private void convertArguments(JBlock parent, VarArgParser parser) {
    int index = 0;
    for (VarArgParser.PositionalArg posArg : parser.getPositionalArguments()) {
      parent.assign(
          posArg.getVariable(), convert(posArg.getFormal(), args.component(lit(index++))));
    }

    JForLoop forLoop = parent._for();
    JVar loopCounter =
        forLoop.init(codeModel._ref(int.class), "i", lit(parser.getPositionalArguments().size()));
    forLoop.test(loopCounter.lt(JExpr.direct("args.length")));
    forLoop.update(loopCounter.incr());

    forLoop
        .body()
        .invoke(parser.getVarArgBuilder(), "add")
        .arg(argNames.component(loopCounter))
        .arg(args.component(loopCounter));
  }
  public List<JVar> readIntent(
      List<? extends VariableElement> parameters,
      JBlock body,
      JVar intentParam,
      BaseAnnotationHandler handler)
      throws Exception {
    List<JVar> vars = new ArrayList<JVar>();

    for (VariableElement variableElement : parameters) {
      String type = variableElement.asType().toString();
      LOGGER.debug("var type:{} {}", variableElement.getSimpleName().toString(), type);
      JVar var = null;
      if (type.equals("java.lang.String")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getStringExtra")
                    .arg(variableElement.getSimpleName().toString()));
      } else if (type.equals("int")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getIntExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(0)));

      } else if (type.equals("float")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getFloatExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(0)));
      }
      if (type.equals("double")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getDoubleExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(0)));
      }
      if (type.equals("char")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getCharExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit((char) 0)));
      } else if (type.equals("java.util.ArrayList<java.lang.Integer>")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getIntegerArrayListExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("java.util.ArrayList<java.lang.String>")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getStringArrayListExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("float[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getFloatArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("double[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getDoubleArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("char[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getCharArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("java.lang.String[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getStringArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("boolean[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getBooleanArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("boolean")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getBooleanExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(false)));

      } else if (type.equals("int[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getIntArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("long[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getLongArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("long")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getLongExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(0)));

      } else if (type.equals("byte[]")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getByteArrayExtra")
                    .arg(variableElement.getSimpleName().toString()));

      } else if (type.equals("byte")) {
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                intentParam
                    .invoke("getByteExtra")
                    .arg(variableElement.getSimpleName().toString())
                    .arg(JExpr.lit(0)));

      } else if (type.endsWith("[]")) {
        if (EntityHandler.isInterface(
            type.substring(0, type.length() - 2), "android.os.Parcelable")) {
          var =
              body.decl(
                  handler.refClass(type),
                  variableElement.getSimpleName().toString(),
                  JExpr.cast(
                      handler.refClass(type),
                      intentParam
                          .invoke("getParcelableArrayExtra")
                          .arg(variableElement.getSimpleName().toString())));
        } else {
          var =
              body.decl(
                  handler.refClass(type),
                  variableElement.getSimpleName().toString(),
                  JExpr.cast(
                      handler.refClass(type),
                      intentParam
                          .invoke("getSerializableExtra")
                          .arg(variableElement.getSimpleName().toString())));
        }
        // JConditional
        // parcel=body._if(JExpr._new(handler.refClass(type.substring(0,type.length()-2)))._instanceof(handler.refClass("android.os.Parcelable")));
        // parcel._then().assign(var,JExpr.cast(handler.refClass(type),
        //
        // intentParam.invoke("getParcelableArrayExtra").arg(variableElement.getSimpleName().toString())));
        // JConditional serializable=
        // parcel._else()._if(JExpr._new(handler.refClass(type.substring(0,type.length()-2)))._instanceof(handler.refClass("java.io.Serializable")));
        // serializable._then().assign(var,
        // JExpr.cast(handler.refClass(variableElement.asType().toString()),
        //
        // intentParam.invoke("getSerializableExtra").arg(variableElement.getSimpleName().toString())));

      } else if (type.startsWith("java.util.ArrayList")) {

        String clz = type.substring(type.indexOf('<') + 1, type.lastIndexOf('>'));
        var =
            body.decl(
                handler.codeModel().parseType(variableElement.asType().toString()),
                variableElement.getSimpleName().toString(),
                JExpr.cast(
                    handler.refClass("java.util.ArrayList").narrow(handler.refClass(clz)),
                    intentParam
                        .invoke("getSerializableExtra")
                        .arg(variableElement.getSimpleName().toString())));
      }
      if (var == null) {
        if (EntityHandler.isInterface(type, "android.os.Parcelable")) {
          var =
              body.decl(
                  handler.refClass(type),
                  variableElement.getSimpleName().toString(),
                  JExpr.cast(
                      handler.refClass(type),
                      intentParam
                          .invoke("getParcelableExtra")
                          .arg(variableElement.getSimpleName().toString())));
        } else {
          var =
              body.decl(
                  handler.refClass(type),
                  variableElement.getSimpleName().toString(),
                  JExpr.cast(
                      handler.refClass(type),
                      intentParam
                          .invoke("getSerializableExtra")
                          .arg(variableElement.getSimpleName().toString())));
        }
        // var=body.decl(handler.refClass(type),variableElement.getSimpleName().toString(),JExpr._new(handler.refClass(type)));
        // JConditional parcel=body._if(var._instanceof(handler.refClass("android.os.Parcelable")));
        // parcel._then().assign(var,JExpr.cast(handler.refClass(variableElement.asType().toString()),
        //
        // intentParam.invoke("getParcelableExtra").arg(variableElement.getSimpleName().toString())));

        // JConditional serializable=
        // parcel._else()._if(var._instanceof(handler.refClass("java.io.Serializable")));
        // serializable._then().assign(var,
        // JExpr.cast(handler.refClass(variableElement.asType().toString()),
        //
        // intentParam.invoke("getSerializableExtra").arg(variableElement.getSimpleName().toString())));
      }
      vars.add(var);
    }
    return vars;
  }
  private void createResponseBuilderInResourceMethodReturnType(
      final JDefinedClass responseClass,
      final int statusCode,
      final Response response,
      final MimeType responseMimeType)
      throws Exception {
    final String responseBuilderMethodName =
        Names.buildResponseMethodName(statusCode, responseMimeType);

    final JMethod responseBuilderMethod =
        responseClass.method(PUBLIC + STATIC, responseClass, responseBuilderMethodName);

    final JDocComment javadoc = responseBuilderMethod.javadoc();

    if (isNotBlank(response.getDescription())) {
      javadoc.add(response.getDescription());
    }

    if ((responseMimeType != null) && (isNotBlank(responseMimeType.getExample()))) {
      javadoc.add(EXAMPLE_PREFIX + responseMimeType.getExample());
    }

    JInvocation builderArgument =
        types
            .getGeneratorClass(javax.ws.rs.core.Response.class)
            .staticInvoke("status")
            .arg(JExpr.lit(statusCode));

    if (responseMimeType != null) {
      builderArgument =
          builderArgument
              .invoke("header")
              .arg(HttpHeaders.CONTENT_TYPE)
              .arg(responseMimeType.getType());
    }

    final StringBuilder freeFormHeadersDescription = new StringBuilder();

    for (final Entry<String, Header> namedHeaderParameter : response.getHeaders().entrySet()) {
      final String headerName = namedHeaderParameter.getKey();
      final Header header = namedHeaderParameter.getValue();

      if (headerName.contains(RESPONSE_HEADER_WILDCARD_SYMBOL)) {
        appendParameterJavadocDescription(header, freeFormHeadersDescription);
        continue;
      }

      final String argumentName = Names.buildVariableName(headerName);

      builderArgument =
          builderArgument.invoke("header").arg(headerName).arg(JExpr.ref(argumentName));

      addParameterJavaDoc(header, argumentName, javadoc);

      responseBuilderMethod.param(types.buildParameterType(header, argumentName), argumentName);
    }

    final JBlock responseBuilderMethodBody = responseBuilderMethod.body();

    final JVar builderVariable =
        responseBuilderMethodBody.decl(
            types.getGeneratorType(ResponseBuilder.class), "responseBuilder", builderArgument);

    if (freeFormHeadersDescription.length() > 0) {
      // generate a Map<String, List<Object>> argument for {?} headers
      final JClass listOfObjectsClass = types.getGeneratorClass(List.class).narrow(Object.class);
      final JClass headersArgument =
          types
              .getGeneratorClass(Map.class)
              .narrow(types.getGeneratorClass(String.class), listOfObjectsClass);

      builderArgument =
          responseBuilderMethodBody
              .invoke("headers")
              .arg(JExpr.ref(MULTIPLE_RESPONSE_HEADERS_ARGUMENT_NAME))
              .arg(builderVariable);

      final JVar param =
          responseBuilderMethod.param(headersArgument, MULTIPLE_RESPONSE_HEADERS_ARGUMENT_NAME);

      javadoc.addParam(param).add(freeFormHeadersDescription.toString());
    }

    if (responseMimeType != null) {
      responseBuilderMethodBody
          .invoke(builderVariable, "entity")
          .arg(JExpr.ref(GENERIC_PAYLOAD_ARGUMENT_NAME));
      responseBuilderMethod.param(
          types.getResponseEntityClass(responseMimeType), GENERIC_PAYLOAD_ARGUMENT_NAME);
      javadoc
          .addParam(GENERIC_PAYLOAD_ARGUMENT_NAME)
          .add(defaultString(responseMimeType.getExample()));
    }

    responseBuilderMethodBody._return(
        JExpr._new(responseClass).arg(builderVariable.invoke("build")));
  }