Skip to content

Commit 12e648f

Browse files
Support analyzer 6.x in analyzer plugin
1 parent b3c0296 commit 12e648f

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ class ExhaustiveDeps extends DiagnosticContributor {
680680
// NamedType case. This is for references to generic type parameters
681681
// (references to other types will get filtered out by the isDeclaredInPureScope check above).
682682
(reference) {
683-
dependency = reference.name.name;
683+
dependency = reference.nameLexeme;
684684
// These aren't possible for type annotations.
685685
isStable = false;
686686
isUsedAsCascadeTarget = false;
@@ -1980,7 +1980,7 @@ _Recommendations collectRecommendations({
19801980
String? getConstructionExpressionType(Expression node) {
19811981
if (node is InstanceCreationExpression) {
19821982
if (node.isConst) return null;
1983-
return node.constructorName.type.name.name;
1983+
return node.constructorName.type.nameLexeme;
19841984
} else if (node is ListLiteral) {
19851985
return _DepType.list;
19861986
} else if (node is SetOrMapLiteral) {
@@ -2365,3 +2365,20 @@ extension<E extends Comparable<dynamic>> on Iterable<E> {
23652365
return true;
23662366
}
23672367
}
2368+
2369+
extension TypeNameHelper on NamedType {
2370+
// Backwards compatibility for various analyzer versions that remove name/name2.
2371+
// ignore: unnecessary_this
2372+
dynamic get name => this.name2; // Use `this.` to point to real impl if it exists, not extension.
2373+
// ignore: unnecessary_this
2374+
dynamic get name2 => this.name; // Use `this.` to point to real impl if it exists, not extension.
2375+
dynamic get _name => name;
2376+
2377+
String get nameLexeme {
2378+
final name = _name;
2379+
if (name is Identifier) return name.name;
2380+
if (name is Token) return name.lexeme;
2381+
if (name is String) return name;
2382+
throw UnimplementedError('Unexpected type for name: ${name.runtimeType}');
2383+
}
2384+
}

tools/analyzer_plugin/lib/src/diagnostic/visitors/non_static_reference_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool referencesImplicitThis(SimpleIdentifier identifier) {
7070
}
7171
// not a class member
7272
final Element? enclosingElement = element.enclosingElement;
73-
if (enclosingElement is! InterfaceOrAugmentationElement) {
73+
if (enclosingElement is! InterfaceElement) {
7474
return false;
7575
}
7676
// comment

tools/analyzer_plugin/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repository: https://github.com/Workiva/over_react/tree/master/tools/analyzer_plu
66
environment:
77
sdk: '>=2.19.0 <3.0.0'
88
dependencies:
9-
analyzer: ^5.11.0
9+
analyzer: '>=5.11.0 <7.0.0'
1010
analyzer_plugin: ^0.11.0
1111
collection: ^1.15.0-nullsafety.4
1212
meta: ^1.16.0

tools/analyzer_plugin/test/integration/stubs.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class StubServerPlugin implements ServerPlugin {
101101
handleEditGetRefactoring(parameters) => throw UnimplementedError();
102102

103103
@override
104+
// ignore: override_on_non_overriding_member
104105
handleKytheGetKytheEntries(parameters) => throw UnimplementedError();
105106

106107
@override

0 commit comments

Comments
 (0)