Skip to content

Commit

Permalink
Version 3.3.0-16.0.dev
Browse files Browse the repository at this point in the history
Merge 0493c44 into dev
  • Loading branch information
Dart CI committed Oct 12, 2023
2 parents 9afac39 + 0493c44 commit 34c06f0
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 58 deletions.
13 changes: 1 addition & 12 deletions pkg/analyzer/lib/src/error/best_practices_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -929,23 +929,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
/// its superclasses, reporting a warning if any non-final instance fields are
/// found.
void _checkForImmutable(NamedCompilationUnitMember node) {
/// Return `true` if the given class [element] is annotated with the
/// `@immutable` annotation.
bool isImmutable(InterfaceElement element) {
for (ElementAnnotation annotation in element.metadata) {
if (annotation.isImmutable) {
return true;
}
}
return false;
}

/// Return `true` if the given class [element] or any superclass of it is
/// annotated with the `@immutable` annotation.
bool isOrInheritsImmutable(
InterfaceElement element, Set<InterfaceElement> visited) {
if (visited.add(element)) {
if (isImmutable(element)) {
if (element.hasImmutable) {
return true;
}
for (InterfaceType interface in element.mixins) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ class C {
''';

/// The name of the top-level variable used to mark a immutable class.
String _immutableVarName = 'immutable';

/// The name of `meta` library, used to define analysis annotations.
String _metaLibName = 'meta';

bool _isImmutable(Element? element) =>
element is PropertyAccessorElement &&
element.name == _immutableVarName &&
element.library.name == _metaLibName;

class AvoidEqualsAndHashCodeOnMutableClasses extends LintRule {
static const LintCode code = LintCode(
'avoid_equals_and_hash_code_on_mutable_classes',
Expand Down Expand Up @@ -124,9 +113,6 @@ class _Visitor extends SimpleAstVisitor<void> {
...clazz.allSupertypes.map((t) => t.element),
clazz,
];
var inheritedAndSelfAnnotations = inheritedAndSelfElements
.expand((c) => c.metadata)
.map((m) => m.element);
return inheritedAndSelfAnnotations.any(_isImmutable);
return inheritedAndSelfElements.any((e) => e.hasImmutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ class A {
''';

/// The name of the top-level variable used to mark a immutable class.
String _immutableVarName = 'immutable';

/// The name of `meta` library, used to define analysis annotations.
String _metaLibName = 'meta';

bool _isImmutable(Element? element) =>
element is PropertyAccessorElement &&
element.name == _immutableVarName &&
element.library.name == _metaLibName;

class PreferConstConstructorsInImmutables extends LintRule {
static const LintCode code = LintCode(
'prefer_const_constructors_in_immutables',
Expand Down Expand Up @@ -128,10 +117,7 @@ class _Visitor extends SimpleAstVisitor<void> {
/// `@immutable`.
bool _hasImmutableAnnotation(InterfaceElement clazz) {
var selfAndInheritedClasses = _getSelfAndSuperClasses(clazz);
for (var cls in selfAndInheritedClasses) {
if (cls.metadata.any((m) => _isImmutable(m.element))) return true;
}
return false;
return selfAndInheritedClasses.any((cls) => cls.hasImmutable);
}

static List<InterfaceElement> _getSelfAndSuperClasses(InterfaceElement self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';

import '../analyzer.dart';
Expand Down Expand Up @@ -36,17 +35,6 @@ A a2 = new A(const {});
''';

/// The name of the top-level variable used to mark a immutable class.
String _immutableVarName = 'immutable';

/// The name of `meta` library, used to define analysis annotations.
String _metaLibName = 'meta';

bool _isImmutable(Element? element) =>
element is PropertyAccessorElement &&
element.name == _immutableVarName &&
element.library.name == _metaLibName;

class PreferConstLiteralsToCreateImmutables extends LintRule {
static const LintCode code = LintCode(
'prefer_const_literals_to_create_immutables',
Expand Down Expand Up @@ -122,9 +110,7 @@ class _Visitor extends SimpleAstVisitor<void> {

InterfaceType? current = type;
while (current != null) {
for (var annotation in current.element.metadata) {
if (_isImmutable(annotation.element)) return true;
}
if (current.element.hasImmutable) return true;
current = current.superclass;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 3
PATCH 0
PRERELEASE 15
PRERELEASE 16
PRERELEASE_PATCH 0

0 comments on commit 34c06f0

Please sign in to comment.