Skip to content

Commit 1d0f34b

Browse files
committed
closer
1 parent e89175a commit 1d0f34b

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

functions_framework_builder/lib/builder.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/// details, and `build.yaml` for how this builder is configured by default.
2323
library;
2424

25-
import 'package:analyzer/dart/element/element.dart';
25+
import 'package:analyzer/dart/element/element2.dart';
2626
import 'package:build/build.dart';
2727
import 'package:dart_style/dart_style.dart';
2828
import 'package:functions_framework/functions_framework.dart';
@@ -53,7 +53,7 @@ class _FunctionsFrameworkBuilder implements Builder {
5353

5454
for (var annotatedElement in _fromLibrary(libraryElement)) {
5555
final element = annotatedElement.element;
56-
if (element is! FunctionElement || element.isPrivate) {
56+
if (element is! TopLevelFunctionElement || element.isPrivate) {
5757
throw InvalidGenerationSourceError(
5858
'Only top-level, public functions are supported.',
5959
element: element,
@@ -63,7 +63,7 @@ class _FunctionsFrameworkBuilder implements Builder {
6363
final targetReader = annotatedElement.annotation.read('target');
6464

6565
final targetName = targetReader.isNull
66-
? element.name
66+
? element.name3!
6767
: targetReader.stringValue;
6868

6969
if (entries.containsKey(targetName)) {
@@ -138,13 +138,14 @@ ${cases.join('\n')}
138138
}
139139
}
140140

141-
Iterable<AnnotatedElement> _fromLibrary(LibraryElement library) sync* {
141+
Iterable<AnnotatedElement> _fromLibrary(LibraryElement2 library) sync* {
142142
// Merging the `topLevelElements` picks up private elements and fields.
143143
// While neither is supported, it allows us to provide helpful errors if devs
144144
// are using the annotations incorrectly.
145-
final mergedElements = {
146-
...library.topLevelElements,
147-
...library.exportNamespace.definedNames.values,
145+
final mergedElements = <Element2>{
146+
...library.topLevelFunctions,
147+
...library.topLevelVariables,
148+
...library.exportNamespace.definedNames2.values,
148149
};
149150

150151
for (var element in mergedElements) {

functions_framework_builder/lib/src/function_type_validator.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import 'package:analyzer/dart/element/element.dart';
15+
import 'package:analyzer/dart/element/element2.dart';
1616
import 'package:build/build.dart';
1717
import 'package:source_gen/source_gen.dart';
1818

@@ -25,9 +25,9 @@ class FunctionTypeValidator {
2525
FunctionTypeValidator._(this._types);
2626

2727
FactoryData validate(
28-
LibraryElement library,
28+
LibraryElement2 library,
2929
String targetName,
30-
FunctionElement element,
30+
TopLevelFunctionElement element,
3131
) {
3232
for (var type in _types) {
3333
final reference = type.createReference(library, targetName, element);

functions_framework_builder/lib/src/generic_function_type.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import 'package:analyzer/dart/element/element.dart';
16+
import 'package:analyzer/dart/element/element2.dart';
1617
import 'package:analyzer/dart/element/nullability_suffix.dart';
1718
import 'package:build/build.dart';
1819
import 'package:source_gen/source_gen.dart';
@@ -72,15 +73,15 @@ class GenericFunctionType implements SupportedFunctionType {
7273

7374
@override
7475
FactoryData? createReference(
75-
LibraryElement library,
76+
LibraryElement2 library,
7677
String targetName,
77-
FunctionElement element,
78+
TopLevelFunctionElement element,
7879
) {
79-
if (element.parameters.isEmpty) {
80+
if (element.formalParameters.isEmpty) {
8081
return null;
8182
}
8283

83-
final firstParamType = element.parameters.first.type;
84+
final firstParamType = element.formalParameters.first.type;
8485

8586
final paramInfo = validJsonParamType(firstParamType);
8687

@@ -106,8 +107,8 @@ class GenericFunctionType implements SupportedFunctionType {
106107
// TODO: add a test for this!
107108
throw InvalidGenerationSourceError(
108109
'The type `${paramInfo.paramType!.element.name}` is not exposed '
109-
'by the function library `${library.source.uri}` so it cannot '
110-
'be used.',
110+
'by the function library `${library.firstFragment.source.uri}` so '
111+
'it cannot be used.',
111112
);
112113
}
113114
}
@@ -117,7 +118,7 @@ class GenericFunctionType implements SupportedFunctionType {
117118
returnKind == JsonReturnKind.isVoid,
118119
paramInfo,
119120
escapeDartString(targetName),
120-
'$functionsLibraryPrefix.${element.name}',
121+
'$functionsLibraryPrefix.${element.name3}',
121122
);
122123
}
123124
return null;

functions_framework_builder/lib/src/supported_function_type.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import 'package:analyzer/dart/element/element.dart';
16+
import 'package:analyzer/dart/element/element2.dart';
1617
import 'package:analyzer/dart/element/nullability_suffix.dart';
1718
import 'package:analyzer/dart/element/type.dart';
1819
import 'package:build/build.dart';
@@ -64,15 +65,15 @@ class SupportedFunctionType {
6465
}
6566

6667
FactoryData? createReference(
67-
LibraryElement library,
68+
LibraryElement2 library,
6869
String targetName,
69-
FunctionElement element,
70+
TopLevelFunctionElement element,
7071
) {
71-
if (element.library.typeSystem.isSubtypeOf(element.type, _type)) {
72+
if (element.library2.typeSystem.isSubtypeOf(element.type, _type)) {
7273
return _TrivialFactoryData(
7374
escapeDartString(targetName),
7475
'$_constructor('
75-
'$functionsLibraryPrefix.${element.name},)',
76+
'$functionsLibraryPrefix.${element.name3},)',
7677
);
7778
}
7879
return null;

functions_framework_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment:
88
sdk: ^3.8.0
99

1010
dependencies:
11-
analyzer: '>=6.9.0 <8.0.0'
11+
analyzer: ^7.5.0
1212
build: ^3.0.0
1313
build_config: ^1.0.0
1414
collection: ^1.17.0

integration_test/test/cloud_behavior_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void main() {
5858
cloudLoggingMiddleware(_projectId),
5959
),
6060
zoneSpecification: ZoneSpecification(
61-
print: (_, __, ___, line) => lines.add(line),
61+
print: (_, _, _, line) => lines.add(line),
6262
),
6363
);
6464

0 commit comments

Comments
 (0)