1 11 package org.eclipse.jdt.core.dom; 12 13 import java.util.Iterator ; 14 import java.util.List ; 15 16 46 public class ASTMatcher { 47 48 52 private boolean matchDocTags; 53 54 63 public ASTMatcher() { 64 this(false); 65 } 66 67 75 public ASTMatcher(boolean matchDocTags) { 76 this.matchDocTags = matchDocTags; 77 } 78 79 95 public final boolean safeSubtreeListMatch(List list1, List list2) { 96 int size1 = list1.size(); 97 int size2 = list2.size(); 98 if (size1 != size2) { 99 return false; 100 } 101 for (Iterator it1 = list1.iterator(), it2 = list2.iterator(); it1.hasNext();) { 102 ASTNode n1 = (ASTNode) it1.next(); 103 ASTNode n2 = (ASTNode) it2.next(); 104 if (!n1.subtreeMatch(this, n2)) { 105 return false; 106 } 107 } 108 return true; 109 } 110 111 130 public final boolean safeSubtreeMatch(Object node1, Object node2) { 131 if (node1 == null && node2 == null) { 132 return true; 133 } 134 if (node1 == null || node2 == null) { 135 return false; 136 } 137 return ((ASTNode) node1).subtreeMatch(this, node2); 139 } 140 141 152 public static boolean safeEquals(Object o1, Object o2) { 153 if (o1 == o2) { 154 return true; 155 } 156 if (o1 == null || o2 == null) { 157 return false; 158 } 159 return o1.equals(o2); 160 } 161 162 177 public boolean match(AnnotationTypeDeclaration node, Object other) { 178 if (!(other instanceof AnnotationTypeDeclaration)) { 179 return false; 180 } 181 AnnotationTypeDeclaration o = (AnnotationTypeDeclaration) other; 182 return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 184 && safeSubtreeListMatch(node.modifiers(), o.modifiers()) 185 && safeSubtreeMatch(node.getName(), o.getName()) 186 && safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations())); 187 } 188 189 204 public boolean match(AnnotationTypeMemberDeclaration node, Object other) { 205 if (!(other instanceof AnnotationTypeMemberDeclaration)) { 206 return false; 207 } 208 AnnotationTypeMemberDeclaration o = (AnnotationTypeMemberDeclaration) other; 209 return (safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 211 && safeSubtreeListMatch(node.modifiers(), o.modifiers()) 212 && safeSubtreeMatch(node.getType(), o.getType()) 213 && safeSubtreeMatch(node.getName(), o.getName()) 214 && safeSubtreeMatch(node.getDefault(), o.getDefault())); 215 } 216 217 231 public boolean match(AnonymousClassDeclaration node, Object other) { 232 if (!(other instanceof AnonymousClassDeclaration)) { 233 return false; 234 } 235 AnonymousClassDeclaration o = (AnonymousClassDeclaration) other; 236 return safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations()); 237 } 238 239 253 public boolean match(ArrayAccess node, Object other) { 254 if (!(other instanceof ArrayAccess)) { 255 return false; 256 } 257 ArrayAccess o = (ArrayAccess) other; 258 return ( 259 safeSubtreeMatch(node.getArray(), o.getArray()) 260 && safeSubtreeMatch(node.getIndex(), o.getIndex())); 261 } 262 263 277 public boolean match(ArrayCreation node, Object other) { 278 if (!(other instanceof ArrayCreation)) { 279 return false; 280 } 281 ArrayCreation o = (ArrayCreation) other; 282 return ( 283 safeSubtreeMatch(node.getType(), o.getType()) 284 && safeSubtreeListMatch(node.dimensions(), o.dimensions()) 285 && safeSubtreeMatch(node.getInitializer(), o.getInitializer())); 286 } 287 288 302 public boolean match(ArrayInitializer node, Object other) { 303 if (!(other instanceof ArrayInitializer)) { 304 return false; 305 } 306 ArrayInitializer o = (ArrayInitializer) other; 307 return safeSubtreeListMatch(node.expressions(), o.expressions()); 308 } 309 310 324 public boolean match(ArrayType node, Object other) { 325 if (!(other instanceof ArrayType)) { 326 return false; 327 } 328 ArrayType o = (ArrayType) other; 329 return safeSubtreeMatch(node.getComponentType(), o.getComponentType()); 330 } 331 332 346 public boolean match(AssertStatement node, Object other) { 347 if (!(other instanceof AssertStatement)) { 348 return false; 349 } 350 AssertStatement o = (AssertStatement) other; 351 return ( 352 safeSubtreeMatch(node.getExpression(), o.getExpression()) 353 && safeSubtreeMatch(node.getMessage(), o.getMessage())); 354 } 355 356 370 public boolean match(Assignment node, Object other) { 371 if (!(other instanceof Assignment)) { 372 return false; 373 } 374 Assignment o = (Assignment) other; 375 return ( 376 node.getOperator().equals(o.getOperator()) 377 && safeSubtreeMatch(node.getLeftHandSide(), o.getLeftHandSide()) 378 && safeSubtreeMatch(node.getRightHandSide(), o.getRightHandSide())); 379 } 380 381 395 public boolean match(Block node, Object other) { 396 if (!(other instanceof Block)) { 397 return false; 398 } 399 Block o = (Block) other; 400 return safeSubtreeListMatch(node.statements(), o.statements()); 401 } 402 403 423 public boolean match(BlockComment node, Object other) { 424 if (!(other instanceof BlockComment)) { 425 return false; 426 } 427 return true; 428 } 429 430 444 public boolean match(BooleanLiteral node, Object other) { 445 if (!(other instanceof BooleanLiteral)) { 446 return false; 447 } 448 BooleanLiteral o = (BooleanLiteral) other; 449 return node.booleanValue() == o.booleanValue(); 450 } 451 452 466 public boolean match(BreakStatement node, Object other) { 467 if (!(other instanceof BreakStatement)) { 468 return false; 469 } 470 BreakStatement o = (BreakStatement) other; 471 return safeSubtreeMatch(node.getLabel(), o.getLabel()); 472 } 473 474 488 public boolean match(CastExpression node, Object other) { 489 if (!(other instanceof CastExpression)) { 490 return false; 491 } 492 CastExpression o = (CastExpression) other; 493 return ( 494 safeSubtreeMatch(node.getType(), o.getType()) 495 && safeSubtreeMatch(node.getExpression(), o.getExpression())); 496 } 497 498 512 public boolean match(CatchClause node, Object other) { 513 if (!(other instanceof CatchClause)) { 514 return false; 515 } 516 CatchClause o = (CatchClause) other; 517 return ( 518 safeSubtreeMatch(node.getException(), o.getException()) 519 && safeSubtreeMatch(node.getBody(), o.getBody())); 520 } 521 522 536 public boolean match(CharacterLiteral node, Object other) { 537 if (!(other instanceof CharacterLiteral)) { 538 return false; 539 } 540 CharacterLiteral o = (CharacterLiteral) other; 541 return safeEquals(node.getEscapedValue(), o.getEscapedValue()); 542 } 543 544 558 public boolean match(ClassInstanceCreation node, Object other) { 559 if (!(other instanceof ClassInstanceCreation)) { 560 return false; 561 } 562 ClassInstanceCreation o = (ClassInstanceCreation) other; 563 int level = node.getAST().apiLevel; 564 if (level == AST.JLS2_INTERNAL) { 565 if (!safeSubtreeMatch(node.internalGetName(), o.internalGetName())) { 566 return false; 567 } 568 } 569 if (level >= AST.JLS3) { 570 if (!safeSubtreeListMatch(node.typeArguments(), o.typeArguments())) { 571 return false; 572 } 573 if (!safeSubtreeMatch(node.getType(), o.getType())) { 574 return false; 575 } 576 } 577 return 578 safeSubtreeMatch(node.getExpression(), o.getExpression()) 579 && safeSubtreeListMatch(node.arguments(), o.arguments()) 580 && safeSubtreeMatch( 581 node.getAnonymousClassDeclaration(), 582 o.getAnonymousClassDeclaration()); 583 } 584 585 599 public boolean match(CompilationUnit node, Object other) { 600 if (!(other instanceof CompilationUnit)) { 601 return false; 602 } 603 CompilationUnit o = (CompilationUnit) other; 604 return ( 605 safeSubtreeMatch(node.getPackage(), o.getPackage()) 606 && safeSubtreeListMatch(node.imports(), o.imports()) 607 && safeSubtreeListMatch(node.types(), o.types())); 608 } 609 610 624 public boolean match(ConditionalExpression node, Object other) { 625 if (!(other instanceof ConditionalExpression)) { 626 return false; 627 } 628 ConditionalExpression o = (ConditionalExpression) other; 629 return ( 630 safeSubtreeMatch(node.getExpression(), o.getExpression()) 631 && safeSubtreeMatch(node.getThenExpression(), o.getThenExpression()) 632 && safeSubtreeMatch(node.getElseExpression(), o.getElseExpression())); 633 } 634 635 649 public boolean match(ConstructorInvocation node, Object other) { 650 if (!(other instanceof ConstructorInvocation)) { 651 return false; 652 } 653 ConstructorInvocation o = (ConstructorInvocation) other; 654 if (node.getAST().apiLevel >= AST.JLS3) { 655 if (!safeSubtreeListMatch(node.typeArguments(), o.typeArguments())) { 656 return false; 657 } 658 } 659 return safeSubtreeListMatch(node.arguments(), o.arguments()); 660 } 661 662 676 public boolean match(ContinueStatement node, Object other) { 677 if (!(other instanceof ContinueStatement)) { 678 return false; 679 } 680 ContinueStatement o = (ContinueStatement) other; 681 return safeSubtreeMatch(node.getLabel(), o.getLabel()); 682 } 683 684 698 public boolean match(DoStatement node, Object other) { 699 if (!(other instanceof DoStatement)) { 700 return false; 701 } 702 DoStatement o = (DoStatement) other; 703 return ( 704 safeSubtreeMatch(node.getExpression(), o.getExpression()) 705 && safeSubtreeMatch(node.getBody(), o.getBody())); 706 } 707 708 722 public boolean match(EmptyStatement node, Object other) { 723 if (!(other instanceof EmptyStatement)) { 724 return false; 725 } 726 return true; 727 } 728 729 744 public boolean match(EnhancedForStatement node, Object other) { 745 if (!(other instanceof EnhancedForStatement)) { 746 return false; 747 } 748 EnhancedForStatement o = (EnhancedForStatement) other; 749 return ( 750 safeSubtreeMatch(node.getParameter(), o.getParameter()) 751 && safeSubtreeMatch(node.getExpression(), o.getExpression()) 752 && safeSubtreeMatch(node.getBody(), o.getBody())); 753 } 754 755 770 public boolean match(EnumConstantDeclaration node, Object other) { 771 if (!(other instanceof EnumConstantDeclaration)) { 772 return false; 773 } 774 EnumConstantDeclaration o = (EnumConstantDeclaration) other; 775 return ( 776 safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 777 && safeSubtreeListMatch(node.modifiers(), o.modifiers()) 778 && safeSubtreeMatch(node.getName(), o.getName()) 779 && safeSubtreeListMatch(node.arguments(), o.arguments()) 780 && safeSubtreeMatch( 781 node.getAnonymousClassDeclaration(), 782 o.getAnonymousClassDeclaration())); 783 } 784 785 800 public boolean match(EnumDeclaration node, Object other) { 801 if (!(other instanceof EnumDeclaration)) { 802 return false; 803 } 804 EnumDeclaration o = (EnumDeclaration) other; 805 return ( 806 safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 807 && safeSubtreeListMatch(node.modifiers(), o.modifiers()) 808 && safeSubtreeMatch(node.getName(), o.getName()) 809 && safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes()) 810 && safeSubtreeListMatch(node.enumConstants(), o.enumConstants()) 811 && safeSubtreeListMatch( 812 node.bodyDeclarations(), 813 o.bodyDeclarations())); 814 } 815 816 830 public boolean match(ExpressionStatement node, Object other) { 831 if (!(other instanceof ExpressionStatement)) { 832 return false; 833 } 834 ExpressionStatement o = (ExpressionStatement) other; 835 return safeSubtreeMatch(node.getExpression(), o.getExpression()); 836 } 837 838 852 public boolean match(FieldAccess node, Object other) { 853 if (!(other instanceof FieldAccess)) { 854 return false; 855 } 856 FieldAccess o = (FieldAccess) other; 857 return ( 858 safeSubtreeMatch(node.getExpression(), o.getExpression()) 859 && safeSubtreeMatch(node.getName(), o.getName())); 860 } 861 862 876 public boolean match(FieldDeclaration node, Object other) { 877 if (!(other instanceof FieldDeclaration)) { 878 return false; 879 } 880 FieldDeclaration o = (FieldDeclaration) other; 881 int level = node.getAST().apiLevel; 882 if (level == AST.JLS2_INTERNAL) { 883 if (node.getModifiers() != o.getModifiers()) { 884 return false; 885 } 886 } 887 if (level >= AST.JLS3) { 888 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 889 return false; 890 } 891 } 892 return 893 safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 894 && safeSubtreeMatch(node.getType(), o.getType()) 895 && safeSubtreeListMatch(node.fragments(), o.fragments()); 896 } 897 898 912 public boolean match(ForStatement node, Object other) { 913 if (!(other instanceof ForStatement)) { 914 return false; 915 } 916 ForStatement o = (ForStatement) other; 917 return ( 918 safeSubtreeListMatch(node.initializers(), o.initializers()) 919 && safeSubtreeMatch(node.getExpression(), o.getExpression()) 920 && safeSubtreeListMatch(node.updaters(), o.updaters()) 921 && safeSubtreeMatch(node.getBody(), o.getBody())); 922 } 923 924 938 public boolean match(IfStatement node, Object other) { 939 if (!(other instanceof IfStatement)) { 940 return false; 941 } 942 IfStatement o = (IfStatement) other; 943 return ( 944 safeSubtreeMatch(node.getExpression(), o.getExpression()) 945 && safeSubtreeMatch(node.getThenStatement(), o.getThenStatement()) 946 && safeSubtreeMatch(node.getElseStatement(), o.getElseStatement())); 947 } 948 949 963 public boolean match(ImportDeclaration node, Object other) { 964 if (!(other instanceof ImportDeclaration)) { 965 return false; 966 } 967 ImportDeclaration o = (ImportDeclaration) other; 968 if (node.getAST().apiLevel >= AST.JLS3) { 969 if (node.isStatic() != o.isStatic()) { 970 return false; 971 } 972 } 973 return ( 974 safeSubtreeMatch(node.getName(), o.getName()) 975 && node.isOnDemand() == o.isOnDemand()); 976 } 977 978 992 public boolean match(InfixExpression node, Object other) { 993 if (!(other instanceof InfixExpression)) { 994 return false; 995 } 996 InfixExpression o = (InfixExpression) other; 997 if (node.hasExtendedOperands() && o.hasExtendedOperands()) { 999 if (!safeSubtreeListMatch(node.extendedOperands(), o.extendedOperands())) { 1000 return false; 1001 } 1002 } 1003 if (node.hasExtendedOperands() != o.hasExtendedOperands()) { 1004 return false; 1005 } 1006 return ( 1007 node.getOperator().equals(o.getOperator()) 1008 && safeSubtreeMatch(node.getLeftOperand(), o.getLeftOperand()) 1009 && safeSubtreeMatch(node.getRightOperand(), o.getRightOperand())); 1010 } 1011 1012 1026 public boolean match(InstanceofExpression node, Object other) { 1027 if (!(other instanceof InstanceofExpression)) { 1028 return false; 1029 } 1030 InstanceofExpression o = (InstanceofExpression) other; 1031 return ( 1032 safeSubtreeMatch(node.getLeftOperand(), o.getLeftOperand()) 1033 && safeSubtreeMatch(node.getRightOperand(), o.getRightOperand())); 1034 } 1035 1036 1050 public boolean match(Initializer node, Object other) { 1051 if (!(other instanceof Initializer)) { 1052 return false; 1053 } 1054 Initializer o = (Initializer) other; 1055 int level = node.getAST().apiLevel; 1056 if (level == AST.JLS2_INTERNAL) { 1057 if (node.getModifiers() != o.getModifiers()) { 1058 return false; 1059 } 1060 } 1061 if (level >= AST.JLS3) { 1062 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 1063 return false; 1064 } 1065 } 1066 return ( 1067 safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 1068 && safeSubtreeMatch(node.getBody(), o.getBody())); 1069 } 1070 1071 1097 public boolean match(Javadoc node, Object other) { 1098 if (!(other instanceof Javadoc)) { 1099 return false; 1100 } 1101 Javadoc o = (Javadoc) other; 1102 if (this.matchDocTags) { 1103 return safeSubtreeListMatch(node.tags(), o.tags()); 1104 } else { 1105 return compareDeprecatedComment(node, o); 1106 } 1107 } 1108 1109 1115 private boolean compareDeprecatedComment(Javadoc first, Javadoc second) { 1116 if (first.getAST().apiLevel == AST.JLS2_INTERNAL) { 1117 return safeEquals(first.getComment(), second.getComment()); 1118 } else { 1119 return true; 1120 } 1121 } 1122 1123 1137 public boolean match(LabeledStatement node, Object other) { 1138 if (!(other instanceof LabeledStatement)) { 1139 return false; 1140 } 1141 LabeledStatement o = (LabeledStatement) other; 1142 return ( 1143 safeSubtreeMatch(node.getLabel(), o.getLabel()) 1144 && safeSubtreeMatch(node.getBody(), o.getBody())); 1145 } 1146 1147 1167 public boolean match(LineComment node, Object other) { 1168 if (!(other instanceof LineComment)) { 1169 return false; 1170 } 1171 return true; 1172 } 1173 1174 1189 public boolean match(MarkerAnnotation node, Object other) { 1190 if (!(other instanceof MarkerAnnotation)) { 1191 return false; 1192 } 1193 MarkerAnnotation o = (MarkerAnnotation) other; 1194 return safeSubtreeMatch(node.getTypeName(), o.getTypeName()); 1195 } 1196 1197 1212 public boolean match(MemberRef node, Object other) { 1213 if (!(other instanceof MemberRef)) { 1214 return false; 1215 } 1216 MemberRef o = (MemberRef) other; 1217 return ( 1218 safeSubtreeMatch(node.getQualifier(), o.getQualifier()) 1219 && safeSubtreeMatch(node.getName(), o.getName())); 1220 } 1221 1222 1237 public boolean match(MemberValuePair node, Object other) { 1238 if (!(other instanceof MemberValuePair)) { 1239 return false; 1240 } 1241 MemberValuePair o = (MemberValuePair) other; 1242 return (safeSubtreeMatch(node.getName(), o.getName()) 1243 && safeSubtreeMatch(node.getValue(), o.getValue())); 1244 } 1245 1246 1261 public boolean match(MethodRef node, Object other) { 1262 if (!(other instanceof MethodRef)) { 1263 return false; 1264 } 1265 MethodRef o = (MethodRef) other; 1266 return ( 1267 safeSubtreeMatch(node.getQualifier(), o.getQualifier()) 1268 && safeSubtreeMatch(node.getName(), o.getName()) 1269 && safeSubtreeListMatch(node.parameters(), o.parameters())); 1270 } 1271 1272 1287 public boolean match(MethodRefParameter node, Object other) { 1288 if (!(other instanceof MethodRefParameter)) { 1289 return false; 1290 } 1291 MethodRefParameter o = (MethodRefParameter) other; 1292 int level = node.getAST().apiLevel; 1293 if (level >= AST.JLS3) { 1294 if (node.isVarargs() != o.isVarargs()) { 1295 return false; 1296 } 1297 } 1298 return ( 1299 safeSubtreeMatch(node.getType(), o.getType()) 1300 && safeSubtreeMatch(node.getName(), o.getName())); 1301 } 1302 1303 1325 public boolean match(MethodDeclaration node, Object other) { 1326 if (!(other instanceof MethodDeclaration)) { 1327 return false; 1328 } 1329 MethodDeclaration o = (MethodDeclaration) other; 1330 int level = node.getAST().apiLevel; 1331 if (level == AST.JLS2_INTERNAL) { 1332 if (node.getModifiers() != o.getModifiers()) { 1333 return false; 1334 } 1335 if (!safeSubtreeMatch(node.internalGetReturnType(), o.internalGetReturnType())) { 1336 return false; 1337 } 1338 } 1339 if (level >= AST.JLS3) { 1340 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 1341 return false; 1342 } 1343 if (!safeSubtreeMatch(node.getReturnType2(), o.getReturnType2())) { 1344 return false; 1345 } 1346 if (!safeSubtreeListMatch(node.typeParameters(), o.typeParameters())) { 1348 return false; 1349 } 1350 } 1351 return ((node.isConstructor() == o.isConstructor()) 1352 && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 1353 && safeSubtreeMatch(node.getName(), o.getName()) 1354 && safeSubtreeListMatch(node.parameters(), o.parameters()) 1356 && node.getExtraDimensions() == o.getExtraDimensions() 1357 && safeSubtreeListMatch(node.thrownExceptions(), o.thrownExceptions()) 1358 && safeSubtreeMatch(node.getBody(), o.getBody())); 1359 } 1360 1361 1375 public boolean match(MethodInvocation node, Object other) { 1376 if (!(other instanceof MethodInvocation)) { 1377 return false; 1378 } 1379 MethodInvocation o = (MethodInvocation) other; 1380 if (node.getAST().apiLevel >= AST.JLS3) { 1381 if (!safeSubtreeListMatch(node.typeArguments(), o.typeArguments())) { 1382 return false; 1383 } 1384 } 1385 return ( 1386 safeSubtreeMatch(node.getExpression(), o.getExpression()) 1387 && safeSubtreeMatch(node.getName(), o.getName()) 1388 && safeSubtreeListMatch(node.arguments(), o.arguments())); 1389 } 1390 1391 1406 public boolean match(Modifier node, Object other) { 1407 if (!(other instanceof Modifier)) { 1408 return false; 1409 } 1410 Modifier o = (Modifier) other; 1411 return (node.getKeyword() == o.getKeyword()); 1412 } 1413 1414 1429 public boolean match(NormalAnnotation node, Object other) { 1430 if (!(other instanceof NormalAnnotation)) { 1431 return false; 1432 } 1433 NormalAnnotation o = (NormalAnnotation) other; 1434 return (safeSubtreeMatch(node.getTypeName(), o.getTypeName()) 1435 && safeSubtreeListMatch(node.values(), o.values())); 1436 } 1437 1438 1452 public boolean match(NullLiteral node, Object other) { 1453 if (!(other instanceof NullLiteral)) { 1454 return false; 1455 } 1456 return true; 1457 } 1458 1459 1473 public boolean match(NumberLiteral node, Object other) { 1474 if (!(other instanceof NumberLiteral)) { 1475 return false; 1476 } 1477 NumberLiteral o = (NumberLiteral) other; 1478 return safeEquals(node.getToken(), o.getToken()); 1479 } 1480 1481 1495 public boolean match(PackageDeclaration node, Object other) { 1496 if (!(other instanceof PackageDeclaration)) { 1497 return false; 1498 } 1499 PackageDeclaration o = (PackageDeclaration) other; 1500 if (node.getAST().apiLevel >= AST.JLS3) { 1501 if (!safeSubtreeMatch(node.getJavadoc(), o.getJavadoc())) { 1502 return false; 1503 } 1504 if (!safeSubtreeListMatch(node.annotations(), o.annotations())) { 1505 return false; 1506 } 1507 } 1508 return safeSubtreeMatch(node.getName(), o.getName()); 1509 } 1510 1511 1526 public boolean match(ParameterizedType node, Object other) { 1527 if (!(other instanceof ParameterizedType)) { 1528 return false; 1529 } 1530 ParameterizedType o = (ParameterizedType) other; 1531 return safeSubtreeMatch(node.getType(), o.getType()) 1532 && safeSubtreeListMatch(node.typeArguments(), o.typeArguments()); 1533 } 1534 1535 1549 public boolean match(ParenthesizedExpression node, Object other) { 1550 if (!(other instanceof ParenthesizedExpression)) { 1551 return false; 1552 } 1553 ParenthesizedExpression o = (ParenthesizedExpression) other; 1554 return safeSubtreeMatch(node.getExpression(), o.getExpression()); 1555 } 1556 1557 1571 public boolean match(PostfixExpression node, Object other) { 1572 if (!(other instanceof PostfixExpression)) { 1573 return false; 1574 } 1575 PostfixExpression o = (PostfixExpression) other; 1576 return ( 1577 node.getOperator().equals(o.getOperator()) 1578 && safeSubtreeMatch(node.getOperand(), o.getOperand())); 1579 } 1580 1581 1595 public boolean match(PrefixExpression node, Object other) { 1596 if (!(other instanceof PrefixExpression)) { 1597 return false; 1598 } 1599 PrefixExpression o = (PrefixExpression) other; 1600 return ( 1601 node.getOperator().equals(o.getOperator()) 1602 && safeSubtreeMatch(node.getOperand(), o.getOperand())); 1603 } 1604 1605 1619 public boolean match(PrimitiveType node, Object other) { 1620 if (!(other instanceof PrimitiveType)) { 1621 return false; 1622 } 1623 PrimitiveType o = (PrimitiveType) other; 1624 return (node.getPrimitiveTypeCode() == o.getPrimitiveTypeCode()); 1625 } 1626 1627 1641 public boolean match(QualifiedName node, Object other) { 1642 if (!(other instanceof QualifiedName)) { 1643 return false; 1644 } 1645 QualifiedName o = (QualifiedName) other; 1646 return ( 1647 safeSubtreeMatch(node.getQualifier(), o.getQualifier()) 1648 && safeSubtreeMatch(node.getName(), o.getName())); 1649 } 1650 1651 1666 public boolean match(QualifiedType node, Object other) { 1667 if (!(other instanceof QualifiedType)) { 1668 return false; 1669 } 1670 QualifiedType o = (QualifiedType) other; 1671 return ( 1672 safeSubtreeMatch(node.getQualifier(), o.getQualifier()) 1673 && safeSubtreeMatch(node.getName(), o.getName())); 1674 } 1675 1676 1690 public boolean match(ReturnStatement node, Object other) { 1691 if (!(other instanceof ReturnStatement)) { 1692 return false; 1693 } 1694 ReturnStatement o = (ReturnStatement) other; 1695 return safeSubtreeMatch(node.getExpression(), o.getExpression()); 1696 } 1697 1698 1712 public boolean match(SimpleName node, Object other) { 1713 if (!(other instanceof SimpleName)) { 1714 return false; 1715 } 1716 SimpleName o = (SimpleName) other; 1717 return node.getIdentifier().equals(o.getIdentifier()); 1718 } 1719 1720 1734 public boolean match(SimpleType node, Object other) { 1735 if (!(other instanceof SimpleType)) { 1736 return false; 1737 } 1738 SimpleType o = (SimpleType) other; 1739 return safeSubtreeMatch(node.getName(), o.getName()); 1740 } 1741 1742 1757 public boolean match(SingleMemberAnnotation node, Object other) { 1758 if (!(other instanceof SingleMemberAnnotation)) { 1759 return false; 1760 } 1761 SingleMemberAnnotation o = (SingleMemberAnnotation) other; 1762 return (safeSubtreeMatch(node.getTypeName(), o.getTypeName()) 1763 && safeSubtreeMatch(node.getValue(), o.getValue())); 1764 } 1765 1766 1784 public boolean match(SingleVariableDeclaration node, Object other) { 1785 if (!(other instanceof SingleVariableDeclaration)) { 1786 return false; 1787 } 1788 SingleVariableDeclaration o = (SingleVariableDeclaration) other; 1789 int level = node.getAST().apiLevel; 1790 if (level == AST.JLS2_INTERNAL) { 1791 if (node.getModifiers() != o.getModifiers()) { 1792 return false; 1793 } 1794 } 1795 if (level >= AST.JLS3) { 1796 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 1797 return false; 1798 } 1799 if (node.isVarargs() != o.isVarargs()) { 1800 return false; 1801 } 1802 } 1803 return 1804 safeSubtreeMatch(node.getType(), o.getType()) 1805 && safeSubtreeMatch(node.getName(), o.getName()) 1806 && node.getExtraDimensions() == o.getExtraDimensions() 1807 && safeSubtreeMatch(node.getInitializer(), o.getInitializer()); 1808 } 1809 1810 1824 public boolean match(StringLiteral node, Object other) { 1825 if (!(other instanceof StringLiteral)) { 1826 return false; 1827 } 1828 StringLiteral o = (StringLiteral) other; 1829 return safeEquals(node.getEscapedValue(), o.getEscapedValue()); 1830 } 1831 1832 1846 public boolean match(SuperConstructorInvocation node, Object other) { 1847 if (!(other instanceof SuperConstructorInvocation)) { 1848 return false; 1849 } 1850 SuperConstructorInvocation o = (SuperConstructorInvocation) other; 1851 if (node.getAST().apiLevel >= AST.JLS3) { 1852 if (!safeSubtreeListMatch(node.typeArguments(), o.typeArguments())) { 1853 return false; 1854 } 1855 } 1856 return ( 1857 safeSubtreeMatch(node.getExpression(), o.getExpression()) 1858 && safeSubtreeListMatch(node.arguments(), o.arguments())); 1859 } 1860 1861 1875 public boolean match(SuperFieldAccess node, Object other) { 1876 if (!(other instanceof SuperFieldAccess)) { 1877 return false; 1878 } 1879 SuperFieldAccess o = (SuperFieldAccess) other; 1880 return ( 1881 safeSubtreeMatch(node.getName(), o.getName()) 1882 && safeSubtreeMatch(node.getQualifier(), o.getQualifier())); 1883 } 1884 1885 1899 public boolean match(SuperMethodInvocation node, Object other) { 1900 if (!(other instanceof SuperMethodInvocation)) { 1901 return false; 1902 } 1903 SuperMethodInvocation o = (SuperMethodInvocation) other; 1904 if (node.getAST().apiLevel >= AST.JLS3) { 1905 if (!safeSubtreeListMatch(node.typeArguments(), o.typeArguments())) { 1906 return false; 1907 } 1908 } 1909 return ( 1910 safeSubtreeMatch(node.getQualifier(), o.getQualifier()) 1911 && safeSubtreeMatch(node.getName(), o.getName()) 1912 && safeSubtreeListMatch(node.arguments(), o.arguments())); 1913 } 1914 1915 1929 public boolean match(SwitchCase node, Object other) { 1930 if (!(other instanceof SwitchCase)) { 1931 return false; 1932 } 1933 SwitchCase o = (SwitchCase) other; 1934 return safeSubtreeMatch(node.getExpression(), o.getExpression()); 1935 } 1936 1937 1951 public boolean match(SwitchStatement node, Object other) { 1952 if (!(other instanceof SwitchStatement)) { 1953 return false; 1954 } 1955 SwitchStatement o = (SwitchStatement) other; 1956 return ( 1957 safeSubtreeMatch(node.getExpression(), o.getExpression()) 1958 && safeSubtreeListMatch(node.statements(), o.statements())); 1959 } 1960 1961 1975 public boolean match(SynchronizedStatement node, Object other) { 1976 if (!(other instanceof SynchronizedStatement)) { 1977 return false; 1978 } 1979 SynchronizedStatement o = (SynchronizedStatement) other; 1980 return ( 1981 safeSubtreeMatch(node.getExpression(), o.getExpression()) 1982 && safeSubtreeMatch(node.getBody(), o.getBody())); 1983 } 1984 1985 2000 public boolean match(TagElement node, Object other) { 2001 if (!(other instanceof TagElement)) { 2002 return false; 2003 } 2004 TagElement o = (TagElement) other; 2005 return ( 2006 safeEquals(node.getTagName(), o.getTagName()) 2007 && safeSubtreeListMatch(node.fragments(), o.fragments())); 2008 } 2009 2010 2025 public boolean match(TextElement node, Object other) { 2026 if (!(other instanceof TextElement)) { 2027 return false; 2028 } 2029 TextElement o = (TextElement) other; 2030 return safeEquals(node.getText(), o.getText()); 2031 } 2032 2033 2047 public boolean match(ThisExpression node, Object other) { 2048 if (!(other instanceof ThisExpression)) { 2049 return false; 2050 } 2051 ThisExpression o = (ThisExpression) other; 2052 return safeSubtreeMatch(node.getQualifier(), o.getQualifier()); 2053 } 2054 2055 2069 public boolean match(ThrowStatement node, Object other) { 2070 if (!(other instanceof ThrowStatement)) { 2071 return false; 2072 } 2073 ThrowStatement o = (ThrowStatement) other; 2074 return safeSubtreeMatch(node.getExpression(), o.getExpression()); 2075 } 2076 2077 2091 public boolean match(TryStatement node, Object other) { 2092 if (!(other instanceof TryStatement)) { 2093 return false; 2094 } 2095 TryStatement o = (TryStatement) other; 2096 return ( 2097 safeSubtreeMatch(node.getBody(), o.getBody()) 2098 && safeSubtreeListMatch(node.catchClauses(), o.catchClauses()) 2099 && safeSubtreeMatch(node.getFinally(), o.getFinally())); 2100 } 2101 2102 2116 public boolean match(TypeDeclaration node, Object other) { 2117 if (!(other instanceof TypeDeclaration)) { 2118 return false; 2119 } 2120 TypeDeclaration o = (TypeDeclaration) other; 2121 int level = node.getAST().apiLevel; 2122 if (level == AST.JLS2_INTERNAL) { 2123 if (node.getModifiers() != o.getModifiers()) { 2124 return false; 2125 } 2126 if (!safeSubtreeMatch(node.internalGetSuperclass(), o.internalGetSuperclass())) { 2127 return false; 2128 } 2129 if (!safeSubtreeListMatch(node.internalSuperInterfaces(), o.internalSuperInterfaces())) { 2130 return false; 2131 } 2132 } 2133 if (level >= AST.JLS3) { 2134 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 2135 return false; 2136 } 2137 if (!safeSubtreeListMatch(node.typeParameters(), o.typeParameters())) { 2138 return false; 2139 } 2140 if (!safeSubtreeMatch(node.getSuperclassType(), o.getSuperclassType())) { 2141 return false; 2142 } 2143 if (!safeSubtreeListMatch(node.superInterfaceTypes(), o.superInterfaceTypes())) { 2144 return false; 2145 } 2146 } 2147 return ( 2148 (node.isInterface() == o.isInterface()) 2149 && safeSubtreeMatch(node.getJavadoc(), o.getJavadoc()) 2150 && safeSubtreeMatch(node.getName(), o.getName()) 2151 && safeSubtreeListMatch(node.bodyDeclarations(), o.bodyDeclarations())); 2152 } 2153 2154 2168 public boolean match(TypeDeclarationStatement node, Object other) { 2169 if (!(other instanceof TypeDeclarationStatement)) { 2170 return false; 2171 } 2172 TypeDeclarationStatement o = (TypeDeclarationStatement) other; 2173 return safeSubtreeMatch(node.getDeclaration(), o.getDeclaration()); 2174 } 2175 2176 2190 public boolean match(TypeLiteral node, Object other) { 2191 if (!(other instanceof TypeLiteral)) { 2192 return false; 2193 } 2194 TypeLiteral o = (TypeLiteral) other; 2195 return safeSubtreeMatch(node.getType(), o.getType()); 2196 } 2197 2198 2213 public boolean match(TypeParameter node, Object other) { 2214 if (!(other instanceof TypeParameter)) { 2215 return false; 2216 } 2217 TypeParameter o = (TypeParameter) other; 2218 return safeSubtreeMatch(node.getName(), o.getName()) 2219 && safeSubtreeListMatch(node.typeBounds(), o.typeBounds()); 2220 } 2221 2222 2236 public boolean match(VariableDeclarationExpression node, Object other) { 2237 if (!(other instanceof VariableDeclarationExpression)) { 2238 return false; 2239 } 2240 VariableDeclarationExpression o = (VariableDeclarationExpression) other; 2241 int level = node.getAST().apiLevel; 2242 if (level == AST.JLS2_INTERNAL) { 2243 if (node.getModifiers() != o.getModifiers()) { 2244 return false; 2245 } 2246 } 2247 if (level >= AST.JLS3) { 2248 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 2249 return false; 2250 } 2251 } 2252 return safeSubtreeMatch(node.getType(), o.getType()) 2253 && safeSubtreeListMatch(node.fragments(), o.fragments()); 2254 } 2255 2256 2274 public boolean match(VariableDeclarationFragment node, Object other) { 2275 if (!(other instanceof VariableDeclarationFragment)) { 2276 return false; 2277 } 2278 VariableDeclarationFragment o = (VariableDeclarationFragment) other; 2279 return safeSubtreeMatch(node.getName(), o.getName()) 2280 && node.getExtraDimensions() == o.getExtraDimensions() 2281 && safeSubtreeMatch(node.getInitializer(), o.getInitializer()); 2282 } 2283 2284 2298 public boolean match(VariableDeclarationStatement node, Object other) { 2299 if (!(other instanceof VariableDeclarationStatement)) { 2300 return false; 2301 } 2302 VariableDeclarationStatement o = (VariableDeclarationStatement) other; 2303 int level = node.getAST().apiLevel; 2304 if (level == AST.JLS2_INTERNAL) { 2305 if (node.getModifiers() != o.getModifiers()) { 2306 return false; 2307 } 2308 } 2309 if (level >= AST.JLS3) { 2310 if (!safeSubtreeListMatch(node.modifiers(), o.modifiers())) { 2311 return false; 2312 } 2313 } 2314 return safeSubtreeMatch(node.getType(), o.getType()) 2315 && safeSubtreeListMatch(node.fragments(), o.fragments()); 2316 } 2317 2318 2332 public boolean match(WhileStatement node, Object other) { 2333 if (!(other instanceof WhileStatement)) { 2334 return false; 2335 } 2336 WhileStatement o = (WhileStatement) other; 2337 return ( 2338 safeSubtreeMatch(node.getExpression(), o.getExpression()) 2339 && safeSubtreeMatch(node.getBody(), o.getBody())); 2340 } 2341 2342 2357 public boolean match(WildcardType node, Object other) { 2358 if (!(other instanceof WildcardType)) { 2359 return false; 2360 } 2361 WildcardType o = (WildcardType) other; 2362 return node.isUpperBound() == o.isUpperBound() 2363 && safeSubtreeMatch(node.getBound(), o.getBound()); 2364 } 2365 2366} 2367 | Popular Tags |