1 19 package org.netbeans.api.java.source; 20 21 import com.sun.source.tree.*; 22 import com.sun.source.tree.Tree.Kind; 23 import com.sun.source.util.SourcePositions; 24 import com.sun.source.util.TreePath; 25 26 import javax.lang.model.element.*; 27 import javax.lang.model.type.*; 28 import javax.tools.JavaFileObject; 29 30 import java.util.List ; 31 import java.util.Set ; 32 import java.util.EnumSet ; 33 34 import org.netbeans.api.java.source.query.CommentHandler; 35 import org.netbeans.api.java.source.query.CommentSet; 36 import org.netbeans.api.java.lexer.JavaTokenId; 37 import org.netbeans.api.java.source.Comment.Style; 38 import org.netbeans.api.java.source.query.CommentHandler; 39 import org.netbeans.api.java.source.query.Query; 40 import org.netbeans.api.lexer.TokenHierarchy; 41 import org.netbeans.api.lexer.TokenSequence; 42 import org.netbeans.modules.java.source.JavaSourceAccessor; 43 44 import org.netbeans.modules.java.source.engine.TreeMakerInt; 45 import org.netbeans.modules.java.source.builder.CommentHandlerService; 46 47 71 public final class TreeMaker { 72 73 private TreeMakerInt delegate; 74 private CommentHandler handler; 75 private WorkingCopy copy; 76 77 TreeMaker(WorkingCopy copy, TreeMakerInt delegate) { 78 this.delegate = delegate; 79 this.copy = copy; 80 this.handler = CommentHandlerService.instance(copy.getJavacTask().getContext()); 81 } 82 83 90 public AnnotationTree Annotation(Tree type, List <? extends ExpressionTree> arguments) { 91 return delegate.Annotation(type, arguments); 92 } 93 94 101 public ArrayAccessTree ArrayAccess(ExpressionTree array, ExpressionTree index) { 102 return delegate.ArrayAccess(array, index); 103 } 104 105 111 public ArrayTypeTree ArrayType(Tree type) { 112 return delegate.ArrayType(type); 113 } 114 115 122 public AssertTree Assert(ExpressionTree condition, ExpressionTree detail) { 123 return delegate.Assert(condition, detail); 124 } 125 126 133 public AssignmentTree Assignment(ExpressionTree variable, ExpressionTree expression) { 134 return delegate.Assignment(variable, expression); 135 } 136 137 146 public BinaryTree Binary(Kind operator, ExpressionTree left, ExpressionTree right) { 147 return delegate.Binary(operator, left, right); 148 } 149 150 159 public BlockTree Block(List <? extends StatementTree> statements, boolean isStatic) { 160 return delegate.Block(statements, isStatic); 161 } 162 163 169 public BreakTree Break(CharSequence label) { 170 return delegate.Break(label); 171 } 172 173 180 public CaseTree Case(ExpressionTree expression, List <? extends StatementTree> statements) { 181 return delegate.Case(expression, statements); 182 } 183 184 191 public CatchTree Catch(VariableTree parameter, BlockTree block) { 192 return delegate.Catch(parameter, block); 193 } 194 195 209 public ClassTree Class(ModifiersTree modifiers, 210 CharSequence simpleName, 211 List <? extends TypeParameterTree> typeParameters, 212 Tree extendsClause, 213 List <? extends ExpressionTree> implementsClauses, 214 List <? extends Tree> memberDecls) { 215 return delegate.Class(modifiers, simpleName, typeParameters, extendsClause, implementsClauses, memberDecls); 216 } 217 230 public ClassTree Interface(ModifiersTree modifiers, 231 CharSequence simpleName, 232 List <? extends TypeParameterTree> typeParameters, 233 List <? extends ExpressionTree> extendsClauses, 234 List <? extends Tree> memberDecls) { 235 return delegate.Interface(modifiers, simpleName, typeParameters, extendsClauses, memberDecls); 236 } 237 238 248 public ClassTree AnnotationType(ModifiersTree modifiers, 249 CharSequence simpleName, 250 List <? extends Tree> memberDecls) { 251 return delegate.AnnotationType(modifiers, simpleName, memberDecls); 252 } 253 254 266 public ClassTree Enum(ModifiersTree modifiers, 267 CharSequence simpleName, 268 List <? extends ExpressionTree> implementsClauses, 269 List <? extends Tree> memberDecls) { 270 return delegate.Enum(modifiers, simpleName, implementsClauses, memberDecls); 271 } 272 273 282 public CompilationUnitTree CompilationUnit(ExpressionTree packageName, 283 List <? extends ImportTree> imports, 284 List <? extends Tree> typeDeclarations, 285 JavaFileObject sourceFile) { 286 return delegate.CompilationUnit(packageName, imports, typeDeclarations, sourceFile); 287 } 288 289 297 public CompoundAssignmentTree CompoundAssignment(Kind operator, 298 ExpressionTree variable, 299 ExpressionTree expression) { 300 return delegate.CompoundAssignment(operator, variable, expression); 301 } 302 303 313 public ConditionalExpressionTree ConditionalExpression(ExpressionTree condition, 314 ExpressionTree trueExpression, 315 ExpressionTree falseExpression) { 316 return delegate.ConditionalExpression(condition, trueExpression, falseExpression); 317 } 318 319 329 public MethodTree Constructor(ModifiersTree modifiers, 330 List <? extends TypeParameterTree> typeParameters, 331 List <? extends VariableTree> parameters, 332 List <? extends ExpressionTree> throwsList, 333 BlockTree body) { 334 return delegate.Method(modifiers, "<init>", null, typeParameters, parameters, throwsList, body, null); 335 } 336 337 347 public MethodTree Constructor(ModifiersTree modifiers, 348 List <? extends TypeParameterTree> typeParameters, 349 List <? extends VariableTree> parameters, 350 List <? extends ExpressionTree> throwsList, 351 String bodyText) { 352 return Method(modifiers, "<init>", null, typeParameters, parameters, throwsList, bodyText, null); 353 } 354 355 361 public ContinueTree Continue(CharSequence label) { 362 return delegate.Continue(label); 363 } 364 365 371 public DoWhileLoopTree DoWhileLoop(ExpressionTree condition, StatementTree statement) { 372 return delegate.DoWhileLoop(condition, statement); 373 } 374 375 380 public EmptyStatementTree EmptyStatement() { 381 return delegate.EmptyStatement(); 382 } 383 384 392 public EnhancedForLoopTree EnhancedForLoop(VariableTree variable, 393 ExpressionTree expression, 394 StatementTree statement) { 395 return delegate.EnhancedForLoop(variable, expression, statement); 396 } 397 398 404 public ErroneousTree Erroneous(List <? extends Tree> errorTrees) { 405 return delegate.Erroneous(errorTrees); 406 } 407 408 414 public ExpressionStatementTree ExpressionStatement(ExpressionTree expression) { 415 return delegate.ExpressionStatement(expression); 416 } 417 418 427 public ForLoopTree ForLoop(List <? extends StatementTree> initializer, 428 ExpressionTree condition, 429 List <? extends ExpressionStatementTree> update, 430 StatementTree statement) { 431 return delegate.ForLoop(initializer, condition, update, statement); 432 } 433 434 440 public IdentifierTree Identifier(CharSequence name) { 441 return delegate.Identifier(name); 442 } 443 444 451 public IdentifierTree Identifier(Element element) { 452 return delegate.Identifier(element); 453 } 454 455 456 465 public IfTree If(ExpressionTree condition, StatementTree thenStatement, StatementTree elseStatement) { 466 return delegate.If(condition, thenStatement, elseStatement); 467 } 468 469 476 public ImportTree Import(Tree qualid, boolean importStatic) { 477 return delegate.Import(qualid, importStatic); 478 } 479 480 487 public InstanceOfTree InstanceOf(ExpressionTree expression, Tree type) { 488 return delegate.InstanceOf(expression, type); 489 } 490 491 498 public LabeledStatementTree LabeledStatement(CharSequence label, StatementTree statement) { 499 return delegate.LabeledStatement(label, statement); 500 } 501 502 511 public LiteralTree Literal(Object value) { 512 return delegate.Literal(value); 513 } 514 515 527 public MemberSelectTree MemberSelect(ExpressionTree expression, CharSequence identifier) { 528 return delegate.MemberSelect(expression, identifier); 529 } 530 531 539 public MemberSelectTree MemberSelect(ExpressionTree expression, Element element) { 540 return delegate.MemberSelect(expression, element); 541 } 542 543 551 public MethodInvocationTree MethodInvocation(List <? extends ExpressionTree> typeArguments, 552 ExpressionTree method, 553 List <? extends ExpressionTree> arguments) { 554 return delegate.MethodInvocation(typeArguments, method, arguments); 555 } 556 557 570 public MethodTree Method(ModifiersTree modifiers, 571 CharSequence name, 572 Tree returnType, 573 List <? extends TypeParameterTree> typeParameters, 574 List <? extends VariableTree> parameters, 575 List <? extends ExpressionTree> throwsList, 576 BlockTree body, 577 ExpressionTree defaultValue) { 578 return delegate.Method(modifiers, name, returnType, typeParameters, parameters, throwsList, body, defaultValue); 579 } 580 581 595 public MethodTree Method(ModifiersTree modifiers, 596 CharSequence name, 597 Tree returnType, 598 List <? extends TypeParameterTree> typeParameters, 599 List <? extends VariableTree> parameters, 600 List <? extends ExpressionTree> throwsList, 601 BlockTree body, 602 ExpressionTree defaultValue, 603 TypeElement enclosingElement) { 604 return delegate.Method(modifiers, name, returnType, typeParameters, parameters, throwsList, body, defaultValue, enclosingElement); 605 } 606 607 616 public MethodTree Method(ExecutableElement element, BlockTree body) { 617 return delegate.Method(element, body); 618 } 619 620 628 public ModifiersTree Modifiers(Set <Modifier> flags, List <? extends AnnotationTree> annotations) { 629 return delegate.Modifiers(flags, annotations); 630 } 631 632 638 public ModifiersTree Modifiers(long flags, List <? extends AnnotationTree> annotations) { 639 return delegate.Modifiers(flags, annotations); 640 } 641 642 649 public ModifiersTree Modifiers(Set <Modifier> flags) { 650 return delegate.Modifiers(flags); 651 } 652 653 662 public ModifiersTree Modifiers(ModifiersTree oldMods, List <? extends AnnotationTree> annotations) { 663 return delegate.Modifiers(oldMods, annotations); 664 } 665 666 674 public NewArrayTree NewArray(Tree elemtype, 675 List <? extends ExpressionTree> dimensions, 676 List <? extends ExpressionTree> initializers) { 677 return delegate.NewArray(elemtype, dimensions, initializers); 678 } 679 680 690 public NewClassTree NewClass(ExpressionTree enclosingExpression, 691 List <? extends ExpressionTree> typeArguments, 692 ExpressionTree identifier, 693 List <? extends ExpressionTree> arguments, 694 ClassTree classBody) { 695 return delegate.NewClass(enclosingExpression, typeArguments, identifier, arguments, classBody); 696 } 697 698 705 public ParameterizedTypeTree ParameterizedType(Tree type, 706 List <? extends ExpressionTree> typeArguments) { 707 return delegate.ParameterizedType(type, typeArguments); 708 } 709 710 716 public ParenthesizedTree Parenthesized(ExpressionTree expression) { 717 return delegate.Parenthesized(expression); 718 } 719 720 727 public PrimitiveTypeTree PrimitiveType(TypeKind typekind) { 728 return delegate.PrimitiveType(typekind); 729 } 730 731 736 public ExpressionTree QualIdent(Element element) { 737 return delegate.QualIdent(element); 738 } 739 740 746 public ReturnTree Return(ExpressionTree expression) { 747 return delegate.Return(expression); 748 } 749 750 757 public SwitchTree Switch(ExpressionTree expression, List <? extends CaseTree> cases) { 758 return delegate.Switch(expression, cases); 759 } 760 761 768 public SynchronizedTree Synchronized(ExpressionTree expression, BlockTree block) { 769 return delegate.Synchronized(expression, block); 770 } 771 772 778 public ThrowTree Throw(ExpressionTree expression) { 779 return delegate.Throw(expression); 780 } 781 782 790 public TryTree Try(BlockTree tryBlock, 791 List <? extends CatchTree> catches, 792 BlockTree finallyBlock) { 793 return delegate.Try(tryBlock, catches, finallyBlock); 794 } 795 796 802 public Tree Type(TypeMirror type) { 803 return delegate.Type(type); 804 } 805 806 813 public TypeCastTree TypeCast(Tree type, ExpressionTree expression) { 814 return delegate.TypeCast(type, expression); 815 } 816 817 824 public TypeParameterTree TypeParameter(CharSequence name, 825 List <? extends ExpressionTree> bounds) { 826 return delegate.TypeParameter(name, bounds); 827 } 828 829 837 public UnaryTree Unary(Kind operator, ExpressionTree arg) { 838 return delegate.Unary(operator, arg); 839 } 840 841 850 public VariableTree Variable(ModifiersTree modifiers, 851 CharSequence name, 852 Tree type, 853 ExpressionTree initializer) { 854 return delegate.Variable(modifiers, name, type, initializer); 855 } 856 857 867 public VariableTree Variable(ModifiersTree modifiers, 868 CharSequence name, 869 Tree type, 870 ExpressionTree initializer, 871 TypeElement enclosingElement) { 872 return delegate.Variable(modifiers, name, type, initializer, enclosingElement); 873 } 874 875 883 public VariableTree Variable(VariableElement variable, ExpressionTree initializer) { 884 return delegate.Variable(variable, initializer); 885 } 886 887 894 public WhileLoopTree WhileLoop(ExpressionTree condition, StatementTree statement) { 895 return delegate.WhileLoop(condition, statement); 896 } 897 898 905 public WildcardTree Wildcard(Kind kind, Tree type) { 906 return delegate.Wildcard(kind, type); 907 } 908 909 919 public AnnotationTree addAnnotationAttrValue(AnnotationTree annotation, ExpressionTree attrValue) { 920 return delegate.addAnnotationAttrValue(annotation, attrValue); 921 } 922 923 935 public AnnotationTree insertAnnotationAttrValue(AnnotationTree annotation, int index, ExpressionTree attrValue) { 936 return delegate.insertAnnotationAttrValue(annotation, index, attrValue); 937 } 938 939 948 public AnnotationTree removeAnnotationAttrValue(AnnotationTree annotation, ExpressionTree attrValue) { 949 return delegate.removeAnnotationAttrValue(annotation, attrValue); 950 } 951 952 963 public AnnotationTree removeAnnotationAttrValue(AnnotationTree annotation, int index) { 964 return delegate.removeAnnotationAttrValue(annotation, index); 965 } 966 967 976 public BlockTree addBlockStatement(BlockTree block, StatementTree statement) { 977 return delegate.addBlockStatement(block, statement); 978 } 979 980 992 public BlockTree insertBlockStatement(BlockTree block, int index, StatementTree statement) { 993 return delegate.insertBlockStatement(block, index, statement); 994 } 995 996 1005 public BlockTree removeBlockStatement(BlockTree block, StatementTree statement) { 1006 return delegate.removeBlockStatement(block, statement); 1007 } 1008 1009 1020 public BlockTree removeBlockStatement(BlockTree block, int index) { 1021 return delegate.removeBlockStatement(block, index); 1022 } 1023 1024 1033 public CaseTree addCaseStatement(CaseTree kejs, StatementTree statement) { 1034 return delegate.addCaseStatement(kejs, statement); 1035 } 1036 1037 1049 public CaseTree insertCaseStatement(CaseTree kejs, int index, StatementTree statement) { 1050 return delegate.insertCaseStatement(kejs, index, statement); 1051 } 1052 1053 1062 public CaseTree removeCaseStatement(CaseTree kejs, StatementTree statement) { 1063 return delegate.removeCaseStatement(kejs, statement); 1064 } 1065 1066 1077 public CaseTree removeCaseStatement(CaseTree kejs, int index) { 1078 return delegate.removeCaseStatement(kejs, index); 1079 } 1080 1081 1124 public ClassTree addClassMember(ClassTree clazz, Tree member) { 1125 return delegate.addClassMember(clazz, member); 1126 } 1127 1128 1140 public ClassTree insertClassMember(ClassTree clazz, int index, Tree member) { 1141 return delegate.insertClassMember(clazz, index, member); 1142 } 1143 1144 1153 public ClassTree removeClassMember(ClassTree clazz, Tree member) { 1154 return delegate.removeClassMember(clazz, member); 1155 } 1156 1157 1168 public ClassTree removeClassMember(ClassTree clazz, int index) { 1169 return delegate.removeClassMember(clazz, index); 1170 } 1171 1172 1180 public ClassTree addClassTypeParameter(ClassTree clazz, TypeParameterTree typeParameter) { 1181 return delegate.addClassTypeParameter(clazz, typeParameter); 1182 } 1183 1184 1196 public ClassTree insertClassTypeParameter(ClassTree clazz, int index, TypeParameterTree typeParameter) { 1197 return delegate.insertClassTypeParameter(clazz, index, typeParameter); 1198 } 1199 1200 1209 public ClassTree removeClassTypeParameter(ClassTree clazz, TypeParameterTree typeParameter) { 1210 return delegate.removeClassTypeParameter(clazz, typeParameter); 1211 } 1212 1213 1224 public ClassTree removeClassTypeParameter(ClassTree clazz, int index) { 1225 return delegate.removeClassTypeParameter(clazz, index); 1226 } 1227 1228 1236 public ClassTree addClassImplementsClause(ClassTree clazz, ExpressionTree implementsClause) { 1237 return delegate.addClassImplementsClause(clazz, implementsClause); 1238 } 1239 1240 1252 public ClassTree insertClassImplementsClause(ClassTree clazz, int index, ExpressionTree implementsClause) { 1253 return delegate.insertClassImplementsClause(clazz, index, implementsClause); 1254 } 1255 1256 1265 public ClassTree removeClassImplementsClause(ClassTree clazz, ExpressionTree implementsClause) { 1266 return delegate.removeClassImplementsClause(clazz, implementsClause); 1267 } 1268 1269 1280 public ClassTree removeClassImplementsClause(ClassTree clazz, int index) { 1281 return delegate.removeClassImplementsClause(clazz, index); 1282 } 1283 1284 1293 public CompilationUnitTree addCompUnitTypeDecl(CompilationUnitTree compilationUnit, Tree typeDeclaration) { 1294 return delegate.addCompUnitTypeDecl(compilationUnit, typeDeclaration); 1295 } 1296 1297 1309 public CompilationUnitTree insertCompUnitTypeDecl(CompilationUnitTree compilationUnit, int index, Tree typeDeclaration) { 1310 return delegate.insertCompUnitTypeDecl(compilationUnit, index, typeDeclaration); 1311 } 1312 1313 1322 public CompilationUnitTree removeCompUnitTypeDecl(CompilationUnitTree compilationUnit, Tree typeDeclaration) { 1323 return delegate.removeCompUnitTypeDecl(compilationUnit, typeDeclaration); 1324 } 1325 1326 1337 public CompilationUnitTree removeCompUnitTypeDecl(CompilationUnitTree compilationUnit, int index) { 1338 return delegate.removeCompUnitTypeDecl(compilationUnit, index); 1339 } 1340 1341 1348 public CompilationUnitTree addCompUnitImport(CompilationUnitTree compilationUnit, ImportTree importt) { 1349 return delegate.addCompUnitImport(compilationUnit, importt); 1350 } 1351 1352 1364 public CompilationUnitTree insertCompUnitImport(CompilationUnitTree compilationUnit, int index, ImportTree importt) { 1365 return delegate.insertCompUnitImport(compilationUnit, index, importt); 1366 } 1367 1368 1377 public CompilationUnitTree removeCompUnitImport(CompilationUnitTree compilationUnit, ImportTree importt) { 1378 return delegate.removeCompUnitImport(compilationUnit, importt); 1379 } 1380 1381 1392 public CompilationUnitTree removeCompUnitImport(CompilationUnitTree compilationUnit, int index) { 1393 return delegate.removeCompUnitImport(compilationUnit, index); 1394 } 1395 1396 1397 1398 1407 public ForLoopTree addForLoopInitializer(ForLoopTree forLoop, StatementTree initializer) { 1408 return delegate.addForLoopInitializer(forLoop, initializer); 1409 } 1410 1411 1423 public ForLoopTree insertForLoopInitializer(ForLoopTree forLoop, int index, StatementTree initializer) { 1424 return delegate.insertForLoopInitializer(forLoop, index, initializer); 1425 } 1426 1427 1436 public ForLoopTree removeForLoopInitializer(ForLoopTree forLoop, StatementTree initializer) { 1437 return delegate.removeForLoopInitializer(forLoop, initializer); 1438 } 1439 1440 1451 public ForLoopTree removeForLoopInitializer(ForLoopTree forLoop, int index) { 1452 return delegate.removeForLoopInitializer(forLoop, index); 1453 } 1454 1455 1464 public ForLoopTree addForLoopUpdate(ForLoopTree forLoop, ExpressionStatementTree update) { 1465 return delegate.addForLoopUpdate(forLoop, update); 1466 } 1467 1468 1480 public ForLoopTree insertForLoopUpdate(ForLoopTree forLoop, int index, ExpressionStatementTree update) { 1481 return delegate.insertForLoopUpdate(forLoop, index, update); 1482 } 1483 1484 1493 public ForLoopTree removeForLoopUpdate(ForLoopTree forLoop, ExpressionStatementTree update) { 1494 return delegate.removeForLoopUpdate(forLoop, update); 1495 } 1496 1497 1508 public ForLoopTree removeForLoopUpdate(ForLoopTree forLoop, int index) { 1509 return delegate.removeForLoopUpdate(forLoop, index); 1510 } 1511 1512 1522 public MethodInvocationTree addMethodInvocationArgument(MethodInvocationTree methodInvocation, ExpressionTree argument, ExpressionTree typeArgument) { 1523 return delegate.addMethodInvocationArgument(methodInvocation, argument, typeArgument); 1524 } 1525 1526 1539 public MethodInvocationTree insertMethodInvocationArgument(MethodInvocationTree methodInvocation, int index, ExpressionTree argument, ExpressionTree typeArgument) { 1540 return delegate.insertMethodInvocationArgument(methodInvocation, index, argument, typeArgument); 1541 } 1542 1543 1554 public MethodInvocationTree removeMethodInvocationArgument(MethodInvocationTree methodInvocation, ExpressionTree argument, ExpressionTree typeArgument) { 1555 return delegate.removeMethodInvocationArgument(methodInvocation, argument, typeArgument); 1556 } 1557 1558 1569 public MethodInvocationTree removeMethodInvocationArgument(MethodInvocationTree methodInvocation, int index) { 1570 return delegate.removeMethodInvocationArgument(methodInvocation, index); 1571 } 1572 1573 1582 public MethodTree addMethodParameter(MethodTree method, VariableTree parameter) { 1583 return delegate.addMethodParameter(method, parameter); 1584 } 1585 1586 1598 public MethodTree insertMethodParameter(MethodTree method, int index, VariableTree parameter) { 1599 return delegate.insertMethodParameter(method, index, parameter); 1600 } 1601 1602 1611 public MethodTree removeMethodParameter(MethodTree method, VariableTree parameter) { 1612 return delegate.removeMethodParameter(method, parameter); 1613 } 1614 1615 1626 public MethodTree removeMethodParameter(MethodTree method, int index) { 1627 return delegate.removeMethodParameter(method, index); 1628 } 1629 1630 1638 public MethodTree addMethodTypeParameter(MethodTree method, TypeParameterTree typeParameter) { 1639 return delegate.addMethodTypeParameter(method, typeParameter); 1640 } 1641 1642 1654 public MethodTree insertMethodTypeParameter(MethodTree method, int index, TypeParameterTree typeParameter) { 1655 return delegate.insertMethodTypeParameter(method, index, typeParameter); 1656 } 1657 1658 1667 public MethodTree removeMethodTypeParameter(MethodTree method, TypeParameterTree typeParameter) { 1668 return delegate.removeMethodTypeParameter(method, typeParameter); 1669 } 1670 1671 1682 public MethodTree removeMethodTypeParameter(MethodTree method, int index) { 1683 return delegate.removeMethodTypeParameter(method, index); 1684 } 1685 1686 1694 public MethodTree addMethodThrows(MethodTree method, ExpressionTree throwz) { 1695 return delegate.addMethodThrows(method, throwz); 1696 } 1697 1698 1710 public MethodTree insertMethodThrows(MethodTree method, int index, ExpressionTree throwz) { 1711 return delegate.insertMethodThrows(method, index, throwz); 1712 } 1713 1714 1723 public MethodTree removeMethodThrows(MethodTree method, ExpressionTree throwz) { 1724 return delegate.removeMethodThrows(method, throwz); 1725 } 1726 1727 1738 public MethodTree removeMethodThrows(MethodTree method, int index) { 1739 return delegate.removeMethodThrows(method, index); 1740 } 1741 1742 1751 public ModifiersTree addModifiersAnnotation(ModifiersTree modifiers, AnnotationTree annotation) { 1752 return delegate.addModifiersAnnotation(modifiers, annotation); 1753 } 1754 1755 1767 public ModifiersTree insertModifiersAnnotation(ModifiersTree modifiers, int index, AnnotationTree annotation) { 1768 return delegate.insertModifiersAnnotation(modifiers, index, annotation); 1769 } 1770 1771 1780 public ModifiersTree removeModifiersAnnotation(ModifiersTree modifiers, AnnotationTree annotation) { 1781 return delegate.removeModifiersAnnotation(modifiers, annotation); 1782 } 1783 1784 1795 public ModifiersTree removeModifiersAnnotation(ModifiersTree modifiers, int index) { 1796 return delegate.removeModifiersAnnotation(modifiers, index); 1797 } 1798 1799 1808 public NewArrayTree addNewArrayDimension(NewArrayTree newArray, ExpressionTree dimension) { 1809 return delegate.addNewArrayDimension(newArray, dimension); 1810 } 1811 1812 1824 public NewArrayTree insertNewArrayDimension(NewArrayTree newArray, int index, ExpressionTree dimension) { 1825 return delegate.insertNewArrayDimension(newArray, index, dimension); 1826 } 1827 1828 1837 public NewArrayTree removeNewArrayDimension(NewArrayTree newArray, ExpressionTree dimension) { 1838 return delegate.removeNewArrayDimension(newArray, dimension); 1839 } 1840 1841 1852 public NewArrayTree removeNewArrayDimension(NewArrayTree newArray, int index) { 1853 return delegate.removeNewArrayDimension(newArray, index); 1854 } 1855 1856 1865 public NewArrayTree addNewArrayInitializer(NewArrayTree newArray, ExpressionTree initializer) { 1866 return delegate.addNewArrayInitializer(newArray, initializer); 1867 } 1868 1869 1881 public NewArrayTree insertNewArrayInitializer(NewArrayTree newArray, int index, ExpressionTree initializer) { 1882 return delegate.insertNewArrayInitializer(newArray, index, initializer); 1883 } 1884 1885 1894 public NewArrayTree removeNewArrayInitializer(NewArrayTree newArray, ExpressionTree initializer) { 1895 return delegate.removeNewArrayInitializer(newArray, initializer); 1896 } 1897 1898 1909 public NewArrayTree removeNewArrayInitializer(NewArrayTree newArray, int index) { 1910 return delegate.removeNewArrayInitializer(newArray, index); 1911 } 1912 1913 1923 public NewClassTree addNewClassArgument(NewClassTree newClass, ExpressionTree typeArgument, ExpressionTree argument) { 1924 return delegate.addNewClassArgument(newClass, typeArgument, argument); 1925 } 1926 1927 1940 public NewClassTree insertNewClassArgument(NewClassTree newClass, int index, ExpressionTree typeArgument, ExpressionTree argument) { 1941 return delegate.insertNewClassArgument(newClass, index, typeArgument, argument); 1942 } 1943 1944 1955 public NewClassTree removeNewClassArgument(NewClassTree newClass, ExpressionTree typeArgument, ExpressionTree argument) { 1956 return delegate.removeNewClassArgument(newClass, typeArgument, argument); 1957 } 1958 1959 1970 public NewClassTree removeNewClassArgument(NewClassTree newClass, int index) { 1971 return delegate.removeNewClassArgument(newClass, index); 1972 } 1973 1974 1983 public ParameterizedTypeTree addParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, ExpressionTree argument) { 1984 return delegate.addParameterizedTypeTypeArgument(parameterizedType, argument); 1985 } 1986 1987 1999 public ParameterizedTypeTree insertParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, int index, ExpressionTree argument) { 2000 return delegate.insertParameterizedTypeTypeArgument(parameterizedType, index, argument); 2001 } 2002 2003 2012 public ParameterizedTypeTree removeParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, ExpressionTree argument) { 2013 return delegate.removeParameterizedTypeTypeArgument(parameterizedType, argument); 2014 } 2015 2016 2027 public ParameterizedTypeTree removeParameterizedTypeTypeArgument(ParameterizedTypeTree parameterizedType, int index) { 2028 return delegate.removeParameterizedTypeTypeArgument(parameterizedType, index); 2029 } 2030 2031 2040 public SwitchTree addSwitchCase(SwitchTree swic, CaseTree kejs) { 2041 return delegate.addSwitchCase(swic, kejs); 2042 } 2043 2044 2056 public SwitchTree insertSwitchCase(SwitchTree swic, int index, CaseTree kejs) { 2057 return delegate.insertSwitchCase(swic, index, kejs); 2058 } 2059 2060 2069 public SwitchTree removeSwitchCase(SwitchTree swic, CaseTree kejs) { 2070 return delegate.removeSwitchCase(swic, kejs); 2071 } 2072 2073 2084 public SwitchTree removeSwitchCase(SwitchTree swic, int index) { 2085 return delegate.removeSwitchCase(swic, index); 2086 } 2087 2088 2097 public TryTree addTryCatch(TryTree traj, CatchTree kec) { 2098 return delegate.addTryCatch(traj, kec); 2099 } 2100 2101 2113 public TryTree insertTryCatch(TryTree traj, int index, CatchTree kec) { 2114 return delegate.insertTryCatch(traj, index, kec); 2115 } 2116 2117 2126 public TryTree removeTryCatch(TryTree traj, CatchTree kec) { 2127 return delegate.removeTryCatch(traj, kec); 2128 } 2129 2130 2141 public TryTree removeTryCatch(TryTree traj, int index) { 2142 return delegate.removeTryCatch(traj, index); 2143 } 2144 2145 2153 public TypeParameterTree addTypeParameterBound(TypeParameterTree typeParameter, ExpressionTree bound) { 2154 return delegate.addTypeParameterBound(typeParameter, bound); 2155 } 2156 2157 2169 public TypeParameterTree insertTypeParameterBound(TypeParameterTree typeParameter, int index, ExpressionTree bound) { 2170 return delegate.insertTypeParameterBound(typeParameter, index, bound); 2171 } 2172 2173 2182 public TypeParameterTree removeTypeParameterBound(TypeParameterTree typeParameter, ExpressionTree bound) { 2183 return delegate.removeTypeParameterBound(typeParameter, bound); 2184 } 2185 2186 2197 public TypeParameterTree removeTypeParameterBound(TypeParameterTree typeParameter, int index) { 2198 return delegate.removeTypeParameterBound(typeParameter, index); 2199 } 2200 2201 2239 public <N extends Tree> N setLabel(final N node, final CharSequence aLabel) { 2240 return delegate.setLabel(node, aLabel); 2241 } 2242 2243 2280 public ClassTree setExtends(final ClassTree node, final ExpressionTree extendz) { 2281 ClassTree copy = Class( 2282 node.getModifiers(), 2283 node.getSimpleName(), 2284 node.getTypeParameters(), 2285 extendz, 2286 (List <ExpressionTree>) node.getImplementsClause(), node.getMembers() 2288 ); 2289 return copy; 2290 } 2291 2292 2328 public <N extends Tree> N setInitialValue(final N node, ExpressionTree initializer) { 2329 switch (node.getKind()) { 2330 case VARIABLE: { 2331 VariableTree t = (VariableTree) node; 2332 N clone = (N) Variable( 2333 t.getModifiers(), 2334 t.getName(), 2335 t.getType(), 2336 initializer 2337 ); 2338 return clone; 2339 } 2340 case METHOD: { 2341 MethodTree t = (MethodTree) node; 2342 N clone = (N) Method( 2343 t.getModifiers(), 2344 t.getName(), 2345 t.getReturnType(), 2346 t.getTypeParameters(), 2347 t.getParameters(), 2348 t.getThrows(), 2349 t.getBody(), 2350 initializer 2351 ); 2352 return clone; 2353 } 2354 default: 2355 throw new IllegalArgumentException ("Invalid kind " + node.getKind()); 2356 } 2357 } 2358 2359 2368 public void addComment(Tree tree, Comment comment, boolean preceding) throws IllegalStateException { 2369 insertComment(tree, comment, -1, preceding); 2370 } 2371 2372 2381 public void insertComment(Tree tree, Comment comment, int index, boolean preceding) throws IllegalStateException { 2382 if (handler == null) { 2383 throw new IllegalStateException ("Cannot modify comments outside runModificationTask."); 2384 } 2385 2386 CommentSet set = handler.getComments(tree); 2387 2388 if (set == null) { 2389 if (index != 0 && index != (-1)) 2390 throw new IllegalArgumentException ("Index out of bounds: " + index); 2391 2392 handler.addComment(tree, comment); 2393 2394 if (!preceding) { 2395 set = handler.getComments(tree); 2396 2397 assert set != null; 2398 2399 set.addTrailingComment(comment); 2400 set.getPrecedingComments().remove(comment); 2401 } 2402 } else { 2403 if (index == (-1)) { 2404 if (preceding) 2405 set.addPrecedingComment(comment); 2406 else 2407 set.addTrailingComment(comment); 2408 } else { 2409 List <Comment> comments; 2410 2411 if (preceding) { 2412 comments = set.getPrecedingComments(); 2413 } else { 2414 comments = set.getTrailingComments(); 2415 } 2416 2417 if (comments.size() > index) { 2418 comments.add(index, comment); 2419 } else { 2420 throw new IllegalArgumentException ("Index out of bounds, index=" + index + ", length=" + comments.size()); 2421 } 2422 } 2423 } 2424 } 2425 2426 2433 public void removeComment(Tree tree, int index, boolean preceding) throws IllegalStateException { 2434 if (handler == null) { 2435 throw new IllegalStateException ("Cannot modify comments outside runModificationTask."); 2436 } 2437 2438 CommentSet set = handler.getComments(tree); 2439 2440 if (set == null) { 2441 throw new IllegalArgumentException ("Index out of bounds: " + index); 2442 } 2443 2444 List <Comment> comments; 2445 2446 if (preceding) { 2447 comments = set.getPrecedingComments(); 2448 } else { 2449 comments = set.getTrailingComments(); 2450 } 2451 2452 if (comments.size() > index) { 2453 comments.remove(index); 2454 } else { 2455 throw new IllegalArgumentException ("Index out of bounds, index=" + index + ", length=" + comments.size()); 2456 } 2457 } 2458 2459 2466 public BlockTree createMethodBody(MethodTree method, String bodyText) { 2467 SourcePositions[] positions = new SourcePositions[1]; 2468 final TreeUtilities treeUtils = copy.getTreeUtilities(); 2469 StatementTree body = treeUtils.parseStatement(bodyText, positions); 2470 assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; 2471 Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), method)); 2472 treeUtils.attributeTree(body, scope); 2473 mapComments((BlockTree) body, bodyText, copy, handler); 2474 return (BlockTree) body; 2475 } 2476 2477 2491 public MethodTree Method(ModifiersTree modifiers, 2492 CharSequence name, 2493 Tree returnType, 2494 List <? extends TypeParameterTree> typeParameters, 2495 List <? extends VariableTree> parameters, 2496 List <? extends ExpressionTree> throwsList, 2497 String bodyText, 2498 ExpressionTree defaultValue) 2499 { 2500 SourcePositions[] positions = new SourcePositions[1]; 2501 StatementTree body = copy.getTreeUtilities().parseStatement(bodyText, positions); 2502 assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; 2503 mapComments((BlockTree) body, bodyText, copy, handler); 2504 return delegate.Method(modifiers, name, returnType, typeParameters, parameters, throwsList, (BlockTree) body, defaultValue); 2505 } 2506 2507 private void mapComments(BlockTree block, String inputText, WorkingCopy copy, CommentHandler comments) { 2508 final EnumSet <JavaTokenId> nonRelevant = EnumSet.of( 2509 JavaTokenId.LINE_COMMENT, 2510 JavaTokenId.BLOCK_COMMENT, 2511 JavaTokenId.JAVADOC_COMMENT, 2512 JavaTokenId.WHITESPACE 2513 ); 2514 TokenSequence<JavaTokenId> seq = TokenHierarchy.create(inputText, JavaTokenId.language()).tokenSequence(JavaTokenId.language()); 2515 List <? extends StatementTree> trees = block.getStatements(); 2516 SourcePositions pos = copy.getTrees().getSourcePositions(); 2517 for (StatementTree statement : trees) { 2518 seq.move((int) pos.getStartPosition(null, statement)); 2519 seq.moveNext(); 2520 while (seq.movePrevious() && nonRelevant.contains(seq.token().id())) { 2521 switch (seq.token().id()) { 2522 case LINE_COMMENT: 2523 comments.addComment(statement, Comment.create(Style.LINE, Query.NOPOS, Query.NOPOS, Query.NOPOS, seq.token().toString())); 2524 break; 2525 case BLOCK_COMMENT: 2526 comments.addComment(statement, Comment.create(Style.BLOCK, Query.NOPOS, Query.NOPOS, Query.NOPOS, seq.token().toString())); 2527 break; 2528 case JAVADOC_COMMENT: 2529 comments.addComment(statement, Comment.create(Style.JAVADOC, Query.NOPOS, Query.NOPOS, Query.NOPOS, seq.token().toString())); 2530 break; 2531 } 2532 } 2533 } 2534 } 2535 2536} 2537 | Popular Tags |