@@ -21,11 +21,11 @@ import 'analyzer.dart';
2121import 'util/dart_type_utilities.dart' ;
2222
2323class EnumLikeClassDescription {
24- final Map <DartObject , Set <FieldElement >> _enumConstants;
24+ final Map <DartObject , Set <FieldElement2 >> _enumConstants;
2525 EnumLikeClassDescription (this ._enumConstants);
2626
2727 /// Returns a fresh map of the class's enum-like constant values.
28- Map <DartObject , Set <FieldElement >> get enumConstants => {..._enumConstants};
28+ Map <DartObject , Set <FieldElement2 >> get enumConstants => {..._enumConstants};
2929}
3030
3131extension AstNodeExtension on AstNode {
@@ -161,9 +161,28 @@ extension ClassElementExtension on ClassElement {
161161 /// Get all mixins, including merged augmentations.
162162 List <InterfaceType > get allMixins => augmented .mixins;
163163
164+ /// Returns whether this class is exactly [otherName] declared in
165+ /// [otherLibrary] .
166+ bool isClass (String otherName, String otherLibrary) =>
167+ name == otherName && library.name == otherLibrary;
168+ }
169+
170+ extension ClassElementExtension2 on ClassElement2 {
171+ bool get hasImmutableAnnotation {
172+ var inheritedAndSelfElements = < InterfaceElement2 > [
173+ ...allSupertypes.map ((t) => t.element3),
174+ this ,
175+ ];
176+
177+ return inheritedAndSelfElements.any ((e) => e.metadata2.hasImmutable);
178+
179+ // TODO(pq): update when implemented or replace w/ a better has{*} call
180+ // https://github.com/dart-lang/linter/issues/4939
181+ //return inheritedAndSelfElements.any((e) => e.augmented.metadata.any((e) => e.isImmutable));
182+ }
183+
164184 bool get hasSubclassInDefiningCompilationUnit {
165- var compilationUnit = library.definingCompilationUnit;
166- for (var cls in compilationUnit.classes) {
185+ for (var cls in library2.classes) {
167186 InterfaceType ? classType = cls.thisType;
168187 do {
169188 classType = classType? .superclass;
@@ -201,7 +220,7 @@ extension ClassElementExtension on ClassElement {
201220 }
202221
203222 // With only private non-factory constructors.
204- for (var constructor in constructors ) {
223+ for (var constructor in constructors2 ) {
205224 if (! constructor.isPrivate || constructor.isFactory) {
206225 return null ;
207226 }
@@ -211,8 +230,8 @@ extension ClassElementExtension on ClassElement {
211230
212231 // And 2 or more static const fields whose type is the enclosing class.
213232 var enumConstantCount = 0 ;
214- var enumConstants = < DartObject , Set <FieldElement >> {};
215- for (var field in fields ) {
233+ var enumConstants = < DartObject , Set <FieldElement2 >> {};
234+ for (var field in fields2 ) {
216235 // Ensure static const.
217236 if (field.isSynthetic || ! field.isConst || ! field.isStatic) {
218237 continue ;
@@ -238,29 +257,9 @@ extension ClassElementExtension on ClassElement {
238257 return EnumLikeClassDescription (enumConstants);
239258 }
240259
241- /// Returns whether this class is exactly [otherName] declared in
242- /// [otherLibrary] .
243- bool isClass (String otherName, String otherLibrary) =>
244- name == otherName && library.name == otherLibrary;
245-
246260 bool isEnumLikeClass () => asEnumLikeClass () != null ;
247261}
248262
249- extension ClassElementExtension2 on ClassElement2 {
250- bool get hasImmutableAnnotation {
251- var inheritedAndSelfElements = < InterfaceElement2 > [
252- ...allSupertypes.map ((t) => t.element3),
253- this ,
254- ];
255-
256- return inheritedAndSelfElements.any ((e) => e.metadata2.hasImmutable);
257-
258- // TODO(pq): update when implemented or replace w/ a better has{*} call
259- // https://github.com/dart-lang/linter/issues/4939
260- //return inheritedAndSelfElements.any((e) => e.augmented.metadata.any((e) => e.isImmutable));
261- }
262- }
263-
264263extension ClassMemberListExtension on List <ClassMember > {
265264 MethodDeclaration ? getMethod (String name) => whereType <MethodDeclaration >()
266265 .firstWhereOrNull ((node) => node.name.lexeme == name);
0 commit comments