Exemple #1
0
  private void genConstructor(
      Refs r,
      JDefinedClass clazz,
      Collection<Ref> refs,
      Map<Ref, JFieldVar> fieldVarMap,
      JFieldVar holderListener,
      Map<Listener.Type, ListenerType> listenerTypeMap) {
    // private MyLayoutViewModel(View view) {
    JMethod constructor = clazz.constructor(PUBLIC);
    JVar viewVar = constructor.param(r.viewClass, "view");
    JBlock body = constructor.body();

    // super(view);
    body.invoke("super").arg(viewVar);

    // myLinearLayout = (LinearLayout) view.findViewById(R.id.my_linear_layout);
    // myTextView = (TextView) myLinearLayout.findViewById(R.id.my_text_view);
    genInitFields(r, fieldVarMap, viewVar, refs, body);

    // myButton.setOnClickListener((view) -> { if (_holderListener != null)
    // _holderListener.onMyButtonClick(myButton); });
    genListeners(r, fieldVarMap, holderListener, refs, body, listenerTypeMap);

    JDocComment doc = constructor.javadoc();
    doc.append(
        "Constructs a new {@link me.tatarka.holdr.Holdr} for {@link "
            + r.packageName
            + ".R.layout#"
            + r.layoutName
            + "}.");
    doc.addParam(viewVar).append("The root view to search for the holdr's views.");
  }
 private static void addSetterDeclaration(
     Names names, JDefinedClass paramType, JDefinedClass setterReturnType) {
   JMethod method = setterReturnType.method(JMod.NONE, setterReturnType, names.getSetterName());
   method.param(paramType, names.getParamName());
   JDocComment javadoc = method.javadoc();
   javadoc.append(names.getJavadoc());
 }
  public static void addGetterSetterDeclaration(
      Names names, JClass type, JDefinedClass jDefinedClass) {
    addGetterDeclaration(names, type, jDefinedClass);

    JMethod method = jDefinedClass.method(JMod.NONE, jDefinedClass, names.getSetterName());
    method.param(type, names.getParamName());

    JDocComment javadoc = method.javadoc();
    javadoc.append(names.getJavadoc());
  }
 public static void addGetterDeclaration(Names names, Class<?> type, JDefinedClass jDefinedClass) {
   JMethod method = jDefinedClass.method(JMod.NONE, type, names.getGetterName());
   JDocComment javadoc = method.javadoc();
   javadoc.append(names.getJavadoc());
 }