getTypeStr static method

String getTypeStr(
  1. Property property, {
  2. bool wantAddPre = false,
  3. bool showNullTag = true,
})

cover dart type to java type wantAddPre if true, it when add pre keywords, like: public static final .....

Implementation

static String getTypeStr(
  Property property, {
  bool wantAddPre = false,
  bool showNullTag = true,
}) {
  String typeStr;
  var baseType = TypeUtils.javaMap[property.type];
  if (baseType != null) {
    //base
    typeStr = baseType;
  } else {
    //other not base type
    typeStr = property.type.split(".").last;
  }
  if (showNullTag && typeStr != "void") {
    typeStr = (property.canBeNull ? " @Nullable " : " @NotNull ") + typeStr;
  }
  if (property.subType.isNotEmpty) {
    typeStr += "<";
    property.subType.forEach((element) {
      typeStr += getTypeStr(element, showNullTag: false) + ", ";
    });
    if (typeStr.endsWith(", ")) {
      //remove ", " ,because java method arg can't end with ", "
      typeStr = typeStr.substring(0, typeStr.length - 2);
    }
    typeStr += ">";
  }
  if (wantAddPre) {
    if (property.isConst) {
      typeStr = " final " + typeStr;
    }
    if (property.isStatic) {
      typeStr = " static " + typeStr;
    }
    if (property.isPrivate) {
      typeStr = " private " + typeStr;
    } else {
      typeStr = " public " + typeStr;
    }
  }
  return typeStr;
}