Skip to content

Commit

Permalink
Update Analyzer to 4.1.0 (#659) (#662)
Browse files Browse the repository at this point in the history
* Update to analyzer 4.1.0 and update to Flutter 3

* Fix tests where type from string were returned as function

* Fix remaining tests

* Use dart formatting

* Update MacOS action to use x64 Flutter version

* Update analyzer version of example project

* Simplify getting enum index

* Use reflection to access name and index

* Update flutter action version of example ci

* Make analyzer version less strict
  • Loading branch information
ThomasMiddel authored Jun 17, 2022
1 parent f0ea5a5 commit ba521e3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 49 deletions.
21 changes: 14 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -168,7 +168,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -298,6 +298,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -325,7 +332,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -379,7 +386,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sqflite:
dependency: transitive
description:
Expand Down Expand Up @@ -463,7 +470,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.9"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -491,7 +498,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
watcher:
dependency: transitive
description:
Expand All @@ -514,5 +521,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.15.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.10.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
sdk: flutter

dev_dependencies:
analyzer: ^3.1.0
analyzer: ^4.1.0
build_runner: ^2.1.7
floor_generator:
path: ../floor_generator/
Expand Down
21 changes: 14 additions & 7 deletions floor/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -168,7 +168,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -291,6 +291,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
meta:
dependency: "direct main"
description:
Expand Down Expand Up @@ -325,7 +332,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -386,7 +393,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sqflite:
dependency: "direct main"
description:
Expand Down Expand Up @@ -470,7 +477,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.9"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -498,7 +505,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
watcher:
dependency: transitive
description:
Expand All @@ -521,5 +528,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.10.0"
16 changes: 4 additions & 12 deletions floor_generator/lib/misc/extension/dart_object_extension.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:collection/collection.dart';
import 'package:floor_annotation/floor_annotation.dart';

extension DartObjectExtension on DartObject {
Expand All @@ -9,10 +8,8 @@ extension DartObjectExtension on DartObject {
String? toEnumValueString() {
final interfaceType = type as InterfaceType;
final enumName = interfaceType.getDisplayString(withNullability: false);
final enumValue = interfaceType.element.fields
.where((element) => element.isEnumConstant)
.map((fieldElement) => fieldElement.name)
.singleWhereOrNull((valueName) => getField(valueName) != null);
final enumValue = getField('_name')?.toStringValue();

if (enumValue == null) {
return null;
} else {
Expand All @@ -23,12 +20,7 @@ extension DartObjectExtension on DartObject {
/// get the ForeignKeyAction this enum represents,
/// or the result of `null` if the enum did not contain a valid value
ForeignKeyAction? toForeignKeyAction() {
final enumValueString = toEnumValueString();
if (enumValueString == null) {
return null;
} else {
return ForeignKeyAction.values.singleWhereOrNull(
(foreignKeyAction) => foreignKeyAction.toString() == enumValueString);
}
final enumIndex = getField('index')?.toIntValue();
return enumIndex != null ? ForeignKeyAction.values[enumIndex] : null;
}
}
27 changes: 10 additions & 17 deletions floor_generator/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "25.0.0"
version: "40.0.0"
analyzer:
dependency: "direct main"
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "4.1.0"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -42,7 +42,7 @@ packages:
name: build
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.3.0"
build_config:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: build_resolvers
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "2.0.9"
build_test:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -99,13 +99,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
code_builder:
dependency: "direct main"
description:
Expand Down Expand Up @@ -154,7 +147,7 @@ packages:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.2.3"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -357,7 +350,7 @@ packages:
name: source_gen
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.2"
source_map_stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -427,21 +420,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.17.12"
version: "1.21.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.9"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.13"
test_cov:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -499,4 +492,4 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.15.0 <3.0.0"
2 changes: 1 addition & 1 deletion floor_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
analyzer: ">=2.1.0 <4.0.0"
analyzer: '>= 4.0.0 <5.0.0'
build: ^2.1.0
build_config: ^1.0.0
code_builder: ^4.1.0
Expand Down
3 changes: 3 additions & 0 deletions floor_generator/test/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class FakeClassElement implements ClassElement {

@override
Element get nonSynthetic => throw UnimplementedError();

@override
bool get isDartCoreEnum => throw UnimplementedError();
}

class FakeFieldElement implements FieldElement {
Expand Down
10 changes: 6 additions & 4 deletions floor_generator/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:build/build.dart';
import 'package:build_test/build_test.dart';
import 'package:code_builder/code_builder.dart';
import 'package:code_builder/code_builder.dart' hide FunctionType;
import 'package:dart_style/dart_style.dart';
import 'package:floor_annotation/floor_annotation.dart' as annotations;
import 'package:floor_generator/misc/type_utils.dart';
Expand Down Expand Up @@ -62,7 +62,7 @@ Future<DartType> getDartTypeWithPerson(String value) async {
return resolveSource(source, (item) async {
final libraryReader =
LibraryReader((await item.findLibraryByName('test'))!);
return (libraryReader.allElements.first as PropertyAccessorElement)
return (libraryReader.allElements.elementAt(1) as PropertyAccessorElement)
.type
.returnType;
});
Expand All @@ -86,7 +86,7 @@ Future<DartType> getDartTypeWithName(String value) async {
return resolveSource(source, (item) async {
final libraryReader =
LibraryReader((await item.findLibraryByName('test'))!);
return (libraryReader.allElements.first as PropertyAccessorElement)
return (libraryReader.allElements.elementAt(1) as PropertyAccessorElement)
.type
.returnType;
});
Expand All @@ -102,7 +102,9 @@ Future<DartType> getDartTypeFromDeclaration(final String declaration) async {
return resolveSource(source, (item) async {
final libraryReader =
LibraryReader((await item.findLibraryByName('test'))!);
return (libraryReader.allElements.elementAt(1) as VariableElement).type;
return (libraryReader.allElements.elementAt(1) as PropertyAccessorElement)
.type
.returnType;
});
}

Expand Down

0 comments on commit ba521e3

Please sign in to comment.