Skip to content

Commit

Permalink
Bump analyzer version, stop using deprecated methods. Release 8.4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmorgan committed Oct 27, 2022
1 parent 2e1b3b3 commit 05da0d3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

# 8.4.2 (unpublished)
# 8.4.2

- Prepare for breaking analyzer changes.
- Bump version of `analyzer`.

# 8.4.1

Expand Down
12 changes: 6 additions & 6 deletions built_value_generator/lib/src/dart_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class DartTypes {

static bool isInstantiableBuiltValue(DartType type) {
return isBuiltValue(type) &&
ValueSourceClass(type.element2 as ClassElement).settings.instantiable;
ValueSourceClass(type.element as ClassElement).settings.instantiable;
}

static bool isBuiltValue(DartType type) =>
type is InterfaceType &&
type.element2.allSupertypes
.any((interfaceType) => interfaceType.element2.name == 'Built');
type.element.allSupertypes
.any((interfaceType) => interfaceType.element.name == 'Built');

static bool isBuiltCollection(DartType type) {
return _builtCollectionNames
Expand Down Expand Up @@ -72,15 +72,15 @@ class DartTypes {
} else if (dartType is InterfaceType) {
var typeArguments = dartType.typeArguments;
if (typeArguments.isEmpty) {
return dartType.element2.name + suffix;
return dartType.element.name + suffix;
} else {
final typeArgumentsStr = typeArguments
.map((type) => getName(type, withNullabilitySuffix: true))
.join(', ');
return '${dartType.element2.name}<$typeArgumentsStr>$suffix';
return '${dartType.element.name}<$typeArgumentsStr>$suffix';
}
} else if (dartType is TypeParameterType) {
return dartType.element2.name + suffix;
return dartType.element.name + suffix;
} else if (dartType.isVoid) {
return 'void';
} else {
Expand Down
8 changes: 4 additions & 4 deletions built_value_generator/lib/src/serializer_source_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ abstract class SerializerSourceClass
@memoized
bool get isBuiltValue =>
element.allSupertypes
.map((type) => type.element2.name)
.map((type) => type.element.name)
.any((name) => name.startsWith('Built')) &&
!element.name.startsWith(r'_$') &&
element.fields.any((field) => field.name == 'serializer');
Expand All @@ -152,7 +152,7 @@ abstract class SerializerSourceClass
@memoized
bool get isEnumClass =>
element.allSupertypes
.map((type) => type.element2.name)
.map((type) => type.element.name)
.any((name) => name == 'EnumClass') &&
!element.name.startsWith(r'_$') &&
element.fields.any((field) => field.name == 'serializer');
Expand Down Expand Up @@ -193,7 +193,7 @@ abstract class SerializerSourceClass
if (fieldElement.setter != null) continue;

final fieldType = fieldElement.type;
final fieldTypeElement = fieldType.element2;
final fieldTypeElement = fieldType.element;

// Type is not fully specified, ignore.
if (fieldTypeElement is! ClassElement) continue;
Expand All @@ -202,7 +202,7 @@ abstract class SerializerSourceClass
// of type List<Foo> means we need to be able to serialize Foo.
if (fieldType is ParameterizedType) {
for (final type in fieldType.typeArguments) {
final typeElement = type.element2;
final typeElement = type.element;

// Type is not fully specified, ignore.
if (typeElement is! ClassElement) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ abstract class SerializerSourceLibrary
result.addValues(
field,
types.map((type) =>
SerializerSourceClass(type!.element2 as InterfaceElement)));
SerializerSourceClass(type!.element as InterfaceElement)));
}
return result.build();
}
Expand Down
26 changes: 13 additions & 13 deletions built_value_generator/lib/src/value_source_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class ValueSourceClass

@memoized
bool get implementsBuilt => element.allSupertypes
.any((interfaceType) => interfaceType.element2.name == 'Built');
.any((interfaceType) => interfaceType.element.name == 'Built');

@memoized
bool get extendsIsAllowed {
Expand All @@ -93,18 +93,18 @@ abstract class ValueSourceClass

for (var supertype in [
element.supertype,
...element.supertype!.element2.allSupertypes
...element.supertype!.element.allSupertypes
]) {
if (DartTypes.tryGetName(supertype) == 'Object') continue;

// Base class must be abstract.
final superElement = supertype!.element2;
final superElement = supertype!.element;
if (superElement is! ClassElement || !superElement.isAbstract) {
return false;
}

// Base class must have no fields.
if (supertype.element2.fields
if (supertype.element.fields
.any((field) => !field.isStatic && !field.isSynthetic)) {
return false;
}
Expand All @@ -116,9 +116,9 @@ abstract class ValueSourceClass
}

// Base class must not implement operator==, hashCode or toString.
if (supertype.element2.getMethod('hashCode') != null) return false;
if (supertype.element2.getMethod('==') != null) return false;
if (supertype.element2.getMethod('toString') != null) return false;
if (supertype.element.getMethod('hashCode') != null) return false;
if (supertype.element.getMethod('==') != null) return false;
if (supertype.element.getMethod('toString') != null) return false;
}

return true;
Expand Down Expand Up @@ -216,7 +216,7 @@ abstract class ValueSourceClass
@memoized
String get builderParameters {
return builderElement!.allSupertypes
.where((interfaceType) => interfaceType.element2.name == 'Builder')
.where((interfaceType) => interfaceType.element.name == 'Builder')
.single
.typeArguments
.map((type) => DartTypes.getName(type))
Expand Down Expand Up @@ -316,7 +316,7 @@ abstract class ValueSourceClass
BuiltList<String> get builderImplements => BuiltList<String>.build((b) => b
..add('Builder<$name$_generics, ${name}Builder$_generics>')
..addAll(element.interfaces
.where((interface) => needsBuiltValue(interface.element2))
.where((interface) => needsBuiltValue(interface.element))
.map(_parentBuilderInterfaceName)));

/// Returns the `with` clause for the builder.
Expand All @@ -325,7 +325,7 @@ abstract class ValueSourceClass
/// the corresponding builders.
@memoized
BuiltList<String> get builderMixins => element.mixins
.where((interface) => needsBuiltValue(interface.element2))
.where((interface) => needsBuiltValue(interface.element))
.map(_parentBuilderInterfaceName)
.toBuiltList();

Expand Down Expand Up @@ -364,7 +364,7 @@ abstract class ValueSourceClass
// Check for any `toString` implementation apart from the one defined on
// `Object`.
var method = element.lookUpConcreteMethod('toString', element.library)!;
var clazz = method.enclosingElement3;
var clazz = method.enclosingElement;
return clazz is! ClassElement || clazz.name != 'Object';
}

Expand All @@ -376,7 +376,7 @@ abstract class ValueSourceClass
// TODO(davidmorgan): more exact type check.
return !classElement.displayName.startsWith('_\$') &&
(classElement.allSupertypes.any(
(interfaceType) => interfaceType.element2.name == 'Built') ||
(interfaceType) => interfaceType.element.name == 'Built') ||
classElement.metadata
.map((annotation) => annotation.computeConstantValue())
.any((value) =>
Expand Down Expand Up @@ -1077,7 +1077,7 @@ abstract class ValueSourceClass
}
if (field.hasNullableGenericType) {
genericFields[name] =
field.element.getter!.returnType.element2!.displayName;
field.element.getter!.returnType.element!.displayName;
}
} else if (!field.isNullable && field.isAutoCreateNestedBuilder) {
// If not nullable, go via the public accessor, which instantiates
Expand Down
2 changes: 1 addition & 1 deletion built_value_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: '>=2.14.0 <3.0.0'

dependencies:
analyzer: '>=4.6.0 <5.0.0'
analyzer: '>=4.6.0 <6.0.0'
build: '>=1.0.0 <3.0.0'
build_config: '>=0.3.1 <2.0.0'
built_collection: ^5.0.0
Expand Down

0 comments on commit 05da0d3

Please sign in to comment.