utils.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return false;
  29. }
  30. return true;
  31. }
  32. /// 获取type
  33. Set<String> getType(String type) {
  34. type.replaceAll("<", ",");
  35. type.replaceAll(">", ",");
  36. return (type
  37. .replaceAll("<", ",")
  38. .replaceAll(">", ",")
  39. .split(",")
  40. .map((e) => e.trim())
  41. .toList()
  42. ..removeWhere((element) => element.trim().isEmpty))
  43. .toSet();
  44. }