| 1 | import "package:analyzer/dart/ast/ast.dart"; |
| 2 | |
| 3 | bool isCakeWalletWidget(ConstructorName constructorName, String className) { |
| 4 | final element = constructorName.type.element; |
| 5 | if (element == null || element.name != className) { |
| 6 | return false; |
| 7 | } |
| 8 | |
| 9 | final libraryUri = element.library?.uri; |
| 10 | if (libraryUri == null || libraryUri.scheme != "package") { |
| 11 | return false; |
| 12 | } |
| 13 | |
| 14 | final segments = libraryUri.pathSegments; |
| 15 | return segments.isNotEmpty && segments.first == "cake_wallet"; |
| 16 | } |
| 17 | |
| 18 | NamedArgument? namedArgument(ArgumentList argumentList, String name) { |
| 19 | for (final argument in argumentList.arguments) { |
| 20 | if (argument is NamedArgument && argument.name.lexeme == name) { |
| 21 | return argument; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | Expression? namedArgumentExpression(ArgumentList argumentList, String name) => |
| 29 | namedArgument(argumentList, name)?.argumentExpression; |
| 30 | |
| 31 | // passed null or "" |
| 32 | // does NOT work if a runtime expression evaluates to an empty string or null |
| 33 | bool isMissingOrEmptyText(Expression? expression) { |
| 34 | if (expression == null || expression is NullLiteral) { |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | return expression is StringLiteral && (expression.stringValue?.isEmpty ?? false); |
| 39 | } |