@@ -47,18 +47,10 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
4747 super .visitPrefixedIdentifier (node);
4848
4949 final prefix = node.prefix;
50+ final name = node.identifier.name;
5051
51- if (_classPattern.hasMatch (prefix.name)) {
52- final staticElement = prefix.staticElement;
53- final name = node.identifier.name;
54-
55- if (staticElement is ClassElement ) {
56- _invocations.update (
57- staticElement,
58- (value) => value..add (name),
59- ifAbsent: () => {name},
60- );
61- }
52+ if (_matchIdentifier (prefix)) {
53+ _addMemberInvocation (prefix, name);
6254 }
6355 }
6456
@@ -85,12 +77,23 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
8577 _addMemberInvocation (classTarget as SimpleIdentifier , name);
8678 }
8779 } else if (_matchStaticGetter (target)) {
88- _addMemberInvocation ((target as PrefixedIdentifier ).prefix, name);
80+ final prefix = target as PrefixedIdentifier ;
81+ final classTarget = prefix.identifier;
82+
83+ if (_matchIdentifier (classTarget)) {
84+ _addMemberInvocation (classTarget, name);
85+ }
86+
87+ _addMemberInvocation (prefix.prefix, name);
8988 }
9089 }
9190
9291 bool _matchIdentifier (Expression ? target) =>
93- target is SimpleIdentifier && _classPattern.hasMatch (target.name);
92+ target is SimpleIdentifier &&
93+ (_classPattern.hasMatch (target.name) ||
94+ _classPattern.hasMatch (
95+ target.staticType? .getDisplayString (withNullability: false ) ?? '' ,
96+ ));
9497
9598 bool _matchConstructorOf (Expression ? target) =>
9699 target is InstanceCreationExpression &&
@@ -115,13 +118,23 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
115118 void _addMemberInvocation (SimpleIdentifier target, String name) {
116119 final staticElement = target.staticElement;
117120
118- if (staticElement is ClassElement ) {
119- _invocations.update (
120- staticElement,
121- (value) => value..add (name),
122- ifAbsent: () => {name},
123- );
121+ if (staticElement is VariableElement ) {
122+ final classElement = staticElement.type.element2;
123+ if (_classPattern.hasMatch (classElement? .name ?? '' )) {
124+ _tryAddInvocation (classElement, name);
125+ }
126+
127+ return ;
128+ } else if (staticElement is PropertyAccessorElement ) {
129+ final classElement = staticElement.type.returnType.element2;
130+ if (_classPattern.hasMatch (classElement? .name ?? '' )) {
131+ _tryAddInvocation (classElement, name);
132+ }
133+
134+ return ;
124135 }
136+
137+ _tryAddInvocation (staticElement, name);
125138 }
126139
127140 void _addMemberInvocationOnConstructor (
@@ -131,13 +144,7 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
131144 final staticElement =
132145 target.constructorName.staticElement? .enclosingElement3;
133146
134- if (staticElement is ClassElement ) {
135- _invocations.update (
136- staticElement,
137- (value) => value..add (name),
138- ifAbsent: () => {name},
139- );
140- }
147+ _tryAddInvocation (staticElement, name);
141148 }
142149
143150 void _addMemberInvocationOnAccessor (SimpleIdentifier target, String name) {
@@ -146,17 +153,21 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
146153
147154 for (final element in staticElement.accessors) {
148155 if (_classPattern.hasMatch (element.returnType.toString ())) {
149- final classElement = element.returnType.element2;
150-
151- if (classElement is ClassElement ) {
152- _invocations.update (
153- classElement,
154- (value) => value..add (name),
155- ifAbsent: () => {name},
156- );
157- break ;
158- }
156+ final declaredElement = element.returnType.element2;
157+
158+ _tryAddInvocation (declaredElement, name);
159+ break ;
159160 }
160161 }
161162 }
163+
164+ void _tryAddInvocation (Element ? element, String name) {
165+ if (element is ClassElement ) {
166+ _invocations.update (
167+ element,
168+ (value) => value..add (name),
169+ ifAbsent: () => {name},
170+ );
171+ }
172+ }
162173}
0 commit comments