Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest pkg:analyzer, prepare to publish #1200

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
include: package:lints/recommended.yaml

analyzer:
errors:
# TODO: remove when pkg:analyzer v5 is out
deprecated_member_use: ignore
language:
strict-casts: true

Expand Down
4 changes: 4 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dev_dependencies:
lints: ^2.0.0
path: ^1.8.0
test: ^1.16.0

dependency_overrides:
json_serializable:
path: ../json_serializable
6 changes: 3 additions & 3 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 6.3.2-dev
## 6.3.2

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

## 6.3.1

Expand Down
3 changes: 1 addition & 2 deletions json_serializable/lib/src/decode_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ _ConstructorData _writeConstructorInvocation(

for (final arg in ctor.parameters) {
if (!availableConstructorParameters.contains(arg.name)) {
// ignore: deprecated_member_use
if (arg.isNotOptional) {
if (arg.isRequired) {
var msg = 'Cannot populate the required constructor '
'argument: ${arg.name}.';

Expand Down
6 changes: 3 additions & 3 deletions json_serializable/lib/src/enum_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import 'json_literal_generator.dart';
import 'utils.dart';

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

String? enumValueMapFromType(
DartType targetType, {
bool nullWithNoAnnotation = false,
}) {
final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element!);
final annotation = _jsonEnumChecker.firstAnnotationOf(targetType.element2!);
final jsonEnum = _fromAnnotation(annotation);

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

final items = enumMap.entries
.map((e) => ' ${targetType.element!.name}.${e.key.name}: '
.map((e) => ' ${targetType.element2!.name}.${e.key.name}: '
'${jsonLiteralAsDart(e.value)},')
.join();

Expand Down
12 changes: 6 additions & 6 deletions json_serializable/lib/src/field_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ class _FieldSet implements Comparable<_FieldSet> {

static int _sortByLocation(FieldElement a, FieldElement b) {
final checkerA =
TypeChecker.fromStatic((a.enclosingElement2 as ClassElement).thisType);
TypeChecker.fromStatic((a.enclosingElement3 as ClassElement).thisType);

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

if (checkerA.isAssignableFrom(b.enclosingElement2)) {
if (checkerA.isAssignableFrom(b.enclosingElement3)) {
return -1;
}

final checkerB = TypeChecker.fromStatic(
(b.enclosingElement2 as ClassElement).thisType);
(b.enclosingElement3 as InterfaceElement).thisType);

if (checkerB.isAssignableFrom(a.enclosingElement2)) {
if (checkerB.isAssignableFrom(a.enclosingElement3)) {
return 1;
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ Iterable<FieldElement> createSortedFieldSet(ClassElement element) {

for (final v in manager.getInheritedConcreteMap2(element).values) {
assert(v is! FieldElement);
if (_dartCoreObjectChecker.isExactly(v.enclosingElement2)) {
if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion json_serializable/lib/src/helper_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $converterOrKeyInstructions
message = '$message because of type `${typeToCode(error.type)}`';
} else {
todo = '''
To support the type `${error.type.element!.name}` you can:
To support the type `${error.type.element2!.name}` you can:
$converterOrKeyInstructions''';
}

Expand Down
2 changes: 1 addition & 1 deletion json_serializable/lib/src/json_enum_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class JsonEnumGenerator extends GeneratorForAnnotation<JsonEnum> {
ConstantReader annotation,
BuildStep buildStep,
) {
if (element is! ClassElement || !element.isEnum) {
if (element is! EnumElement) {
throw InvalidGenerationSourceError(
'`@JsonEnum` can only be used on enum elements.',
element: element,
Expand Down
6 changes: 3 additions & 3 deletions json_serializable/lib/src/json_key_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KeyConfig _from(FieldElement element, ClassConfig classAnnotation) {
// TODO: Support calling function for the default value?
badType = 'Function';
} else if (!reader.isLiteral) {
badType = dartObject.type!.element!.name;
badType = dartObject.type!.element2!.name;
}

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

return '${annotationType.element!.name}'
return '${annotationType.element2!.name}'
'.$enumValueName';
} else {
final defaultValueLiteral = annotationValue.isNull
Expand Down Expand Up @@ -280,7 +280,7 @@ bool _includeIfNull(
bool _interfaceTypesEqual(DartType a, DartType b) {
if (a is InterfaceType && b is InterfaceType) {
// Handle nullability case. Pretty sure this is fine for enums.
return a.element == b.element;
return a.element2 == b.element2;
}
return a == b;
}
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/lib/src/json_serializable_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class JsonSerializableGenerator
);
}

if (element is! ClassElement || element.isEnum) {
if (element is! ClassElement || element is EnumElement) {
throw InvalidGenerationSourceError(
'`@JsonSerializable` can only be used on classes.',
element: element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ _JsonConvertData? _typeConverterFrom(

final annotationElement = match.elementAnnotation?.element;
if (annotationElement is PropertyAccessorElement) {
final enclosing = annotationElement.enclosingElement2;
final enclosing = annotationElement.enclosingElement3;

var accessString = annotationElement.name;

Expand All @@ -226,7 +226,7 @@ _JsonConvertData? _typeConverterFrom(

if (match.genericTypeArg != null) {
return _JsonConvertData.genericClass(
match.annotation.type!.element!.name!,
match.annotation.type!.element2!.name!,
match.genericTypeArg!,
reviver.accessor,
match.jsonType,
Expand All @@ -235,7 +235,7 @@ _JsonConvertData? _typeConverterFrom(
}

return _JsonConvertData.className(
match.annotation.type!.element!.name!,
match.annotation.type!.element2!.name!,
reviver.accessor,
match.jsonType,
match.fieldType,
Expand Down Expand Up @@ -263,18 +263,18 @@ _ConverterMatch? _compatibleMatch(
ElementAnnotation? annotation,
DartObject constantValue,
) {
final converterClassElement = constantValue.type!.element as ClassElement;
final converterClassElement = constantValue.type!.element2 as ClassElement;

final jsonConverterSuper =
converterClassElement.allSupertypes.singleWhereOrNull(
(e) => _jsonConverterChecker.isExactly(e.element),
(e) => _jsonConverterChecker.isExactly(e.element2),
);

if (jsonConverterSuper == null) {
return null;
}

assert(jsonConverterSuper.element.typeParameters.length == 2);
assert(jsonConverterSuper.element2.typeParameters.length == 2);
assert(jsonConverterSuper.typeArguments.length == 2);

final fieldType = jsonConverterSuper.typeArguments[0];
Expand Down Expand Up @@ -305,7 +305,7 @@ _ConverterMatch? _compatibleMatch(
annotation,
constantValue,
jsonConverterSuper.typeArguments[1],
'${targetType.element.name}${targetType.isNullableType ? '?' : ''}',
'${targetType.element2.name}${targetType.isNullableType ? '?' : ''}',
fieldType,
);
}
Expand Down
16 changes: 8 additions & 8 deletions json_serializable/lib/src/type_helpers/json_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class JsonHelper extends TypeHelper<TypeHelperContextWithConfig> {
return null;
}

final classElement = targetType.element;
final classElement = targetType.element2;

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

for (var helperArg in rest) {
final typeParamIndex =
type.element.typeParameters.indexOf(helperArg.element);
type.element2.typeParameters.indexOf(helperArg.element2);

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

if (param.name == fromJsonForName(funcReturnType.element!.name!)) {
if (param.name == fromJsonForName(funcReturnType.element2!.name!)) {
final funcParamType = type.normalParameterTypes.single;

if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) ||
Expand Down Expand Up @@ -205,7 +205,7 @@ TypeParameterType _encodeHelper(
type.normalParameterTypes.length == 1) {
final funcParamType = type.normalParameterTypes.single;

if (param.name == toJsonForName(funcParamType.element!.name!)) {
if (param.name == toJsonForName(funcParamType.element2!.name!)) {
if (funcParamType is TypeParameterType) {
return funcParamType;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ InterfaceType? _instantiate(
InterfaceType classType,
) {
final argTypes = ctorParamType.typeArguments.map((arg) {
final typeParamIndex = classType.element.typeParameters.indexWhere(
final typeParamIndex = classType.element2.typeParameters.indexWhere(
// TODO: not 100% sure `nullabilitySuffix` is right
(e) => e.instantiate(nullabilitySuffix: arg.nullabilitySuffix) == arg);
if (typeParamIndex >= 0) {
Expand All @@ -261,7 +261,7 @@ InterfaceType? _instantiate(
return null;
}

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

if (annotations.isEmpty) {
Expand All @@ -283,7 +283,7 @@ ClassConfig? _annotation(ClassConfig config, InterfaceType source) {
return mergeConfig(
config,
ConstantReader(annotations.single),
classElement: source.element,
classElement: source.element2 as ClassElement,
);
}

Expand Down
11 changes: 6 additions & 5 deletions json_serializable/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,16 @@ ConstructorElement constructorByName(ClassElement classElement, String name) {
///
/// Otherwise, `null`.
Iterable<FieldElement>? iterateEnumFields(DartType targetType) {
if (targetType is InterfaceType && targetType.element.isEnum) {
return targetType.element.fields.where((element) => element.isEnumConstant);
if (targetType is InterfaceType && targetType.element2 is EnumElement) {
return targetType.element2.fields
.where((element) => element.isEnumConstant);
}
return null;
}

extension DartTypeExtension on DartType {
DartType promoteNonNullable() =>
element?.library?.typeSystem.promoteToNonNull(this) ?? this;
element2?.library?.typeSystem.promoteToNonNull(this) ?? this;
}

String ifNullOrElse(String test, String ifNull, String ifNotNull) =>
Expand Down Expand Up @@ -206,7 +207,7 @@ String typeToCode(
return 'dynamic';
} else if (type is InterfaceType) {
return [
type.element.name,
type.element2.name,
if (type.typeArguments.isNotEmpty)
'<${type.typeArguments.map(typeToCode).join(', ')}>',
(type.isNullableType || forceNullable) ? '?' : '',
Expand All @@ -228,7 +229,7 @@ extension ExecutableElementExtension on ExecutableElement {
}

if (this is MethodElement) {
return '${enclosingElement2.name}.$name';
return '${enclosingElement3.name}.$name';
}

throw UnsupportedError(
Expand Down
4 changes: 2 additions & 2 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 6.3.2-dev
version: 6.3.2
description: >-
Automatically generate code for converting to and from JSON by annotating
Dart classes.
Expand All @@ -8,7 +8,7 @@ environment:
sdk: '>=2.17.0 <3.0.0'

dependencies:
analyzer: '>=4.3.1 <5.0.0'
analyzer: '>=4.6.0 <6.0.0'
async: ^2.8.0
build: ^2.0.0
build_config: '>=0.4.4 <2.0.0'
Expand Down