1 22 package org.jboss.aop.pointcut; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.Field ; 26 import java.lang.reflect.Method ; 27 import java.lang.reflect.Modifier ; 28 import java.util.ArrayList ; 29 import java.util.HashMap ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 33 import javassist.ClassPool; 34 import javassist.CtClass; 35 import javassist.CtConstructor; 36 import javassist.CtField; 37 import javassist.CtMethod; 38 import javassist.NotFoundException; 39 40 import org.jboss.aop.Advisor; 41 import org.jboss.aop.AspectManager; 42 import org.jboss.aop.annotation.AnnotationElement; 43 import org.jboss.aop.annotation.PortableAnnotationElement; 44 import org.jboss.aop.introduction.InterfaceIntroduction; 45 import org.jboss.aop.pointcut.ast.ASTAttribute; 46 import org.jboss.aop.pointcut.ast.ASTConstructor; 47 import org.jboss.aop.pointcut.ast.ASTException; 48 import org.jboss.aop.pointcut.ast.ASTField; 49 import org.jboss.aop.pointcut.ast.ASTMethod; 50 import org.jboss.aop.pointcut.ast.ASTParameter; 51 import org.jboss.aop.pointcut.ast.ClassExpression; 52 import org.jboss.aop.util.JavassistMethodHashing; 53 import org.jboss.aop.util.MethodHashing; 54 55 61 public class Util 62 { 63 public static boolean matchesClassExpr(ClassExpression classExpr, CtClass clazz, Advisor advisor) 64 { 65 try 66 { 67 if (classExpr.isAnnotation()) 68 { 69 String sub = classExpr.getOriginal().substring(1); 70 if (advisor != null) 71 { 72 if (advisor.getClassMetaData().hasTag(sub)) return true; 73 return advisor.hasAnnotation(clazz, sub); 74 } 75 else 76 { 77 return AnnotationElement.isAnyAnnotationPresent(clazz, sub); 78 } 79 } 80 else if (classExpr.isInstanceOf()) 81 { 82 return Util.subtypeOf(clazz, classExpr, advisor); 83 } 84 else if (classExpr.isTypedef()) 85 { 86 return Util.matchesTypedef(clazz, classExpr, advisor); 87 } 88 else 89 { 90 return classExpr.matches(clazz.getName()); 91 } 92 } 93 catch (Exception e) 94 { 95 throw new RuntimeException (e); } 97 98 } 99 100 public static boolean matchesClassExpr(ClassExpression classExpr, Class clazz) 101 { 102 return matchesClassExpr(classExpr, clazz, null); 103 } 104 105 public static boolean matchesClassExpr(ClassExpression classExpr, Class clazz, Advisor advisor) 106 { 107 try 108 { 109 if (classExpr.isAnnotation()) 110 { 111 String sub = classExpr.getOriginal().substring(1); 112 if (advisor != null) 113 { 114 if (advisor.getClassMetaData().hasTag(sub)) return true; 115 return advisor.hasAnnotation(clazz, sub); 116 } 117 else 118 { 119 return AnnotationElement.isAnyAnnotationPresent(clazz, sub); 120 } 121 } 122 else if (classExpr.isInstanceOf()) 123 { 124 return Util.subtypeOf(clazz, classExpr, advisor); 125 } 126 else if (classExpr.isTypedef()) 127 { 128 return Util.matchesTypedef(clazz, classExpr, advisor); 129 } 130 else 131 { 132 return(classExpr.matches(clazz.getName())); 133 } 134 } 135 catch (Exception e) 136 { 137 throw new RuntimeException (e); } 139 140 } 141 142 146 public static boolean methodExistsInSuperClassOrInterface(Method method, ClassExpression target, boolean exactSuper, Advisor advisor) throws Exception 147 { 148 long hash = MethodHashing.calculateHash(method); 149 boolean exists = methodExistsInSuperClassOrInterface(hash, target, method.getDeclaringClass(), exactSuper); 150 if (!exists) 151 { 152 exists = checkMethodExistsInIntroductions(hash, target, exactSuper, advisor); 153 } 154 return exists; 155 } 156 157 private static boolean methodExistsInSuperClassOrInterface(long hash, ClassExpression expr, Class clazz, boolean exactSuper) throws Exception 158 { 159 if (clazz == null) return false; 160 161 if (expr.isAnnotation()) 162 { 163 String sub = expr.getOriginal().substring(1); 164 if (AnnotationElement.isAnyAnnotationPresent(clazz, sub)) 165 { 166 if (classHasMethod(clazz, hash, exactSuper)) return true; 167 } 168 } 169 else if (expr.matches(clazz.getName())) 170 { 171 if (classHasMethod(clazz, hash, exactSuper)) return true; 172 } 173 174 Class [] interfaces = clazz.getInterfaces(); 175 for (int i = 0; i < interfaces.length; i++) 176 { 177 if (methodExistsInSuperClassOrInterface(hash, expr, interfaces[i], exactSuper)) return true; 178 } 179 180 if (clazz.isInterface()) return false; 182 return methodExistsInSuperClassOrInterface(hash, expr, clazz.getSuperclass(), exactSuper); 183 } 184 185 189 private static boolean checkMethodExistsInIntroductions(long hash, ClassExpression target, boolean exactSuper, Advisor advisor) throws Exception 190 { 191 if (advisor != null) 192 { 193 ArrayList intros = advisor.getInterfaceIntroductions(); 194 if (intros.size() > 0) 195 { 196 ClassLoader tcl = Thread.currentThread().getContextClassLoader(); 197 ClassPool pool = advisor.getManager().findClassPool(tcl); 198 HashSet doneClasses = new HashSet (); 199 for (Iterator it = intros.iterator() ; it.hasNext() ; ) 200 { 201 InterfaceIntroduction intro = (InterfaceIntroduction)it.next(); 202 String [] ifs = intro.getInterfaces(); 203 for (int i = 0 ; ifs != null && i < ifs.length ; i++) 204 { 205 if (!doneClasses.contains(ifs[i])) 206 { 207 doneClasses.add(ifs[i]); 208 if (methodExistsInSuperClassOrInterface(pool, hash, target, ifs[i], exactSuper)) return true; 209 } 210 } 211 212 ArrayList mixins = intro.getMixins(); 213 if (mixins != null && mixins.size() > 0) 214 { 215 for (Iterator mit = mixins.iterator() ; mit.hasNext() ; ) 216 { 217 InterfaceIntroduction.Mixin mixin = (InterfaceIntroduction.Mixin)mit.next(); 218 String [] mifs = mixin.getInterfaces(); 219 for (int i = 0 ; mifs != null && i < mifs.length ; i++) 220 { 221 if (!doneClasses.contains(mifs[i])) 222 { 223 doneClasses.add(mifs[i]); 224 if (methodExistsInSuperClassOrInterface(pool, hash, target, mifs[i], exactSuper)) return true; 225 } 226 } 227 } 228 } 229 } 230 } 231 } 232 return false; 233 } 234 235 private static boolean classHasMethod(Class clazz, long hash, boolean exactSuper)throws Exception 236 { 237 Method m = MethodHashing.findMethodByHash(clazz, hash); 238 if (m != null) 239 { 240 if (exactSuper) 241 { 242 return clazz == m.getDeclaringClass(); 244 } 245 else 246 { 247 return true; 248 } 249 } 250 251 return false; 252 } 253 254 258 public static boolean methodExistsInSuperClassOrInterface(CtMethod method, ClassExpression target, boolean exactSuper) throws Exception 259 { 260 long hash = JavassistMethodHashing.methodHash(method); 261 return methodExistsInSuperClassOrInterface(hash, target, method.getDeclaringClass(), exactSuper); 262 } 263 264 private static boolean methodExistsInSuperClassOrInterface(ClassPool pool, long hash, ClassExpression expr, String className, boolean exactSuper) throws Exception 265 { 266 CtClass clazz = pool.get(className); 267 HashMap map = JavassistMethodHashing.getMethodMap(clazz); 268 return methodExistsInSuperClassOrInterface(hash, expr, clazz, exactSuper); 269 } 270 271 private static boolean methodExistsInSuperClassOrInterface(long hash, ClassExpression expr, CtClass clazz, boolean exactSuper) throws Exception 272 { 273 if (clazz == null) return false; 274 275 if (expr.isAnnotation()) 276 { 277 String sub = expr.getOriginal().substring(1); 278 if (AnnotationElement.isAnyAnnotationPresent(clazz, sub)) 279 { 280 if (classHasMethod(clazz, hash, exactSuper)) return true; 281 } 282 } 283 else if (expr.matches(clazz.getName())) 284 { 285 if (classHasMethod(clazz, hash, exactSuper)) return true; 286 } 287 288 CtClass[] interfaces = clazz.getInterfaces(); 289 for (int i = 0; i < interfaces.length; i++) 290 { 291 if (methodExistsInSuperClassOrInterface(hash, expr, interfaces[i], exactSuper)) return true; 292 } 293 if (clazz.isInterface()) return false; 295 return methodExistsInSuperClassOrInterface(hash, expr, clazz.getSuperclass(), exactSuper); 296 } 297 298 private static boolean classHasMethod(CtClass clazz, long hash, boolean exactSuper)throws Exception 299 { 300 HashMap methods = JavassistMethodHashing.getMethodMap(clazz); 301 CtMethod m = (CtMethod)methods.get(new Long (hash)); 302 if (m != null) 303 { 304 if (exactSuper) 305 { 306 return clazz == m.getDeclaringClass(); 308 } 309 else 310 { 311 return true; 312 } 313 } 314 315 if (clazz.isInterface() && !exactSuper) 316 { 317 CtClass[] interfaces = clazz.getInterfaces(); 318 for (int i = 0 ; i < interfaces.length ; i++) 319 { 320 if (classHasMethod(interfaces[i], hash, exactSuper)) return true; 321 } 322 } 323 return false; 324 } 325 326 public static boolean subtypeOf(CtClass clazz, ClassExpression instanceOf, Advisor advisor) 327 { 328 try 329 { 330 if (clazz == null) return false; 331 if (instanceOf.isInstanceOfAnnotated()) 332 { 333 if (clazz.isPrimitive()) return false; 334 String sub = instanceOf.getInstanceOfAnnotation().substring(1); 335 if (PortableAnnotationElement.isAnyAnnotationPresent(clazz, sub)) return true; 336 } 337 else if (instanceOf.matches(clazz.getName())) 338 { 339 return true; 340 } 341 CtClass[] interfaces = clazz.getInterfaces(); 342 for (int i = 0; i < interfaces.length; i++) 343 { 344 if (subtypeOf(interfaces[i], instanceOf, advisor)) return true; 345 } 346 if (clazz.isInterface()) return false; 348 if (checkIntroductions(clazz, instanceOf, advisor)) 349 { 350 return true; 351 } 352 353 return subtypeOf(clazz.getSuperclass(), instanceOf, advisor); 354 } 355 catch (Exception e) 356 { 357 throw new RuntimeException (e); 358 } 359 } 360 361 private static boolean checkIntroductions(CtClass clazz, ClassExpression instanceOf, Advisor advisor) 362 { 363 try 364 { 365 if (advisor != null) 366 { 367 ArrayList intros = advisor.getInterfaceIntroductions(); 368 if (intros.size() > 0) 369 { 370 for (Iterator itIntro = intros.iterator() ; itIntro.hasNext() ; ) 371 { 372 InterfaceIntroduction intro = (InterfaceIntroduction)itIntro.next(); 373 String [] introductions = intro.getInterfaces(); 374 if (introductions != null) 375 { 376 for (int i = 0 ; i < introductions.length ; i++) 377 { 378 Class iface = Thread.currentThread().getContextClassLoader().loadClass(introductions[i]); 379 if (subtypeOf(iface, instanceOf, advisor)) return true; 380 } 381 } 382 ArrayList mixins = intro.getMixins(); 383 if (mixins.size() > 0) 384 { 385 for (Iterator itMixin = mixins.iterator() ; itMixin.hasNext() ; ) 386 { 387 InterfaceIntroduction.Mixin mixin = (InterfaceIntroduction.Mixin)itMixin.next(); 388 String [] mixinInterfaces = mixin.getInterfaces(); 389 if (mixinInterfaces != null) 390 { 391 for (int i = 0 ; i < mixinInterfaces.length ; i++) 392 { 393 Class iface = Thread.currentThread().getContextClassLoader().loadClass(mixinInterfaces[i]); 394 if (subtypeOf(iface, instanceOf, advisor)) return true; 395 } 396 } 397 } 398 } 399 } 400 } 401 } 402 } 403 catch (ClassNotFoundException e) 404 { 405 throw new RuntimeException (e); 406 } 407 408 return false; 409 } 410 411 public static boolean subtypeOf(Class clazz, ClassExpression instanceOf, Advisor advisor) 412 { 413 return MatcherStrategy.getMatcher(advisor).subtypeOf(clazz, instanceOf, advisor); 414 } 415 416 public static boolean has(CtClass target, ASTMethod method, Advisor advisor) 417 { 418 return has(target, method, advisor, true); 419 } 420 421 public static boolean has(CtClass target, ASTMethod method, Advisor advisor, boolean checkSuper) 422 { 423 try 424 { 425 CtMethod[] methods = target.getDeclaredMethods(); 426 for (int i = 0; i < methods.length; i++) 427 { 428 MethodMatcher matcher = new MethodMatcher(advisor, methods[i], null); 429 if (matcher.matches(method).booleanValue()) return true; 430 } 431 432 if (checkSuper) 433 { 434 CtClass superClass = target.getSuperclass(); 435 if (superClass != null) return has(superClass, method, advisor, checkSuper); 436 } 437 } 438 catch (NotFoundException e) 439 { 440 throw new RuntimeException (e); } 442 return false; 443 } 444 445 public static boolean has(CtClass target, ASTField field, Advisor advisor) 446 { 447 return has(target, field, advisor, true); 448 } 449 450 public static boolean has(CtClass target, ASTField field, Advisor advisor, boolean checkSuper) 451 { 452 try 453 { 454 CtField[] fields = target.getDeclaredFields(); 455 for (int i = 0; i < fields.length; i++) 456 { 457 FieldGetMatcher matcher = new FieldGetMatcher(advisor, fields[i], null); 458 if (((Boolean ) field.jjtAccept(matcher, null)).booleanValue()) return true; 459 } 460 461 if (checkSuper) 462 { 463 CtClass superClass = target.getSuperclass(); 464 if (superClass != null) return has(superClass, field, advisor, checkSuper); 465 } 466 } 467 catch (NotFoundException e) 468 { 469 throw new RuntimeException (e); } 471 return false; 472 } 473 474 public static boolean has(CtClass target, ASTConstructor con, Advisor advisor) 475 { 476 try 477 { 478 CtConstructor[] cons = target.getDeclaredConstructors(); 479 for (int i = 0; i < cons.length; i++) 480 { 481 ConstructorMatcher matcher = new ConstructorMatcher(advisor, cons[i], null); 482 if (matcher.matches(con).booleanValue()) return true; 483 } 484 } 485 catch (NotFoundException e) 486 { 487 throw new RuntimeException (e); } 489 return false; 490 } 491 492 public static boolean has(Class target, ASTMethod method, Advisor advisor) 493 { 494 return has(target, method, advisor, true); 495 } 496 497 public static boolean has(Class target, ASTMethod method, Advisor advisor, boolean checkSuper) 498 { 499 Method [] methods = advisor.getAllMethods(); 500 if (methods == null) 501 methods = target.getDeclaredMethods(); 502 for (int i = 0; i < methods.length; i++) 503 { 504 MethodMatcher matcher = new MethodMatcher(advisor, methods[i], null); 505 if (matcher.matches(method).booleanValue()) return true; 506 } 507 508 if (checkSuper) 509 { 510 Class superClass = target.getSuperclass(); 511 if (superClass != null) return has(superClass, method, advisor, checkSuper); 512 } 513 return false; 514 } 515 516 public static boolean has(Class target, ASTField field, Advisor advisor) 517 { 518 return has(target, field, advisor, true); 519 } 520 521 public static boolean has(Class target, ASTField field, Advisor advisor, boolean checkSuper) 522 { 523 Field [] fields = target.getDeclaredFields(); 524 for (int i = 0; i < fields.length; i++) 525 { 526 FieldGetMatcher matcher = new FieldGetMatcher(advisor, fields[i], null); 527 if (((Boolean ) field.jjtAccept(matcher, null)).booleanValue()) return true; 528 } 529 530 if (checkSuper) 531 { 532 Class superClass = target.getSuperclass(); 533 if (superClass != null) return has(superClass, field, advisor, checkSuper); 534 } 535 return false; 536 } 537 538 public static boolean has(Class target, ASTConstructor con, Advisor advisor) 539 { 540 Constructor [] cons = target.getDeclaredConstructors(); 541 for (int i = 0; i < cons.length; i++) 542 { 543 ConstructorMatcher matcher = new ConstructorMatcher(advisor, cons[i], null); 544 if (matcher.matches(con).booleanValue()) return true; 545 } 546 return false; 547 } 548 549 public static boolean matchesTypedef(CtClass clazz, ClassExpression classExpr, Advisor advisor) 550 { 551 String original = classExpr.getOriginal(); 552 String typedefName = original.substring("$typedef{".length(), original.lastIndexOf("}")); 553 AspectManager manager = (advisor != null) ? advisor.getManager() : AspectManager.instance(); 554 Typedef typedef = manager.getTypedef(typedefName); 555 if (typedef == null) return false; 556 return typedef.matches(advisor, clazz); 557 } 558 559 public static boolean matchesTypedef(Class clazz, ClassExpression classExpr, Advisor advisor) 560 { 561 String original = classExpr.getOriginal(); 562 String typedefName = original.substring("$typedef{".length(), original.lastIndexOf("}")); 563 AspectManager manager = (advisor != null) ? advisor.getManager() : AspectManager.instance(); 564 Typedef typedef = manager.getTypedef(typedefName); 565 if (typedef == null) return false; 566 return typedef.matches(advisor, clazz); 567 } 568 569 public static boolean matchModifiers(ASTAttribute need, int have) 570 { 571 if (Modifier.isAbstract(need.attribute) && need.not) return !Modifier.isAbstract(have); 572 if (Modifier.isAbstract(need.attribute) && !need.not) return Modifier.isAbstract(have); 573 if (Modifier.isFinal(need.attribute) && need.not) return !Modifier.isFinal(have); 574 if (Modifier.isFinal(need.attribute) && !need.not) return Modifier.isFinal(have); 575 if (Modifier.isInterface(need.attribute) && need.not) return !Modifier.isInterface(have); 576 if (Modifier.isInterface(need.attribute) && !need.not) return Modifier.isInterface(have); 577 if (Modifier.isNative(need.attribute) && need.not) return !Modifier.isNative(have); 578 if (Modifier.isNative(need.attribute) && !need.not) return Modifier.isNative(have); 579 if (Modifier.isPrivate(need.attribute) && need.not) return !Modifier.isPrivate(have); 580 if (Modifier.isPrivate(need.attribute) && !need.not) return Modifier.isPrivate(have); 581 if (Modifier.isProtected(need.attribute) && need.not) return !Modifier.isProtected(have); 582 if (Modifier.isProtected(need.attribute) && !need.not) return Modifier.isProtected(have); 583 if (Modifier.isPublic(need.attribute) && need.not) return !Modifier.isPublic(have); 584 if (Modifier.isPublic(need.attribute) && !need.not) return Modifier.isPublic(have); 585 if (Modifier.isStatic(need.attribute) && need.not) return !Modifier.isStatic(have); 586 if (Modifier.isStatic(need.attribute) && !need.not) return Modifier.isStatic(have); 587 if (Modifier.isStrict(need.attribute) && need.not) return !Modifier.isStrict(have); 588 if (Modifier.isStrict(need.attribute) && !need.not) return Modifier.isStrict(have); 589 if (Modifier.isSynchronized(need.attribute) && need.not) return !Modifier.isSynchronized(have); 590 if (Modifier.isSynchronized(need.attribute) && !need.not) return Modifier.isSynchronized(have); 591 if (Modifier.isTransient(need.attribute) && need.not) return !Modifier.isTransient(have); 592 if (Modifier.isTransient(need.attribute) && !need.not) return Modifier.isTransient(have); 593 if (Modifier.isVolatile(need.attribute) && need.not) return !Modifier.isVolatile(have); 594 if (Modifier.isVolatile(need.attribute) && !need.not) return Modifier.isVolatile(have); 595 596 return true; 597 } 598 599 603 public static boolean matchExceptions(ArrayList nodeExceptions, CtClass[] foundExceptions) 604 { 605 if (nodeExceptions.size() > foundExceptions.length) return false; 606 for (Iterator it = nodeExceptions.iterator(); it.hasNext();) 607 { 608 boolean found = false; 609 ASTException ex = (ASTException) it.next(); 610 for (int i = 0; i < foundExceptions.length; i++) 611 { 612 if (ex.getType().matches(foundExceptions[i].getName())) 613 { 614 found = true; 615 break; 616 } 617 } 618 619 if (!found) return false; 620 } 621 622 return true; 623 } 624 625 629 public static boolean matchExceptions(ArrayList nodeExceptions, Class [] foundExceptions) 630 { 631 if (nodeExceptions.size() > foundExceptions.length) return false; 632 for (Iterator it = nodeExceptions.iterator(); it.hasNext();) 633 { 634 boolean found = false; 635 ASTException ex = (ASTException) it.next(); 636 for (int i = 0; i < foundExceptions.length; i++) 637 { 638 if (ex.getType().matches(foundExceptions[i].getName())) 639 { 640 found = true; 641 break; 642 } 643 } 644 645 if (!found) return false; 646 } 647 648 return true; 649 } 650 651 public static boolean matchesParameters(Advisor advisor, ASTMethod node, CtMethod ctMethod) 652 { 653 if (node.isAnyParameters()) return true; 654 try 655 { 656 return Util.matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), ctMethod.getParameterTypes()); 657 } 658 catch (NotFoundException e) 659 { 660 throw new RuntimeException (e); 662 } 663 } 664 665 public static boolean matchesParameters(Advisor advisor, ASTConstructor node, CtConstructor ctConstructor) 666 { 667 int i = 0; 668 if (node.isAnyParameters()) return true; 669 try 670 { 671 CtClass[] params = ctConstructor.getParameterTypes(); 672 return Util.matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), params); 673 } 674 catch (NotFoundException e) 675 { 676 throw new RuntimeException (e); 678 } 679 } 680 681 public static boolean matchesParameters(Advisor advisor, ASTMethod node, Method method) 682 { 683 if (node.isAnyParameters()) return true; 684 return matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), method.getParameterTypes()); 685 } 686 687 public static boolean matchesParameters(Advisor advisor, ASTConstructor node, Constructor con) 688 { 689 if (node.isAnyParameters()) return true; 690 691 Class [] params = con.getParameterTypes(); 692 693 return matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), con.getParameterTypes()); 694 } 695 696 private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList parameters, Class [] params) 697 { 698 RefParameterMatcher matcher = new RefParameterMatcher(advisor, parameters, params); 699 return matcher.matches(); 700 } 701 702 private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList parameters, CtClass[] params) 703 { 704 CtParameterMatcher matcher = new CtParameterMatcher(advisor, parameters, params); 705 return matcher.matches(); 706 } 707 708 private static class ParameterMatcher 709 { 710 Advisor advisor; 711 ArrayList astParameters; 712 final long paramsLength; 713 int asti; 714 int actuali; 715 716 ParameterMatcher(Advisor advisor, ArrayList parameters, Object [] params) 717 { 718 this.advisor = advisor; 719 this.astParameters = parameters; 720 paramsLength = params.length; 721 } 722 723 boolean matches() 724 { 725 return matches(0, 0); 726 } 727 728 private boolean matches(int ast, int actual) 729 { 730 boolean match = true; 731 for ( ; match && ast < astParameters.size() && actual < paramsLength ; ast++) 732 { 733 if (isAnyZeroOrMoreParameters(ast)) 734 { 735 asti = ast; 736 actuali = actual; 737 match = wildcard(); ast = asti; 739 actual = actuali; 740 ast--; 741 } 742 else 743 { 744 match = doMatch(ast, actual); 745 actual++; 746 } 747 } 748 749 while (match && ast < astParameters.size() && isAnyZeroOrMoreParameters(ast)) 750 { 751 ast++; 752 } 753 return (match && ast == astParameters.size() && paramsLength == actual); 754 } 755 756 private boolean isAnyZeroOrMoreParameters(int index) 757 { 758 return ((ASTParameter)astParameters.get(index)).isAnyZeroOrMoreParameters(); 759 } 760 761 boolean doMatch(int astIndex, int actualIndex) 762 { 763 return false; 765 } 766 767 private boolean wildcard() 768 { 769 boolean match = true; 770 asti++; 771 772 while (actuali < paramsLength && asti < astParameters.size() && isAnyZeroOrMoreParameters(asti)) 773 { 774 asti++; 775 } 776 777 while (asti < astParameters.size() && isAnyZeroOrMoreParameters(asti)) 778 { 779 asti++; 780 } 781 782 if (actuali == paramsLength && asti < astParameters.size()) 783 return false; 784 if (actuali == paramsLength && asti == astParameters.size()) 785 return true; 786 else 787 { 788 if (!matches(asti, actuali)) 789 { 790 do 791 { 792 actuali++; 793 while (actuali < paramsLength && asti < astParameters.size() && !doMatch(asti, actuali)) 794 { 795 actuali++; 796 } 797 798 }while ( (actuali < paramsLength) ? !(match = matches(asti, actuali)) : false); 799 800 } 801 if (actuali == paramsLength && asti == astParameters.size()) 802 { 803 match = true; 804 } 805 return match; 806 } 807 } 808 } 809 810 private static class RefParameterMatcher extends ParameterMatcher 811 { 812 Class [] params; 813 public RefParameterMatcher(Advisor advisor, ArrayList parameters, Class [] params) 814 { 815 super(advisor, parameters, params); 816 this.params = params; 817 } 818 819 boolean doMatch(int astIndex, int actualIndex) 820 { 821 ASTParameter ast = (ASTParameter) astParameters.get(astIndex); 822 ClassExpression exp = ast.getType(); 823 824 if (exp.isSimple()) 825 { 826 String asString = ClassExpression.simpleType(params[actualIndex]); 827 if (!exp.matches(asString)) return false; 828 } 829 else 830 { 831 if (!Util.matchesClassExpr(exp, params[actualIndex], advisor)) return false; 832 } 833 834 return true; 835 } 836 } 837 838 private static class CtParameterMatcher extends ParameterMatcher 839 { 840 CtClass[] params; 841 public CtParameterMatcher(Advisor advisor, ArrayList parameters, CtClass[] params) 842 { 843 super(advisor, parameters, params); 844 this.params = params; 845 } 846 847 boolean doMatch(int astIndex, int actualIndex) 848 { 849 ASTParameter ast = (ASTParameter) astParameters.get(astIndex); 850 ClassExpression exp = ast.getType(); 851 if (!matchesClassExpr(exp, params[actualIndex], advisor)) return false; 852 return true; 853 } 854 } 855 } 856 | Popular Tags |