From b77886e2795b0e1cfac0f05a623a538a0fd5b920 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 1 Jun 2023 11:16:04 -0700 Subject: [PATCH 1/4] [pigeon] Require analyzer 5.13.0, prepare for NamedType refactoring. --- packages/pigeon/lib/pigeon_lib.dart | 30 ++++++++++++++--------------- packages/pigeon/pubspec.yaml | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 1ef6e8a900b..4eb3dfe0bac 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1004,10 +1004,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final dart_ast.NamedType? namedType = getFirstChildOfType(parameter); if (namedType != null) { - // TODO(stuartmorgan): Replace `name` when adopting the next version of - // analyzer. - // ignore: deprecated_member_use - final String argTypeBaseName = namedType.name.name; + final String argTypeBaseName = namedType.qualifiedName; final bool isNullable = namedType.question != null; final List argTypeArguments = typeAnnotationsToTypeArguments(namedType.typeArguments); @@ -1089,10 +1086,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { Method( name: node.name.lexeme, returnType: TypeDeclaration( - // TODO(stuartmorgan): Replace `name` when adopting the next - // version of analyzer. - // ignore: deprecated_member_use - baseName: returnType.name.name, + baseName: returnType.qualifiedName, typeArguments: typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), @@ -1141,10 +1135,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { for (final Object x in typeArguments.childEntities) { if (x is dart_ast.NamedType) { result.add(TypeDeclaration( - // TODO(stuartmorgan): Replace `name` when adopting the next - // version of analyzer. - // ignore: deprecated_member_use - baseName: x.name.name, + baseName: x.qualifiedName, isNullable: x.question != null, typeArguments: typeAnnotationsToTypeArguments(x.typeArguments))); } @@ -1174,10 +1165,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; _currentClass!.fields.add(NamedType( type: TypeDeclaration( - // TODO(stuartmorgan): Replace `name` when adopting the next - // version of analyzer. - // ignore: deprecated_member_use - baseName: type.name.name, + baseName: type.qualifiedName, isNullable: type.question != null, typeArguments: typeAnnotationsToTypeArguments(typeArguments), ), @@ -1546,3 +1534,13 @@ ${_argParser.usage}'''; } } } + +extension on dart_ast.NamedType { + String get qualifiedName { + final dart_ast.ImportPrefixReference? importPrefix = this.importPrefix; + if (importPrefix != null) { + return '${importPrefix.name.lexeme}.${name2.lexeme}'; + } + return name2.lexeme; + } +} diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 26b6465413c..374fae40cda 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -8,7 +8,7 @@ environment: sdk: ">=2.18.0 <4.0.0" dependencies: - analyzer: "^5.2.0" + analyzer: "^5.13.0" args: ^2.1.0 collection: ^1.15.0 meta: ^1.7.0 From 064f82ed4514e62dc59c9934260f4932a6b62132 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 5 Jun 2023 09:53:31 -0700 Subject: [PATCH 2/4] Require at least SDK 2.19.0 --- packages/pigeon/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 374fae40cda..192581e5d8f 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -5,7 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 10.0.0 # This must match the version in lib/generator_tools.dart environment: - sdk: ">=2.18.0 <4.0.0" + sdk: ">=2.19.0 <4.0.0" dependencies: analyzer: "^5.13.0" From e6f048f94d2cc6bbc93521c164b7f8cc910e995c Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 5 Jun 2023 11:07:06 -0700 Subject: [PATCH 3/4] Avoid using extensions. --- packages/pigeon/lib/pigeon_lib.dart | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 4eb3dfe0bac..1dc99e4916d 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1004,7 +1004,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final dart_ast.NamedType? namedType = getFirstChildOfType(parameter); if (namedType != null) { - final String argTypeBaseName = namedType.qualifiedName; + final String argTypeBaseName = _getNamedTypeQualifiedName(namedType); final bool isNullable = namedType.question != null; final List argTypeArguments = typeAnnotationsToTypeArguments(namedType.typeArguments); @@ -1086,7 +1086,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { Method( name: node.name.lexeme, returnType: TypeDeclaration( - baseName: returnType.qualifiedName, + baseName: _getNamedTypeQualifiedName(returnType), typeArguments: typeAnnotationsToTypeArguments(returnType.typeArguments), isNullable: returnType.question != null), @@ -1135,7 +1135,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { for (final Object x in typeArguments.childEntities) { if (x is dart_ast.NamedType) { result.add(TypeDeclaration( - baseName: x.qualifiedName, + baseName:_getNamedTypeQualifiedName(x), isNullable: x.question != null, typeArguments: typeAnnotationsToTypeArguments(x.typeArguments))); } @@ -1165,7 +1165,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { final dart_ast.TypeArgumentList? typeArguments = type.typeArguments; _currentClass!.fields.add(NamedType( type: TypeDeclaration( - baseName: type.qualifiedName, + baseName: _getNamedTypeQualifiedName(type), isNullable: type.question != null, typeArguments: typeAnnotationsToTypeArguments(typeArguments), ), @@ -1211,6 +1211,14 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { node.visitChildren(this); return null; } + + static String _getNamedTypeQualifiedName(dart_ast.NamedType node) { + final dart_ast.ImportPrefixReference? importPrefix = node.importPrefix; + if (importPrefix != null) { + return '${importPrefix.name.lexeme}.${node.name2.lexeme}'; + } + return node.name2.lexeme; + } } int? _calculateLineNumberNullable(String contents, int? offset) { @@ -1534,13 +1542,3 @@ ${_argParser.usage}'''; } } } - -extension on dart_ast.NamedType { - String get qualifiedName { - final dart_ast.ImportPrefixReference? importPrefix = this.importPrefix; - if (importPrefix != null) { - return '${importPrefix.name.lexeme}.${name2.lexeme}'; - } - return name2.lexeme; - } -} From 6924b9cbce1eeb23bf30b1c86594062ba807db2d Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 6 Jun 2023 12:04:01 -0700 Subject: [PATCH 4/4] Update version, format (not quite complete). --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/pigeon_lib.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index fe7793e8b31..e48f0eec1bc 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.0.1 + +* Requires `analyzer 5.13.0` and replaces use of deprecated APIs. + ## 10.0.0 * [swift] Avoids using `Any` to represent `Optional` in Swift. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 7508c566d77..f7b0fc0a9f7 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '10.0.0'; +const String pigeonVersion = '10.0.1'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 1dc99e4916d..09ea9133adc 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -1135,7 +1135,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { for (final Object x in typeArguments.childEntities) { if (x is dart_ast.NamedType) { result.add(TypeDeclaration( - baseName:_getNamedTypeQualifiedName(x), + baseName: _getNamedTypeQualifiedName(x), isNullable: x.question != null, typeArguments: typeAnnotationsToTypeArguments(x.typeArguments))); } diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 192581e5d8f..a4284b0b498 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 10.0.0 # This must match the version in lib/generator_tools.dart +version: 10.0.1 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.19.0 <4.0.0"