@@ -11,6 +11,8 @@ class _ConstVisitor extends RecursiveVisitor<void> {
1111 this .kernelFilePath,
1212 this .classLibraryUri,
1313 this .className,
14+ this .annotationClassLibraryUri,
15+ this .annotationClassName,
1416 ) : _visitedInstances = < String > {},
1517 constantInstances = < Map <String , dynamic >> [],
1618 nonConstantLocations = < Map <String , dynamic >> [];
@@ -30,6 +32,14 @@ class _ConstVisitor extends RecursiveVisitor<void> {
3032
3133 bool inIgnoredClass = false ;
3234
35+ /// The name of the name of the class of the annotation marking classes
36+ /// whose constant references should be ignored.
37+ final String ? annotationClassName;
38+
39+ /// The library URI of the class of the annotation marking classes whose
40+ /// constant references should be ignored.
41+ final String ? annotationClassLibraryUri;
42+
3343 // A cache of previously evaluated classes.
3444 static final Map <Class , bool > _classHeirarchyCache = < Class , bool > {};
3545 bool _matches (Class node) {
@@ -76,27 +86,27 @@ class _ConstVisitor extends RecursiveVisitor<void> {
7686
7787 @override
7888 void visitClass (Class node) {
79- // Check if this is a class that we should ignore.
80- if (! _isStaticIconProvider (node)) {
81- // Not an ignored class.
82- super .visitClass (node);
83- return ;
84- }
85- inIgnoredClass = true ;
89+ // check if this is a class that we should ignore
90+ inIgnoredClass = _classShouldBeIgnored (node);
8691 super .visitClass (node);
8792 inIgnoredClass = false ;
8893 }
8994
90- // Constants from classes annotated with an instance of StaticIconProvider
91- // should be ignored.
92- bool _isStaticIconProvider (Class node) {
95+ // If any annotations on the class match annotationClassName AND
96+ // annotationClassLibraryUri.
97+ bool _classShouldBeIgnored (Class node) {
98+ if (annotationClassName == null || annotationClassLibraryUri == null ) {
99+ return false ;
100+ }
93101 return node.annotations.any ((Expression expression) {
94102 if (expression is ! ConstantExpression ) {
95103 return false ;
96104 }
97105
98- final DartType type = expression.type;
99- return type is InterfaceType && type.classNode.name == 'StaticIconProvider' ;
106+ final Constant constant = expression.constant;
107+ return constant is InstanceConstant
108+ && constant.classNode.name == annotationClassName
109+ && constant.classNode.enclosingLibrary.importUri.toString () == annotationClassLibraryUri;
100110 });
101111 }
102112
@@ -131,10 +141,14 @@ class ConstFinder {
131141 required String kernelFilePath,
132142 required String classLibraryUri,
133143 required String className,
144+ String ? annotationClassLibraryUri,
145+ String ? annotationClassName,
134146 }) : _visitor = _ConstVisitor (
135147 kernelFilePath,
136148 classLibraryUri,
137149 className,
150+ annotationClassLibraryUri,
151+ annotationClassName,
138152 );
139153
140154 final _ConstVisitor _visitor;
0 commit comments