Ejemplo n.º 1
0
  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);
  }
Ejemplo n.º 2
0
 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());
 }