property static method

String property(
  1. GenClassBean genBean,
  2. List<Property> properties
)

create property

Implementation

static String property(GenClassBean genBean, List<Property> properties) {
  String propertyStr = "";

  if (genBean.classInfo.type == ClassType.enumType) {
    properties
        .where((element) =>
            element.name != "index" &&
            element.name != "_name" &&
            element.name != "values")
        .forEach((element) {
      propertyStr += "\t" + element.name.toUpperCase() + ",\n";
    });
    return propertyStr;
  }
  properties.forEach((property) {
    String typeStr = getTypeStr(property, wantAddPre: true);
    String name = property.name;
    String defaultValue = property.defaultValue1;
    // if (genBean.classInfo.type == 1) {
    //   //java interface can't have any default value.
    //   defaultValue = "";
    // }
    if (defaultValue == "null") {
      //todo no way if the String == "null"; don't do it
      defaultValue = "";
    }
    if (defaultValue.isNotEmpty) {
      if (property.type == "dart.core.int" &&
          !defaultValue.endsWith("L") &&
          !defaultValue.endsWith("l")) {
        //if type is int, the java type is Long, so your should add 'L' to the default
        defaultValue += "L";
      } else if (property.type == "dart.core.String") {
        //string should wrap with ""
        defaultValue = "\"$defaultValue\"";
      } else if (property.type == "dart.typed_data.Uint8List" ||
          property.type == "dart.typed_data.Int32List" ||
          property.type == "dart.typed_data.Int64List" ||
          property.type == "dart.typed_data.Float64List") {
        defaultValue = " new " +
            (TypeUtils.javaMap[property.type] ?? "") +
            "{ " +
            defaultValue.replaceAll('[', '').replaceAll(']', '') +
            " }";
      } else if (property.type == "dart.core.List") {
        defaultValue = "new ArrayList<>()";
      } else if (property.type == "dart.core.Map") {
        defaultValue = "new HashMap<>()";
      }
      defaultValue = " = " + defaultValue;
    }
    propertyStr += "\t$typeStr $name $defaultValue;\n";
  });
  return propertyStr;
}