utils.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:build/build.dart';
  2. String toCamelCase(String s) {
  3. if (s.length < 2) {
  4. return s.toLowerCase();
  5. }
  6. return s[0].toLowerCase() + s.substring(1);
  7. }
  8. String getImportStr(BuildStep buildStep) {
  9. var importStr = "";
  10. if (buildStep.inputId.path.contains('lib/')) {
  11. importStr =
  12. "package:${buildStep.inputId.package}/${buildStep.inputId.path.replaceFirst('lib/', '')}";
  13. } else {
  14. importStr = "${buildStep.inputId.path}";
  15. }
  16. return importStr;
  17. }
  18. bool isSpeciousType(String type) {
  19. if (type == "int" ||
  20. type == "double" ||
  21. type == "num" ||
  22. type == "Runes" ||
  23. type == "String" ||
  24. type == "bool" ||
  25. type == "dynamic" ||
  26. type == "List" ||
  27. type == "Map" ||
  28. type == "dynamic") {
  29. return false;
  30. }
  31. return true;
  32. }
  33. /// 获取type
  34. Set<String> getType(String type) {
  35. type.replaceAll("<", ",");
  36. type.replaceAll(">", ",");
  37. return (type
  38. .replaceAll("<", ",")
  39. .replaceAll(">", ",")
  40. .split(",")
  41. .map((e) => e.trim())
  42. .toList()
  43. ..removeWhere((element) => element.trim().isEmpty))
  44. .toSet();
  45. }