Skip to content

Commit c8c3b39

Browse files
authored
Stop using source_gen TypeChecker.fromRuntime. (#1517)
1 parent 426f5a2 commit c8c3b39

11 files changed

+30
-11
lines changed

json_serializable/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Require `dart_style: ^3.0.0`
66
- Require `meta: ^1.15.0`
77
- Require `source_helper: ^1.3.6`
8+
- Require `source_gen: ^3.1.0`, stop using deprecated `TypeChecker.fromRuntime`
9+
and use the new `TypeChecker.typeNamed` instead.
810

911
## 6.10.0
1012

json_serializable/lib/src/enum_utils.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ Object? _generateEntry({
8383
required JsonEnum jsonEnum,
8484
required DartType targetType,
8585
}) {
86-
final annotation = const TypeChecker.fromRuntime(
86+
final annotation = const TypeChecker.typeNamed(
8787
JsonValue,
88+
inPackage: 'json_annotation',
8889
).firstAnnotationOfExact(field);
8990

9091
if (annotation == null) {
@@ -144,7 +145,10 @@ Object? _generateEntry({
144145
}
145146
}
146147

147-
const _jsonEnumChecker = TypeChecker.fromRuntime(JsonEnum);
148+
const _jsonEnumChecker = TypeChecker.typeNamed(
149+
JsonEnum,
150+
inPackage: 'json_annotation',
151+
);
148152

149153
JsonEnum _fromAnnotation(DartObject? dartObject) {
150154
if (dartObject == null) {

json_serializable/lib/src/field_helpers.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,8 @@ List<FieldElement2> createSortedFieldSet(ClassElement2 element) {
107107
return fields.map((fs) => fs.field).toList(growable: false);
108108
}
109109

110-
const _dartCoreObjectChecker = TypeChecker.fromRuntime(Object);
110+
const _dartCoreObjectChecker = TypeChecker.typeNamed(
111+
Object,
112+
inPackage: 'core',
113+
inSdk: true,
114+
);

json_serializable/lib/src/json_enum_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:source_gen/source_gen.dart';
1010
import 'enum_utils.dart';
1111

1212
class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> {
13-
const JsonEnumGenerator();
13+
const JsonEnumGenerator() : super(inPackage: 'json_annotation');
1414

1515
@override
1616
List<String> generateForAnnotatedElement(

json_serializable/lib/src/json_key_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ bool _interfaceTypesEqual(DartType a, DartType b) {
365365
const jsonKeyNullForUndefinedEnumValueFieldName =
366366
'JsonKey.nullForUndefinedEnumValue';
367367

368-
final _nullAsUnknownChecker = TypeChecker.fromRuntime(
368+
final _nullAsUnknownChecker = TypeChecker.typeNamed(
369369
JsonKey.nullForUndefinedEnumValue.runtimeType,
370+
inPackage: 'json_annotation',
370371
);

json_serializable/lib/src/json_literal_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:source_gen/source_gen.dart';
1313
import 'package:source_helper/source_helper.dart';
1414

1515
class JsonLiteralGenerator extends GeneratorForAnnotation<JsonLiteral> {
16-
const JsonLiteralGenerator();
16+
const JsonLiteralGenerator() : super(inPackage: 'json_annotation');
1717

1818
@override
1919
Future<String> generateForAnnotatedElement(

json_serializable/lib/src/json_serializable_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class JsonSerializableGenerator
2222

2323
JsonSerializable get config => _settings.config.toJsonSerializable();
2424

25-
JsonSerializableGenerator.fromSettings(this._settings);
25+
JsonSerializableGenerator.fromSettings(this._settings)
26+
: super(inPackage: 'json_annotation');
2627

2728
/// Creates an instance of [JsonSerializableGenerator].
2829
///

json_serializable/lib/src/type_helpers/json_converter_helper.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,7 @@ _ConverterMatch? _compatibleMatch(
331331
return null;
332332
}
333333

334-
const _jsonConverterChecker = TypeChecker.fromRuntime(JsonConverter);
334+
const _jsonConverterChecker = TypeChecker.typeNamed(
335+
JsonConverter,
336+
inPackage: 'json_annotation',
337+
);

json_serializable/lib/src/type_helpers/json_helper.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
279279
if (source.isEnum) {
280280
return null;
281281
}
282-
final annotations = const TypeChecker.fromRuntime(
282+
final annotations = const TypeChecker.typeNamed(
283283
JsonSerializable,
284+
inPackage: 'json_annotation',
284285
).annotationsOfExact(source.element3, throwOnUnresolved: false).toList();
285286

286287
if (annotations.isEmpty) {

json_serializable/lib/src/utils.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import 'package:source_helper/source_helper.dart';
1212
import 'shared_checkers.dart';
1313
import 'type_helpers/config_types.dart';
1414

15-
const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey);
15+
const _jsonKeyChecker = TypeChecker.typeNamed(
16+
JsonKey,
17+
inPackage: 'json_annotation',
18+
);
1619

1720
/// If an annotation exists on `element` the source is a 'real' field.
1821
/// If the result is `null`, check the getter – it is a property.

0 commit comments

Comments
 (0)