@@ -206,48 +206,40 @@ class _MethodExecuteVisitor extends RecursiveVisitor<void> {
206206
207207 @override
208208 void visitLibrary (Library library) {
209- String importUri = library.importUri.toString ();
210-
211- bool matches = false ;
212- int aopItemInfoListLen = _aopItemList.length;
213- for (int i = 0 ; i < aopItemInfoListLen && ! matches; i++ ) {
214- MethodItem aopItem = _aopItemList[i];
215- if ((aopItem.isRegex && RegExp (aopItem.importUri).hasMatch (importUri)) ||
216- (! aopItem.isRegex && importUri == aopItem.importUri)) {
217- matches = true ;
218- break ;
219- }
220- }
221- if (matches) {
222- library.visitChildren (this );
223- }
209+ library.visitChildren (this );
224210 }
225211
226212 @override
227213 void visitClass (Class node) {
228214 String clsName = node.name;
229215
230216 Library originalLibrary = node.enclosingLibrary;
217+
231218 if (node.isAnonymousMixin && node.isEliminatedMixin) {
232- print (
233- "[MethodAopTransformer] ${node .name } isAnonymousMixin:${originalLibrary .importUri .toString ()}}" );
219+ if (node.implementedTypes.isNotEmpty) {
220+ originalLibrary =
221+ node.implementedTypes.first.classNode.enclosingLibrary;
222+ clsName = node.implementedTypes.first.classNode.name;
223+ }
224+ //print(
225+ // "[MethodAopTransformer] visitClass isAnonymousMixin ${node.name} ${originalLibrary.importUri.toString()}}");
234226 }
235227 bool matches = false ;
236228 int aopItemInfoListLen = _aopItemList.length;
237229 for (int i = 0 ; i < aopItemInfoListLen && ! matches; i++ ) {
238230 MethodItem aopItem = _aopItemList[i];
239231
240- if ((aopItem.isRegex && RegExp (aopItem.clsName).hasMatch (clsName)) ||
241- (! aopItem.isRegex && clsName == aopItem.clsName) &&
242- originalLibrary.importUri.toString () == aopItem.importUri) {
232+ if ((( aopItem.isRegex && RegExp (aopItem.clsName).hasMatch (clsName)) ||
233+ (! aopItem.isRegex && clsName == aopItem.clsName) ) &&
234+ originalLibrary.importUri.toString () == aopItem.importUri) {
243235 matches = true ;
244236 break ;
245237 }
246238 }
247239
248240 if (matches) {
249241 print (
250- "[MethodAopTransformer] visitClass match ${node . parent . runtimeType . toString () } ${node .name }" );
242+ "[MethodAopTransformer] visitClass match ${originalLibrary . importUri } ${node .name }" );
251243 node.visitChildren (this );
252244 }
253245 }
@@ -283,7 +275,7 @@ class _MethodExecuteVisitor extends RecursiveVisitor<void> {
283275 if (node.parent is Class ) {
284276 needCompareClass = true ;
285277 originalClass = node.parent as Class ;
286- originalLibrary = originalClass .enclosingLibrary;
278+ originalLibrary = node .enclosingLibrary;
287279 }
288280
289281 String ? clsName = null ;
@@ -293,6 +285,20 @@ class _MethodExecuteVisitor extends RecursiveVisitor<void> {
293285 importUri = originalLibrary? .importUri.toString ();
294286 }
295287
288+ if (needCompareClass &&
289+ originalClass != null &&
290+ originalClass.isAnonymousMixin &&
291+ originalClass.isEliminatedMixin) {
292+ if (originalClass.implementedTypes.isNotEmpty) {
293+ clsName = originalClass.implementedTypes.first.classNode.name;
294+ importUri = originalClass
295+ .implementedTypes.first.classNode.enclosingLibrary.importUri
296+ .toString ();
297+ //print(
298+ // "[MethodAopTransformer] visitProcedure isAnonymousMixin so transform it clasName[${originalClass.name} to $clsName] importUri[${originalLibrary?.importUri.toString()} to $importUri]");
299+ }
300+ }
301+
296302 MethodItem ? matchedAopItem = null ;
297303 int aopItemInfoListLen = _aopItemList.length;
298304 for (int i = 0 ; i < aopItemInfoListLen && matchedAopItem == null ; i++ ) {
@@ -316,7 +322,17 @@ class _MethodExecuteVisitor extends RecursiveVisitor<void> {
316322 }
317323 }
318324 if (matchedAopItem == null ) {
325+ if ((originalClass? .isAnonymousMixin ?? false ) &&
326+ (originalClass? .isEliminatedMixin ?? false )) {
327+ //print(
328+ // "[MethodAopTransformer] visitProcedure isAnonymousMixin so transform it clasName[${originalClass?.name} to $clsName] importUri[${originalLibrary?.importUri.toString()} to $importUri]");
329+ //print(
330+ // "[MethodAopTransformer] visitProcedure notMatch ${originalLibrary?.importUri.toString()}|${originalClass?.name}|$procedureName");
331+ }
319332 return ;
333+ } else {
334+ print (
335+ "[MethodAopTransformer] visitProcedure match ${originalLibrary ?.importUri .toString ()}|${originalClass ?.name }|$procedureName " );
320336 }
321337
322338 try {
@@ -329,20 +345,20 @@ class _MethodExecuteVisitor extends RecursiveVisitor<void> {
329345 node.parent? .parent as Library , matchedAopItem, node);
330346 } else {
331347 print (
332- "[MethodAopTransformer] error ${node .parent .runtimeType .toString ()} ${node .name .text }" );
348+ "[MethodAopTransformer] visitProcedure error ${node .parent .runtimeType .toString ()} ${node .name .text }" );
333349 }
334350 } else {
335351 if (node.parent != null ) {
336352 transformInstanceMethodProcedure (
337353 node.parent? .parent as Library , matchedAopItem, node);
338354 } else {
339355 print (
340- "[MethodAopTransformer] error node.parent == null ${node .name .text }" );
356+ "[MethodAopTransformer] visitProcedure error node.parent == null ${node .name .text }" );
341357 }
342358 }
343359 } catch (error, stack) {
344360 print (
345- "[MethodAopTransformer] ${error .toString ()} \n ${stack .toString ()}" );
361+ "[MethodAopTransformer] visitProcedure ${error .toString ()} \n ${stack .toString ()}" );
346362 }
347363 }
348364
0 commit comments