Skip to content

Commit 9e78252

Browse files
committed
Fix deprecated APIs
1 parent 58c0652 commit 9e78252

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

packages/freezed/lib/src/models.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ class _Sentinel {
2929

3030
extension on Element2 {
3131
bool get hasJsonSerializable {
32-
return const TypeChecker.fromRuntime(
32+
return const TypeChecker.typeNamed(
3333
JsonSerializable,
34+
inPackage: 'json_annotation',
3435
).hasAnnotationOf(this, throwOnUnresolved: false);
3536
}
3637
}
@@ -42,8 +43,9 @@ extension on ConstructorElement2 {
4243
}
4344

4445
String unionValue(FreezedUnionCase? unionCase) {
45-
final annotation = const TypeChecker.fromRuntime(
46+
final annotation = const TypeChecker.typeNamed(
4647
FreezedUnionValue,
48+
inPackage: 'freezed_annotation',
4749
).firstAnnotationOf(this, throwOnUnresolved: false);
4850
if (annotation != null) {
4951
return annotation.getField('value')!.toStringValue()!;
@@ -66,7 +68,10 @@ extension on ConstructorElement2 {
6668
}
6769
}
6870

69-
const freezedType = TypeChecker.fromRuntime(Freezed);
71+
const freezedType = TypeChecker.typeNamed(
72+
Freezed,
73+
inPackage: 'freezed_annotation',
74+
);
7075

7176
/// A generated property that has for type a class generated using Freezed
7277
///
@@ -421,8 +426,9 @@ class ImplementsAnnotation {
421426
static Iterable<ImplementsAnnotation> parseAll(
422427
ConstructorElement2 constructor,
423428
) sync* {
424-
for (final meta in const TypeChecker.fromRuntime(
429+
for (final meta in const TypeChecker.typeNamed(
425430
Implements,
431+
inPackage: 'freezed_annotation',
426432
).annotationsOf(constructor, throwOnUnresolved: false)) {
427433
final stringType = meta.getField('stringType');
428434
if (stringType?.isNull == false) {
@@ -474,8 +480,9 @@ class AssertAnnotation {
474480
static Iterable<AssertAnnotation> parseAll(
475481
ConstructorDeclaration constructor,
476482
) sync* {
477-
for (final meta in const TypeChecker.fromRuntime(
483+
for (final meta in const TypeChecker.typeNamed(
478484
Assert,
485+
inPackage: 'freezed_annotation',
479486
).annotationsOf(constructor.declaredFragment!.element)) {
480487
yield AssertAnnotation(
481488
code: meta.getField('eval')!.toStringValue()!,

packages/freezed/lib/src/templates/concrete_template.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ extension DefaultValue on FormalParameterElement {
517517
/// Returns the sources of the default value associated with a `@Default`,
518518
/// or `null` if no `@Default` are specified.
519519
String? get defaultValue {
520-
const matcher = TypeChecker.fromRuntime(Default);
520+
const matcher = TypeChecker.typeNamed(
521+
Default,
522+
inPackage: 'freezed_annotation',
523+
);
521524

522525
for (final meta in metadata2.annotations) {
523526
final obj = meta.computeConstantValue()!;
@@ -541,7 +544,10 @@ extension DefaultValue on FormalParameterElement {
541544
}
542545

543546
bool get hasJsonKey {
544-
return const TypeChecker.fromRuntime(JsonKey).hasAnnotationOf(this);
547+
return const TypeChecker.typeNamed(
548+
JsonKey,
549+
inPackage: 'json_annotation',
550+
).hasAnnotationOf(this);
545551
}
546552
}
547553

packages/freezed/lib/src/templates/prototypes.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@ String wrapClassField(String name) {
1818
extension FreezedElementAnnotation on ElementAnnotation {
1919
/// if the element is decorated with `@Default(value)`
2020
bool get isDefault {
21-
return const TypeChecker.fromRuntime(
21+
return const TypeChecker.typeNamed(
2222
Default,
23+
inPackage: 'freezed_annotation',
2324
).isExactlyType(computeConstantValue()!.type!);
2425
}
2526

2627
/// if the element is decorated with `@With<Type>`
2728
bool get isWith {
28-
return const TypeChecker.fromRuntime(
29+
return const TypeChecker.typeNamed(
2930
With,
31+
inPackage: 'freezed_annotation',
3032
).isExactlyType(computeConstantValue()!.type!);
3133
}
3234

3335
/// if the element is decorated with `@Implements<Type>`
3436
bool get isImplements {
35-
return const TypeChecker.fromRuntime(
37+
return const TypeChecker.typeNamed(
3638
Implements,
39+
inPackage: 'freezed_annotation',
3740
).isExactlyType(computeConstantValue()!.type!);
3841
}
3942
}

packages/freezed_lint/lib/src/missing_private_empty_ctor.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class MissingPrivateEmptyCtor extends DartLintRule {
3232
final methods = element.methods2.where((method) => !method.isStatic);
3333
final fields = element.fields2.where((field) => !field.isStatic);
3434

35-
36-
final accessors =[
35+
final accessors = [
3736
...element.getters2,
3837
...element.setters2,
3938
].where((accessor) => !accessor.isStatic);

0 commit comments

Comments
 (0)