Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e30a519

Browse files
authoredSep 13, 2022
latest pkg:analyzer, prepare to publish (google#1200)
1 parent b1cd6be commit e30a519

14 files changed

+46
-45
lines changed
 

‎analysis_options.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
include: package:lints/recommended.yaml
22

33
analyzer:
4-
errors:
5-
# TODO: remove when pkg:analyzer v5 is out
6-
deprecated_member_use: ignore
74
language:
85
strict-casts: true
96

‎example/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ dev_dependencies:
2222
lints: ^2.0.0
2323
path: ^1.8.0
2424
test: ^1.16.0
25+
26+
dependency_overrides:
27+
json_serializable:
28+
path: ../json_serializable

‎json_serializable/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## 6.3.2-dev
1+
## 6.3.2
22

3-
- Require Dart SDK 2.17
4-
- Require package:analyzer >=4.3.1
3+
- Require `analyzer: '>=4.6.0 <6.0.0'`
4+
- Require `sdk: '>=2.17.0 <3.0.0'`
55

66
## 6.3.1
77

‎json_serializable/lib/src/decode_helper.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ _ConstructorData _writeConstructorInvocation(
278278

279279
for (final arg in ctor.parameters) {
280280
if (!availableConstructorParameters.contains(arg.name)) {
281-
// ignore: deprecated_member_use
282-
if (arg.isNotOptional) {
281+
if (arg.isRequired) {
283282
var msg = 'Cannot populate the required constructor '
284283
'argument: ${arg.name}.';
285284

‎json_serializable/lib/src/enum_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import 'json_literal_generator.dart';
1212
import 'utils.dart';
1313

1414
String constMapName(DartType targetType) =>
15-
'_\$${targetType.element!.name}EnumMap';
15+
'_\$${targetType.element2!.name}EnumMap';
1616

1717
String? enumValueMapFromType(
1818
DartType targetType, {
1919
bool nullWithNoAnnotation = false,
2020
}) {
21-
final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!);
21+
final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element2!);
2222
final jsonEnum = _fromAnnotation(annotation);
2323

2424
final enumFields = iterateEnumFields(targetType);
@@ -59,7 +59,7 @@ String? enumValueMapFromType(
5959
Map<FieldElement, dynamic>.fromEntries(enumFields.map(generateEntry));
6060

6161
final items = enumMap.entries
62-
.map((e) => ' ${targetType.element!.name}.${e.key.name}: '
62+
.map((e) => ' ${targetType.element2!.name}.${e.key.name}: '
6363
'${jsonLiteralAsDart(e.value)},')
6464
.join();
6565

‎json_serializable/lib/src/field_helpers.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ class _FieldSet implements Comparable<_FieldSet> {
3737

3838
static int _sortByLocation(FieldElement a, FieldElement b) {
3939
final checkerA =
40-
TypeChecker.fromStatic((a.enclosingElement2 as ClassElement).thisType);
40+
TypeChecker.fromStatic((a.enclosingElement3 as ClassElement).thisType);
4141

42-
if (!checkerA.isExactly(b.enclosingElement2)) {
42+
if (!checkerA.isExactly(b.enclosingElement3)) {
4343
// in this case, you want to prioritize the enclosingElement that is more
4444
// "super".
4545

46-
if (checkerA.isAssignableFrom(b.enclosingElement2)) {
46+
if (checkerA.isAssignableFrom(b.enclosingElement3)) {
4747
return -1;
4848
}
4949

5050
final checkerB = TypeChecker.fromStatic(
51-
(b.enclosingElement2 as ClassElement).thisType);
51+
(b.enclosingElement3 as InterfaceElement).thisType);
5252

53-
if (checkerB.isAssignableFrom(a.enclosingElement2)) {
53+
if (checkerB.isAssignableFrom(a.enclosingElement3)) {
5454
return 1;
5555
}
5656
}
@@ -82,7 +82,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) {
8282

8383
for (final v in manager.getInheritedConcreteMap2(element).values) {
8484
assert(v is! FieldElement);
85-
if (_dartCoreObjectChecker.isExactly(v.enclosingElement2)) {
85+
if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) {
8686
continue;
8787
}
8888

‎json_serializable/lib/src/helper_core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $converterOrKeyInstructions
7878
message = '$message because of type `${typeToCode(error.type)}`';
7979
} else {
8080
todo = '''
81-
To support the type `${error.type.element!.name}` you can:
81+
To support the type `${error.type.element2!.name}` you can:
8282
$converterOrKeyInstructions''';
8383
}
8484

‎json_serializable/lib/src/json_enum_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> {
1818
ConstantReader annotation,
1919
BuildStep buildStep,
2020
) {
21-
if (element is! ClassElement || !element.isEnum) {
21+
if (element is! EnumElement) {
2222
throw InvalidGenerationSourceError(
2323
'`@JsonEnum` can only be used on enum elements.',
2424
element: element,

‎json_serializable/lib/src/json_key_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) {
6161
// TODO: Support calling function for the default value?
6262
badType = 'Function';
6363
} else if (!reader.isLiteral) {
64-
badType = dartObject.type!.element!.name;
64+
badType = dartObject.type!.element2!.name;
6565
}
6666

6767
if (badType != null) {
@@ -173,7 +173,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) {
173173
final enumValueName = enumValueForDartObject<String>(
174174
annotationValue.objectValue, enumValueNames, (n) => n);
175175

176-
return '${annotationType.element!.name}'
176+
return '${annotationType.element2!.name}'
177177
'.$enumValueName';
178178
} else {
179179
final defaultValueLiteral = annotationValue.isNull
@@ -280,7 +280,7 @@ bool _includeIfNull(
280280
bool _interfaceTypesEqual(DartType a, DartType b) {
281281
if (a is InterfaceType && b is InterfaceType) {
282282
// Handle nullability case. Pretty sure this is fine for enums.
283-
return a.element == b.element;
283+
return a.element2 == b.element2;
284284
}
285285
return a == b;
286286
}

‎json_serializable/lib/src/json_serializable_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class JsonSerializableGenerator
6969
);
7070
}
7171

72-
if (element is! ClassElement || element.isEnum) {
72+
if (element is! ClassElement || element is EnumElement) {
7373
throw InvalidGenerationSourceError(
7474
'`@JsonSerializable` can only be used on classes.',
7575
element: element,

‎json_serializable/lib/src/type_helpers/json_converter_helper.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ _JsonConvertData? _typeConverterFrom(
199199

200200
final annotationElement = match.elementAnnotation?.element;
201201
if (annotationElement is PropertyAccessorElement) {
202-
final enclosing = annotationElement.enclosingElement2;
202+
final enclosing = annotationElement.enclosingElement3;
203203

204204
var accessString = annotationElement.name;
205205

@@ -226,7 +226,7 @@ _JsonConvertData? _typeConverterFrom(
226226

227227
if (match.genericTypeArg != null) {
228228
return _JsonConvertData.genericClass(
229-
match.annotation.type!.element!.name!,
229+
match.annotation.type!.element2!.name!,
230230
match.genericTypeArg!,
231231
reviver.accessor,
232232
match.jsonType,
@@ -235,7 +235,7 @@ _JsonConvertData? _typeConverterFrom(
235235
}
236236

237237
return _JsonConvertData.className(
238-
match.annotation.type!.element!.name!,
238+
match.annotation.type!.element2!.name!,
239239
reviver.accessor,
240240
match.jsonType,
241241
match.fieldType,
@@ -263,18 +263,18 @@ _ConverterMatch? _compatibleMatch(
263263
ElementAnnotation? annotation,
264264
DartObject constantValue,
265265
) {
266-
final converterClassElement = constantValue.type!.element as ClassElement;
266+
final converterClassElement = constantValue.type!.element2 as ClassElement;
267267

268268
final jsonConverterSuper =
269269
converterClassElement.allSupertypes.singleWhereOrNull(
270-
(e) => _jsonConverterChecker.isExactly(e.element),
270+
(e) => _jsonConverterChecker.isExactly(e.element2),
271271
);
272272

273273
if (jsonConverterSuper == null) {
274274
return null;
275275
}
276276

277-
assert(jsonConverterSuper.element.typeParameters.length == 2);
277+
assert(jsonConverterSuper.element2.typeParameters.length == 2);
278278
assert(jsonConverterSuper.typeArguments.length == 2);
279279

280280
final fieldType = jsonConverterSuper.typeArguments[0];
@@ -305,7 +305,7 @@ _ConverterMatch? _compatibleMatch(
305305
annotation,
306306
constantValue,
307307
jsonConverterSuper.typeArguments[1],
308-
'${targetType.element.name}${targetType.isNullableType ? '?' : ''}',
308+
'${targetType.element2.name}${targetType.isNullableType ? '?' : ''}',
309309
fieldType,
310310
);
311311
}

‎json_serializable/lib/src/type_helpers/json_helper.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> {
7676
return null;
7777
}
7878

79-
final classElement = targetType.element;
79+
final classElement = targetType.element2;
8080

8181
final fromJsonCtor = classElement.constructors
8282
.singleWhereOrNull((ce) => ce.name == 'fromJson');
@@ -152,7 +152,7 @@ List<String> _helperParams(
152152

153153
for (var helperArg in rest) {
154154
final typeParamIndex =
155-
type.element.typeParameters.indexOf(helperArg.element);
155+
type.element2.typeParameters.indexOf(helperArg.element2);
156156

157157
// TODO: throw here if `typeParamIndex` is -1 ?
158158
final typeArg = type.typeArguments[typeParamIndex];
@@ -174,7 +174,7 @@ TypeParameterType _decodeHelper(
174174
type.normalParameterTypes.length == 1) {
175175
final funcReturnType = type.returnType;
176176

177-
if (param.name == fromJsonForName(funcReturnType.element!.name!)) {
177+
if (param.name == fromJsonForName(funcReturnType.element2!.name!)) {
178178
final funcParamType = type.normalParameterTypes.single;
179179

180180
if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) ||
@@ -205,7 +205,7 @@ TypeParameterType _encodeHelper(
205205
type.normalParameterTypes.length == 1) {
206206
final funcParamType = type.normalParameterTypes.single;
207207

208-
if (param.name == toJsonForName(funcParamType.element!.name!)) {
208+
if (param.name == toJsonForName(funcParamType.element2!.name!)) {
209209
if (funcParamType is TypeParameterType) {
210210
return funcParamType;
211211
}
@@ -245,7 +245,7 @@ InterfaceType? _instantiate(
245245
InterfaceType classType,
246246
) {
247247
final argTypes = ctorParamType.typeArguments.map((arg) {
248-
final typeParamIndex = classType.element.typeParameters.indexWhere(
248+
final typeParamIndex = classType.element2.typeParameters.indexWhere(
249249
// TODO: not 100% sure `nullabilitySuffix` is right
250250
(e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg);
251251
if (typeParamIndex >= 0) {
@@ -261,7 +261,7 @@ InterfaceType? _instantiate(
261261
return null;
262262
}
263263

264-
return ctorParamType.element.instantiate(
264+
return ctorParamType.element2.instantiate(
265265
typeArguments: argTypes.cast<DartType>(),
266266
// TODO: not 100% sure nullabilitySuffix is right... Works for now
267267
nullabilitySuffix: NullabilitySuffix.none,
@@ -273,7 +273,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
273273
return null;
274274
}
275275
final annotations = const TypeChecker.fromRuntime(JsonSerializable)
276-
.annotationsOfExact(source.element, throwOnUnresolved: false)
276+
.annotationsOfExact(source.element2, throwOnUnresolved: false)
277277
.toList();
278278

279279
if (annotations.isEmpty) {
@@ -283,7 +283,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
283283
return mergeConfig(
284284
config,
285285
ConstantReader(annotations.single),
286-
classElement: source.element,
286+
classElement: source.element2 as ClassElement,
287287
);
288288
}
289289

‎json_serializable/lib/src/utils.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,16 @@ ConstructorElement constructorByName(ClassElement classElement, String name) {
160160
///
161161
/// Otherwise, `null`.
162162
Iterable<FieldElement>? iterateEnumFields(DartType targetType) {
163-
if (targetType is InterfaceType && targetType.element.isEnum) {
164-
return targetType.element.fields.where((element) => element.isEnumConstant);
163+
if (targetType is InterfaceType && targetType.element2 is EnumElement) {
164+
return targetType.element2.fields
165+
.where((element) => element.isEnumConstant);
165166
}
166167
return null;
167168
}
168169

169170
extension DartTypeExtension on DartType {
170171
DartType promoteNonNullable() =>
171-
element?.library?.typeSystem.promoteToNonNull(this) ?? this;
172+
element2?.library?.typeSystem.promoteToNonNull(this) ?? this;
172173
}
173174

174175
String ifNullOrElse(String test, String ifNull, String ifNotNull) =>
@@ -206,7 +207,7 @@ String typeToCode(
206207
return 'dynamic';
207208
} else if (type is InterfaceType) {
208209
return [
209-
type.element.name,
210+
type.element2.name,
210211
if (type.typeArguments.isNotEmpty)
211212
'<${type.typeArguments.map(typeToCode).join(', ')}>',
212213
(type.isNullableType || forceNullable) ? '?' : '',
@@ -228,7 +229,7 @@ extension ExecutableElementExtension on ExecutableElement {
228229
}
229230

230231
if (this is MethodElement) {
231-
return '${enclosingElement2.name}.$name';
232+
return '${enclosingElement3.name}.$name';
232233
}
233234

234235
throw UnsupportedError(

‎json_serializable/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 6.3.2-dev
2+
version: 6.3.2
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.
@@ -8,7 +8,7 @@ environment:
88
sdk: '>=2.17.0 <3.0.0'
99

1010
dependencies:
11-
analyzer: '>=4.3.1 <5.0.0'
11+
analyzer: '>=4.6.0 <6.0.0'
1212
async: ^2.8.0
1313
build: ^2.0.0
1414
build_config: '>=0.4.4 <2.0.0'

0 commit comments

Comments
 (0)
Please sign in to comment.