0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.api.java.source;
0042:
0043: import com.sun.source.tree.*;
0044: import org.netbeans.modules.java.source.parsing.FileObjects;
0045: import org.openide.filesystems.FileObject;
0046: import static com.sun.source.tree.Tree.*;
0047:
0048: import com.sun.source.util.SourcePositions;
0049: import com.sun.source.util.TreePath;
0050:
0051: import com.sun.tools.javac.code.Flags;
0052: import com.sun.tools.javac.tree.JCTree.JCModifiers;
0053: import javax.lang.model.element.*;
0054: import javax.lang.model.type.*;
0055: import javax.tools.JavaFileObject;
0056:
0057: import java.util.List;
0058: import java.util.Set;
0059:
0060: import org.netbeans.api.lexer.TokenHierarchy;
0061: import org.netbeans.api.lexer.TokenSequence;
0062:
0063: import org.netbeans.api.java.lexer.JavaTokenId;
0064:
0065: import org.netbeans.modules.java.source.query.CommentHandler;
0066: import org.netbeans.modules.java.source.query.CommentSet;
0067: import org.netbeans.api.java.source.Comment.Style;
0068: import org.netbeans.modules.java.source.query.CommentHandler;
0069:
0070: import org.netbeans.modules.java.source.builder.CommentHandlerService;
0071: import org.netbeans.modules.java.source.builder.TreeFactory;
0072: import org.netbeans.modules.java.source.save.PositionEstimator;
0073: import static org.netbeans.modules.java.source.save.PositionEstimator.*;
0074:
0075: /**
0076: * Factory interface for creating new com.sun.source.tree instances. The
0077: * parameters for each method correspond as closely as possible to the
0078: * accessor methods for each tree interface.<br>
0079: *
0080: * You can obtain appropriate instance of this class by getting it from working
0081: * copy:
0082: *
0083: * <pre>
0084: * CancellableTask task = new CancellableTask<WorkingCopy>() {
0085: *
0086: * public void run(WorkingCopy workingCopy) throws Exception {
0087: * <b>TreeMaker make = workingCopy.getTreeMaker()</b>;
0088: * ... your modification code here
0089: * }
0090: * ...
0091: * };
0092: * </pre>
0093: *
0094: * @see <a href="http://wiki.netbeans.org/wiki/view/JavaHT_Modification">How do I do modification to a source file?</a>
0095: *
0096: * @author Tom Ball
0097: * @author Pavel Flaska
0098: */
0099: public final class TreeMaker {
0100:
0101: private TreeFactory delegate;
0102: private CommentHandler handler;
0103: private WorkingCopy copy;
0104:
0105: TreeMaker(WorkingCopy copy, TreeFactory delegate) {
0106: this .delegate = delegate;
0107: this .copy = copy;
0108: this .handler = CommentHandlerService.instance(copy.impl
0109: .getJavacTask().getContext());
0110: }
0111:
0112: /**
0113: * Creates a new AnnotationTree.
0114: *
0115: * @param type the annotation type.
0116: * @param arguments the arguments for this annotation, or an empty list.
0117: * @see com.sun.source.tree.AnnotationTree
0118: */
0119: public AnnotationTree Annotation(Tree type,
0120: List<? extends ExpressionTree> arguments) {
0121: return delegate.Annotation(type, arguments);
0122: }
0123:
0124: /**
0125: * Creates a new ArrayAccessTree.
0126: *
0127: * @param array the array expression.
0128: * @param index the array index.
0129: * @see com.sun.source.tree.ArrayAccessTree
0130: */
0131: public ArrayAccessTree ArrayAccess(ExpressionTree array,
0132: ExpressionTree index) {
0133: return delegate.ArrayAccess(array, index);
0134: }
0135:
0136: /**
0137: * Creates a new ArrayTypeTree.
0138: *
0139: * @param type the array type.
0140: * @see com.sun.source.tree.ArrayTypeTree
0141: */
0142: public ArrayTypeTree ArrayType(Tree type) {
0143: return delegate.ArrayType(type);
0144: }
0145:
0146: /**
0147: * Creates a new AssertTree.
0148: *
0149: * @param condition the boolean expression to test.
0150: * @param detail the detail message to include if the assertion fails.
0151: * @see com.sun.source.tree.AssertTree
0152: */
0153: public AssertTree Assert(ExpressionTree condition,
0154: ExpressionTree detail) {
0155: return delegate.Assert(condition, detail);
0156: }
0157:
0158: /**
0159: * Creates a new AssignmentTree.
0160: *
0161: * @param variable the variable the expression is assigned to.
0162: * @param expression the expression to assign to the variable.
0163: * @see com.sun.source.tree.AssignmentTree
0164: */
0165: public AssignmentTree Assignment(ExpressionTree variable,
0166: ExpressionTree expression) {
0167: return delegate.Assignment(variable, expression);
0168: }
0169:
0170: /**
0171: * Creates a new BinaryTree.
0172: *
0173: * @param operator the operator for this tree, such as Tree.Kind.PLUS.
0174: * @param left the left operand of the tree.
0175: * @param right the right operand of the tree.
0176: * @see com.sun.source.tree.BinaryTree
0177: * @see com.sun.source.tree.Tree.Kind
0178: */
0179: public BinaryTree Binary(Kind operator, ExpressionTree left,
0180: ExpressionTree right) {
0181: return delegate.Binary(operator, left, right);
0182: }
0183:
0184: /**
0185: * Creates a new BlockTree.
0186: *
0187: * @param statements the list of statements to be contained within the block.
0188: * @param isStatic true if the block defines a static initializer for a class. ExpressionTree getCondition();
0189: ExpressionTree getDetail();
0190:
0191: * @see com.sun.source.tree.BlockTree
0192: */
0193: public BlockTree Block(List<? extends StatementTree> statements,
0194: boolean isStatic) {
0195: return delegate.Block(statements, isStatic);
0196: }
0197:
0198: /**
0199: * Creates a new BreakTree.
0200: *
0201: * @param label the label to break to, or null if there is no label.
0202: * @see com.sun.source.tree.BreakTree
0203: */
0204: public BreakTree Break(CharSequence label) {
0205: return delegate.Break(label);
0206: }
0207:
0208: /**
0209: * Creates a new CaseTree.
0210: *
0211: * @param expression the label for this case statement.
0212: * @param statements the list of statements.
0213: * @see com.sun.source.tree.CaseTree
0214: */
0215: public CaseTree Case(ExpressionTree expression,
0216: List<? extends StatementTree> statements) {
0217: return delegate.Case(expression, statements);
0218: }
0219:
0220: /**
0221: * Creates a new CatchTree.
0222: *
0223: * @param parameter the exception variable declaration.
0224: * @param block the block of statements executed by this catch statement.
0225: * @see com.sun.source.tree.CatchTree
0226: */
0227: public CatchTree Catch(VariableTree parameter, BlockTree block) {
0228: return delegate.Catch(parameter, block);
0229: }
0230:
0231: /**
0232: * Creates a new ClassTree.
0233: *
0234: * @param modifiers the modifiers declaration
0235: * @param simpleName the name of the class without its package, such
0236: * as "String" for the class "java.lang.String".
0237: * @param typeParameters the list of type parameters, or an empty list.
0238: * @param extendsClause the name of the class this class extends, or null.
0239: * @param implementsClauses the list of the interfaces this class
0240: * implements, or an empty list.
0241: * @param memberDecls the list of fields defined by this class, or an
0242: * empty list.
0243: * @see com.sun.source.tree.ClassTree
0244: */
0245: public ClassTree Class(ModifiersTree modifiers,
0246: CharSequence simpleName,
0247: List<? extends TypeParameterTree> typeParameters,
0248: Tree extendsClause, List<? extends Tree> implements Clauses,
0249: List<? extends Tree> memberDecls) {
0250: return delegate.Class(modifiers, simpleName, typeParameters,
0251: extendsClause, implements Clauses, memberDecls);
0252: }
0253:
0254: /**
0255: * Creates a new ClassTree representing interface.
0256: *
0257: * @param modifiers the modifiers declaration
0258: * @param simpleName the name of the class without its package, such
0259: * as "String" for the class "java.lang.String".
0260: * @param typeParameters the list of type parameters, or an empty list.
0261: * @param extendsClauses the list of the interfaces this class
0262: * extends, or an empty list.
0263: * @param memberDecls the list of fields defined by this class, or an
0264: * empty list.
0265: * @see com.sun.source.tree.ClassTree
0266: */
0267: public ClassTree Interface(ModifiersTree modifiers,
0268: CharSequence simpleName,
0269: List<? extends TypeParameterTree> typeParameters,
0270: List<? extends Tree> extendsClauses,
0271: List<? extends Tree> memberDecls) {
0272: return delegate.Interface(modifiers, simpleName,
0273: typeParameters, extendsClauses, memberDecls);
0274: }
0275:
0276: /**
0277: * Creates a new ClassTree representing annotation type.
0278: *
0279: * @param modifiers the modifiers declaration
0280: * @param simpleName the name of the class without its package, such
0281: * as "String" for the class "java.lang.String".
0282: * @param memberDecls the list of fields defined by this class, or an
0283: * empty list.
0284: * @see com.sun.source.tree.ClassTree
0285: */
0286: public ClassTree AnnotationType(ModifiersTree modifiers,
0287: CharSequence simpleName, List<? extends Tree> memberDecls) {
0288: return delegate.AnnotationType(modifiers, simpleName,
0289: memberDecls);
0290: }
0291:
0292: /**
0293: * Creates a new ClassTree representing enum.
0294: *
0295: * @param modifiers the modifiers declaration
0296: * @param simpleName the name of the class without its package, such
0297: * as "String" for the class "java.lang.String".
0298: * @param implementsClauses the list of the interfaces this class
0299: * implements, or an empty list.
0300: * @param memberDecls the list of fields defined by this class, or an
0301: * empty list.
0302: * @see com.sun.source.tree.ClassTree
0303: */
0304: public ClassTree Enum(ModifiersTree modifiers,
0305: CharSequence simpleName,
0306: List<? extends Tree> implements Clauses,
0307: List<? extends Tree> memberDecls) {
0308: return delegate.Enum(modifiers, simpleName, implements Clauses,
0309: memberDecls);
0310: }
0311:
0312: /**
0313: * Creates a new CompilationUnitTree.
0314: *
0315: * @param packageName a tree representing the package name.
0316: * @param imports a list of import statements.
0317: * @param typeDeclarations a list of type (class, interface or enum) declarations.
0318: * @param sourceFile the source file associated with this compilation unit.
0319: * @see com.sun.source.tree.CompilationUnitTree
0320: */
0321: public CompilationUnitTree CompilationUnit(
0322: ExpressionTree packageName,
0323: List<? extends ImportTree> imports,
0324: List<? extends Tree> typeDeclarations,
0325: JavaFileObject sourceFile) {
0326: return delegate.CompilationUnit(packageName, imports,
0327: typeDeclarations, sourceFile);
0328: }
0329:
0330: /**
0331: * Creates a new CompilationUnitTree.
0332: * @param sourceRoot a source root under which the new file is created
0333: * @param path a relative path to file separated by '/'
0334: * @param imports a list of import statements.
0335: * @param typeDeclarations a list of type (class, interface or enum) declarations.
0336: * @see com.sun.source.tree.CompilationUnitTree
0337: */
0338: public CompilationUnitTree CompilationUnit(FileObject sourceRoot,
0339: String path, List<? extends ImportTree> imports,
0340: List<? extends Tree> typeDeclarations) {
0341: String[] nameComponent = FileObjects.getFolderAndBaseName(path,
0342: '/'); //NOI18N
0343: JavaFileObject sourceFile = FileObjects.templateFileObject(
0344: sourceRoot, nameComponent[0], nameComponent[1]);
0345: return delegate.CompilationUnit(Identifier(nameComponent[0]
0346: .replace('/', '.')), imports, typeDeclarations,
0347: sourceFile);
0348: }
0349:
0350: /**
0351: * Creates a new CompoundAssignmentTree.
0352: *
0353: * @param operator the operator for this tree, such as Tree.Kind.PLUS_ASSIGNMENT.
0354: * @param variable the variable the expression is assigned to.
0355: * @param expression the expression to assign to the variable.
0356: * @see com.sun.source.tree.CompoundAssignmentTree
0357: */
0358: public CompoundAssignmentTree CompoundAssignment(Kind operator,
0359: ExpressionTree variable, ExpressionTree expression) {
0360: return delegate.CompoundAssignment(operator, variable,
0361: expression);
0362: }
0363:
0364: /**
0365: * Creates a new ConditionalExpressionTree.
0366: *
0367: * @param condition the boolean expression to test.
0368: * @param trueExpression the expression to be executed when the
0369: * condition is true.
0370: * @param falseExpression the expression to be executed when the
0371: * condition is false.
0372: * @see com.sun.source.tree.ConditionalExpressionTree
0373: */
0374: public ConditionalExpressionTree ConditionalExpression(
0375: ExpressionTree condition, ExpressionTree trueExpression,
0376: ExpressionTree falseExpression) {
0377: return delegate.ConditionalExpression(condition,
0378: trueExpression, falseExpression);
0379: }
0380:
0381: /**
0382: * Creates a new MethodTree representing constructor.
0383: *
0384: * @param modifiers the modifiers of this method.
0385: * @param typeParameters the list of generic type parameters, or an empty list.
0386: * @param parameters the list of parameters, or an empty list.
0387: * @param throwsList the list of throws clauses, or an empty list.
0388: * @param body the method's code block.
0389: * @see com.sun.source.tree.MethodTree
0390: */
0391: public MethodTree Constructor(ModifiersTree modifiers,
0392: List<? extends TypeParameterTree> typeParameters,
0393: List<? extends VariableTree> parameters,
0394: List<? extends ExpressionTree> throwsList, BlockTree body) {
0395: return delegate.Method(modifiers, "<init>", null,
0396: typeParameters, parameters, throwsList, body, null);
0397: }
0398:
0399: /**
0400: * Creates a new MethodTree representing constructor.
0401: *
0402: * @param modifiers the modifiers of this method.
0403: * @param typeParameters the list of generic type parameters, or an empty list.
0404: * @param parameters the list of parameters, or an empty list.
0405: * @param throwsList the list of throws clauses, or an empty list.
0406: * @param bodyText the method's code block provided as a plain text
0407: * @see com.sun.source.tree.MethodTree
0408: */
0409: public MethodTree Constructor(ModifiersTree modifiers,
0410: List<? extends TypeParameterTree> typeParameters,
0411: List<? extends VariableTree> parameters,
0412: List<? extends ExpressionTree> throwsList, String bodyText) {
0413: return Method(modifiers, "<init>", null, typeParameters,
0414: parameters, throwsList, bodyText, null);
0415: }
0416:
0417: /**
0418: * Creates a new ContinueTree.
0419: *
0420: * @param label the label to break to, or null if there is no label.
0421: * @see com.sun.source.tree.ContinueTree
0422: */
0423: public ContinueTree Continue(CharSequence label) {
0424: return delegate.Continue(label);
0425: }
0426:
0427: /** Creates a new DoWhileLoopTree.
0428: *
0429: * @param condition the boolean expression to test.
0430: * @param statement the statement to execute while the condition is true.
0431: * @see com.sun.source.tree.DoWhileLoopTree
0432: */
0433: public DoWhileLoopTree DoWhileLoop(ExpressionTree condition,
0434: StatementTree statement) {
0435: return delegate.DoWhileLoop(condition, statement);
0436: }
0437:
0438: /**
0439: * Creates a new EmptyStatementTree.
0440: *
0441: * @see com.sun.source.tree.EmptyStatementTree
0442: */
0443: public EmptyStatementTree EmptyStatement() {
0444: return delegate.EmptyStatement();
0445: }
0446:
0447: /**
0448: * Creates a new EnhancedForLoopTree.
0449: *
0450: * @param variable the loop variable declaration.
0451: * @param expression the expression to be iterated.
0452: * @param statement the statement to execute each iteration.
0453: * @see com.sun.source.tree.EnhancedForLoopTree
0454: */
0455: public EnhancedForLoopTree EnhancedForLoop(VariableTree variable,
0456: ExpressionTree expression, StatementTree statement) {
0457: return delegate
0458: .EnhancedForLoop(variable, expression, statement);
0459: }
0460:
0461: /**
0462: * Creates a new ErroneousTree.
0463: *
0464: * @param errorTrees a list of trees with possible errors.
0465: * @see com.sun.source.tree.ErroneousTree
0466: */
0467: public ErroneousTree Erroneous(List<? extends Tree> errorTrees) {
0468: return delegate.Erroneous(errorTrees);
0469: }
0470:
0471: /**
0472: * Creates a new ExpressionStatementTree.
0473: *
0474: * @param expression the expression body for this statement.
0475: * @see com.sun.source.tree.ExpressionStatementTree
0476: */
0477: public ExpressionStatementTree ExpressionStatement(
0478: ExpressionTree expression) {
0479: return delegate.ExpressionStatement(expression);
0480: }
0481:
0482: /**
0483: * Creates a new ForLoopTree.
0484: *
0485: * @param initializer a list of initializer statements, or an empty list.
0486: * @param condition the condition to evaluate after each iteration.
0487: * @param update the statements to execute after each iteration.
0488: * @param statement the statement to execute for each iteration.
0489: * @see com.sun.source.tree.ForLoopTree
0490: */
0491: public ForLoopTree ForLoop(
0492: List<? extends StatementTree> initializer,
0493: ExpressionTree condition,
0494: List<? extends ExpressionStatementTree> update,
0495: StatementTree statement) {
0496: return delegate.ForLoop(initializer, condition, update,
0497: statement);
0498: }
0499:
0500: /**
0501: * Creates a new IdentifierTree.
0502: *
0503: * @param name the name of the identifier.
0504: * @see com.sun.source.tree.IdentifierTree
0505: */
0506: public IdentifierTree Identifier(CharSequence name) {
0507: return delegate.Identifier(name);
0508: }
0509:
0510: /**
0511: * Creates a new IdentifierTree from an Element.
0512: *
0513: * @param element the element from which to extract the identifier name.
0514: * @see com.sun.source.tree.IdentifierTree
0515: * @see javax.lang.model.element.Element
0516: */
0517: public IdentifierTree Identifier(Element element) {
0518: return delegate.Identifier(element);
0519: }
0520:
0521: /** Creates a new IfTree.
0522: *
0523: * @param condition the boolean expression to test.
0524: * @param thenStatement the statement to execute if the condition is true.
0525: * @param elseStatement the statement to execute if the condition if false.
0526: * A null value should be used if there is no else
0527: * statement.
0528: * @see com.sun.source.tree.IfTree
0529: */
0530: public IfTree If(ExpressionTree condition,
0531: StatementTree thenStatement, StatementTree elseStatement) {
0532: return delegate.If(condition, thenStatement, elseStatement);
0533: }
0534:
0535: /**
0536: * Creates a new ImportTree.
0537: *
0538: * @param qualid fully qualified identifier.
0539: * @param importStatic true if static import statement.
0540: * @see com.sun.source.tree.ImportTree
0541: */
0542: public ImportTree Import(Tree qualid, boolean importStatic) {
0543: return delegate.Import(qualid, importStatic);
0544: }
0545:
0546: /**
0547: * Creates a new InstanceOfTree.
0548: *
0549: * @param expression the expression whose type is being checked.
0550: * @param type the type to compare to.
0551: * @see com.sun.source.tree.InstanceOfTree
0552: */
0553: public InstanceOfTree InstanceOf(ExpressionTree expression,
0554: Tree type) {
0555: return delegate.InstanceOf(expression, type);
0556: }
0557:
0558: /**
0559: * Creates a new LabeledStatementTree.
0560: *
0561: * @param label the label string.
0562: * @param statement the statement being labeled.
0563: * @see com.sun.source.tree.LabeledStatementTree
0564: */
0565: public LabeledStatementTree LabeledStatement(CharSequence label,
0566: StatementTree statement) {
0567: return delegate.LabeledStatement(label, statement);
0568: }
0569:
0570: /**
0571: * Creates a new LiteralTree. Only literals which are wrappers for
0572: * primitive types (Integer, Boolean, etc.) and String instances can
0573: * be literals.
0574: *
0575: * @param value the value of the literal.
0576: * @throws IllegalArgumentException for illegal literal values.
0577: * @see com.sun.source.tree.LiteralTree
0578: */
0579: public LiteralTree Literal(Object value) {
0580: return delegate.Literal(value);
0581: }
0582:
0583: /**
0584: * Creates a new MemberSelectTree. A MemberSelectTree consists of an
0585: * expression and an identifier. Valid expressions include things like
0586: * packages, class and field references, etc., while the identifier is a
0587: * "child" of the expression. For example, "System.out" is represented by
0588: * MemberSelectTree which has an ExpressionTree representing "System" and
0589: * an identifier of "out".
0590: *
0591: * @param expression the expression the identifier is part of.
0592: * @param identifier the element to select.
0593: * @see com.sun.source.tree.MemberSelectTree
0594: */
0595: public MemberSelectTree MemberSelect(ExpressionTree expression,
0596: CharSequence identifier) {
0597: return delegate.MemberSelect(expression, identifier);
0598: }
0599:
0600: /**
0601: * Creates a new MemberSelectTree from an expression and an element.
0602: *
0603: * @param expression the expression the identifier is part of.
0604: * @param element the element that provides the identifier name.
0605: * @see com.sun.source.tree.MemberSelectTree
0606: * @see javax.lang.model.element.Element
0607: */
0608: public MemberSelectTree MemberSelect(ExpressionTree expression,
0609: Element element) {
0610: return delegate.MemberSelect(expression, element);
0611: }
0612:
0613: /**
0614: * Creates a new MethodInvocationTree.
0615: *
0616: * @param typeArguments the list of generic type arguments, or an empty list.
0617: * @param method the method to be invoked.
0618: * @param arguments the list of arguments to pass to the method, or an empty list.
0619: * @see com.sun.source.tree.MethodInvocationTree
0620: */
0621: public MethodInvocationTree MethodInvocation(
0622: List<? extends ExpressionTree> typeArguments,
0623: ExpressionTree method,
0624: List<? extends ExpressionTree> arguments) {
0625: return delegate.MethodInvocation(typeArguments, method,
0626: arguments);
0627: }
0628:
0629: /**
0630: * Creates a new MethodTree.
0631: *
0632: * @param modifiers the modifiers of this method.
0633: * @param name the name of the method.
0634: * @param returnType the return type for this method.
0635: * @param typeParameters the list of generic type parameters, or an empty list.
0636: * @param parameters the list of parameters, or an empty list.
0637: * @param throwsList the list of throws clauses, or an empty list.
0638: * @param body the method's code block.
0639: * @param defaultValue the default value, used by annotation types.
0640: * @see com.sun.source.tree.MethodTree
0641: */
0642: public MethodTree Method(ModifiersTree modifiers,
0643: CharSequence name, Tree returnType,
0644: List<? extends TypeParameterTree> typeParameters,
0645: List<? extends VariableTree> parameters,
0646: List<? extends ExpressionTree> throwsList, BlockTree body,
0647: ExpressionTree defaultValue) {
0648: return delegate.Method(modifiers, name, returnType,
0649: typeParameters, parameters, throwsList, body,
0650: defaultValue);
0651: }
0652:
0653: /**
0654: * Creates a new MethodTree from an ExecutableElement and a BlockTree.
0655: *
0656: * @param element the executable element of this method.
0657: * @param body the method's code block, or null for native, abstract,
0658: * and interface methods.
0659: * @see com.sun.source.tree.MethodTree
0660: * @see javax.lang.model.element.ExecutableElement
0661: */
0662: public MethodTree Method(ExecutableElement element, BlockTree body) {
0663: return delegate.Method(element, body);
0664: }
0665:
0666: /**
0667: * Creates a new ModifiersTree with a new set of flags and annotations.
0668: *
0669: * @param flags the set of modifier flags
0670: * @param annotations a list of annotations, or an empty list.
0671: * @see com.sun.source.tree.ModifiersTree
0672: * @see javax.lang.model.element.Modifier
0673: */
0674: public ModifiersTree Modifiers(Set<Modifier> flags,
0675: List<? extends AnnotationTree> annotations) {
0676: return delegate.Modifiers(flags, annotations);
0677: }
0678:
0679: /**
0680: * Creates a new ModifiersTree with a new flags and annotation.
0681: *
0682: * @param flags modifier flags
0683: * @see com.sun.source.tree.ModifiersTree
0684: */
0685: public ModifiersTree Modifiers(long flags,
0686: List<? extends AnnotationTree> annotations) {
0687: return delegate.Modifiers(flags, annotations);
0688: }
0689:
0690: /**
0691: * Creates a new ModifiersTree without any annotations specified.
0692: *
0693: * @param flags the set of modifier flags
0694: * @see com.sun.source.tree.ModifiersTree
0695: * @see javax.lang.model.element.Modifier
0696: */
0697: public ModifiersTree Modifiers(Set<Modifier> flags) {
0698: return delegate.Modifiers(flags);
0699: }
0700:
0701: /**
0702: * Creates a new ModifiersTree with a new set of annotations. The existing
0703: * flags are copied from the old tree; this preserves private javac flags.
0704: *
0705: * @param oldMods the old ModifiersTree, from which the flags are copied.
0706: * @param annotations a list of annotations, or an empty list.
0707: * @see com.sun.source.tree.ModifiersTree
0708: * @see javax.lang.model.element.Modifier
0709: */
0710: public ModifiersTree Modifiers(ModifiersTree oldMods,
0711: List<? extends AnnotationTree> annotations) {
0712: return delegate.Modifiers(oldMods, annotations);
0713: }
0714:
0715: /**
0716: * Creates a new NewArrayTree.
0717: *
0718: * @param elemtype the element type.
0719: * @param dimensions the list of array dimensions.
0720: * @param initializers the list of initializer statements, or an empty list.
0721: * @see com.sun.source.tree.NewArrayTree
0722: */
0723: public NewArrayTree NewArray(Tree elemtype,
0724: List<? extends ExpressionTree> dimensions,
0725: List<? extends ExpressionTree> initializers) {
0726: return delegate.NewArray(elemtype, dimensions, initializers);
0727: }
0728:
0729: /**
0730: * Creates a new NewClassTree.
0731: *
0732: * @param enclosingExpression the enclosing expression, or null.
0733: * @param typeArguments the list of generic type arguments, or an empty list.
0734: * @param identifier the class name expression
0735: * @param arguments the list of constructor arguments, or an empty list.
0736: * @param classBody the class definition, or null if there is no definition.
0737: * @see com.sun.source.tree.NewClassTree
0738: */
0739: public NewClassTree NewClass(ExpressionTree enclosingExpression,
0740: List<? extends ExpressionTree> typeArguments,
0741: ExpressionTree identifier,
0742: List<? extends ExpressionTree> arguments,
0743: ClassTree classBody) {
0744: return delegate.NewClass(enclosingExpression, typeArguments,
0745: identifier, arguments, classBody);
0746: }
0747:
0748: /**
0749: * Creates a new ParameterizedTypeTree.
0750: *
0751: * @param type the generic type
0752: * @param typeArguments the list of generic type arguments, or an empty list.
0753: * @see com.sun.source.tree.ParameterizedTypeTree
0754: */
0755: public ParameterizedTypeTree ParameterizedType(Tree type,
0756: List<? extends Tree> typeArguments) {
0757: return delegate.ParameterizedType(type, typeArguments);
0758: }
0759:
0760: /**
0761: * Creates a new ParenthesizedTree.
0762: *
0763: * @param expression the expression within the parentheses.
0764: * @see com.sun.source.tree.ParenthesizedTree
0765: */
0766: public ParenthesizedTree Parenthesized(ExpressionTree expression) {
0767: return delegate.Parenthesized(expression);
0768: }
0769:
0770: /**
0771: * Creates a new PrimitiveTypeTree.
0772: *
0773: * @param typekind the primitive type.
0774: * @see com.sun.source.tree.PrimitiveTypeTree
0775: * @see javax.lang.model.type.TypeKind
0776: */
0777: public PrimitiveTypeTree PrimitiveType(TypeKind typekind) {
0778: return delegate.PrimitiveType(typekind);
0779: }
0780:
0781: /**
0782: * Creates a qualified identifier from an element.
0783: *
0784: * @param element the element to use.
0785: */
0786: public ExpressionTree QualIdent(Element element) {
0787: return delegate.QualIdent(element);
0788: }
0789:
0790: /**
0791: * Creates a new ReturnTree.
0792: *
0793: * @param expression the expression to be returned.
0794: * @see com.sun.source.tree.ReturnTree
0795: */
0796: public ReturnTree Return(ExpressionTree expression) {
0797: return delegate.Return(expression);
0798: }
0799:
0800: /**
0801: * Creates a new SwitchTree.
0802: *
0803: * @param expression the expression which provides the value to be switched.
0804: * @param cases the list of cases, or an empty list.
0805: * @see com.sun.source.tree.SwitchTree
0806: */
0807: public SwitchTree Switch(ExpressionTree expression,
0808: List<? extends CaseTree> cases) {
0809: return delegate.Switch(expression, cases);
0810: }
0811:
0812: /**
0813: * Creates a new SynchronizedTree.
0814: *
0815: * @param expression the expression defining the object being synchronized.
0816: * @param block the block of statements executed by this statement.
0817: * @see com.sun.source.tree.SynchronizedTree
0818: */
0819: public SynchronizedTree Synchronized(ExpressionTree expression,
0820: BlockTree block) {
0821: return delegate.Synchronized(expression, block);
0822: }
0823:
0824: /**
0825: * Creates a new ThrowTree.
0826: *
0827: * @param expression the exception to be thrown.
0828: * @see com.sun.source.tree.ThrowTree
0829: */
0830: public ThrowTree Throw(ExpressionTree expression) {
0831: return delegate.Throw(expression);
0832: }
0833:
0834: /**
0835: * Creates a new TryTree.
0836: *
0837: * @param tryBlock the statement block in the try clause.
0838: * @param catches the list of catch clauses, or an empty list.
0839: * @param finallyBlock the finally clause, or null.
0840: * @see com.sun.source.tree.TryTree
0841: */
0842: public TryTree Try(BlockTree tryBlock,
0843: List<? extends CatchTree> catches, BlockTree finallyBlock) {
0844: return delegate.Try(tryBlock, catches, finallyBlock);
0845: }
0846:
0847: /**
0848: * Creates a new Tree for a given TypeMirror.
0849: *
0850: * @param type TypeMirror for which a Tree should be created
0851: * @see com.sun.source.tree.ExpressionTree
0852: */
0853: public Tree Type(TypeMirror type) {
0854: return delegate.Type(type);
0855: }
0856:
0857: /**
0858: * Creates a new TypeCastTree.
0859: *
0860: * @param type the class or interface to cast.
0861: * @param expression the expression being cast.
0862: * @see com.sun.source.tree.TypeCastTree
0863: */
0864: public TypeCastTree TypeCast(Tree type, ExpressionTree expression) {
0865: return delegate.TypeCast(type, expression);
0866: }
0867:
0868: /**
0869: * Creates a new TypeParameterTree.
0870: *
0871: * @param name the name of this type parameter.
0872: * @param bounds the bounds of this parameter.
0873: * @see com.sun.source.tree.TypeParameterTree
0874: */
0875: public TypeParameterTree TypeParameter(CharSequence name,
0876: List<? extends ExpressionTree> bounds) {
0877: return delegate.TypeParameter(name, bounds);
0878: }
0879:
0880: /**
0881: * Creates a new UnaryTree.
0882: *
0883: * @param operator the operator for this tree, such as Tree.Kind.PLUS.
0884: * @param arg the operand of the tree.
0885: * @see com.sun.source.tree.UnaryTree
0886: * @see com.sun.source.tree.Tree.Kind
0887: */
0888: public UnaryTree Unary(Kind operator, ExpressionTree arg) {
0889: return delegate.Unary(operator, arg);
0890: }
0891:
0892: /**
0893: * Creates a new VariableTree.
0894: *
0895: * @param modifiers the modifiers of this variable.
0896: * @param name the name of the variable.
0897: * @param type the type of this variable.
0898: * @param initializer the initialization expression for this variable, or null.
0899: * @see com.sun.source.tree.VariableTree
0900: */
0901: public VariableTree Variable(ModifiersTree modifiers,
0902: CharSequence name, Tree type, ExpressionTree initializer) {
0903: return delegate.Variable(modifiers, name, type, initializer);
0904: }
0905:
0906: /**
0907: * Creates a new VariableTree from a VariableElement.
0908: *
0909: * @param variable the VariableElement to reference.
0910: * @param initializer the initialization expression, or null.
0911: * @see com.sun.source.tree.VariableTree
0912: * @see javax.lang.model.element.VariableElement
0913: */
0914: public VariableTree Variable(VariableElement variable,
0915: ExpressionTree initializer) {
0916: return delegate.Variable(variable, initializer);
0917: }
0918:
0919: /**
0920: * Creates a new WhileLoopTree.
0921: *
0922: * @param condition the boolean expression to test.
0923: * @param statement the statement to execute while the condition is true.
0924: * @see com.sun.source.tree.WhileLoopTree
0925: */
0926: public WhileLoopTree WhileLoop(ExpressionTree condition,
0927: StatementTree statement) {
0928: return delegate.WhileLoop(condition, statement);
0929: }
0930:
0931: /**
0932: * Creates a new WildcardTree.
0933: *
0934: * @param kind the kind of wildcard to create.
0935: * @param type the type (class, interface or enum) of this wildcard.
0936: * @see com.sun.source.tree.WildcardTree
0937: */
0938: public WildcardTree Wildcard(Kind kind, Tree type) {
0939: return delegate.Wildcard(kind, type);
0940: }
0941:
0942: ////////////////////////////////////////////////////////////////////////////
0943: // AnnotationTree
0944: /**
0945: * Appends specified element <tt>attrValue</tt> to the end of attribute
0946: * values list.
0947: *
0948: * @param annotation annotation tree containing attribute values list.
0949: * @param attrValue element to be appended to attribute values list.
0950: * @return annotation tree with modified attribute values.
0951: */
0952: public AnnotationTree addAnnotationAttrValue(
0953: AnnotationTree annotation, ExpressionTree attrValue) {
0954: return delegate.addAnnotationAttrValue(annotation, attrValue);
0955: }
0956:
0957: /**
0958: * Inserts the specified element <tt>attrValue</tt> at the specified
0959: * position in attribute values list.
0960: *
0961: * @param annotation annotation tree with attribute values list.
0962: * @param index index at which the specified element is to be inserted.
0963: * @param attrValue element to be inserted to attribute values list.
0964: * @return annotation tree with modified attribute values.
0965: *
0966: * @throws IndexOutOfBoundsException if the index is out of range
0967: * (index < 0 || index > size()).
0968: */
0969: public AnnotationTree insertAnnotationAttrValue(
0970: AnnotationTree annotation, int index,
0971: ExpressionTree attrValue) {
0972: return delegate.insertAnnotationAttrValue(annotation, index,
0973: attrValue);
0974: }
0975:
0976: /**
0977: * Removes the first occurrence in attribute values list of the specified
0978: * element. If this list does not contain the element, it is
0979: * unchanged.
0980: *
0981: * @param annotation annotation tree with attribute values list.
0982: * @param attrValue element to be removed from this list, if present.
0983: * @return annotation tree with modified attribute values.
0984: */
0985: public AnnotationTree removeAnnotationAttrValue(
0986: AnnotationTree annotation, ExpressionTree attrValue) {
0987: return delegate
0988: .removeAnnotationAttrValue(annotation, attrValue);
0989: }
0990:
0991: /**
0992: * Removes the element at the specified position in attribute values list.
0993: * Returns the modified annotation tree.
0994: *
0995: * @param annotation annotation tree with attribute values list.
0996: * @param index the index of the element to be removed.
0997: * @return annotation tree with modified attribute values.
0998: *
0999: * @throws IndexOutOfBoundsException if the index is out of range
1000: * (index < 0 || index >= size()).
1001: */
1002: public AnnotationTree removeAnnotationAttrValue(
1003: AnnotationTree annotation, int index) {
1004: return delegate.removeAnnotationAttrValue(annotation, index);
1005: }
1006:
1007: // BlockTree
1008: /**
1009: * Appends specified element <tt>statement</tt> to the end of statements
1010: * list.
1011: *
1012: * @param block block tree containing statements list.
1013: * @param statement element to be appended to statements list.
1014: * @return block tree with modified statements
1015: */
1016: public BlockTree addBlockStatement(BlockTree block,
1017: StatementTree statement) {
1018: return delegate.addBlockStatement(block, statement);
1019: }
1020:
1021: /**
1022: * Inserts the specified element <tt>statement</tt> at the specified
1023: * position in statements list.
1024: *
1025: * @param block block tree with statements list
1026: * @param index index at which the specified element is to be inserted.
1027: * @param statement element to be inserted to statements list.
1028: * @return block tree with modified statements
1029: *
1030: * @throws IndexOutOfBoundsException if the index is out of range
1031: * (index < 0 || index > size()).
1032: */
1033: public BlockTree insertBlockStatement(BlockTree block, int index,
1034: StatementTree statement) {
1035: return delegate.insertBlockStatement(block, index, statement);
1036: }
1037:
1038: /**
1039: * Removes the first occurrence in statements list of the specified
1040: * element. If this list does not contain the element, it is
1041: * unchanged.
1042: *
1043: * @param block block tree with statements list
1044: * @param statement element to be removed from this list, if present.
1045: * @return block tree with modified statements
1046: */
1047: public BlockTree removeBlockStatement(BlockTree block,
1048: StatementTree statement) {
1049: return delegate.removeBlockStatement(block, statement);
1050: }
1051:
1052: /**
1053: * Removes the element at the specified position in statements list.
1054: * Returns the modified block tree.
1055: *
1056: * @param block block tree with statements list
1057: * @param index the index of the element to be removed.
1058: * @return block tree with modified statements
1059: *
1060: * @throws IndexOutOfBoundsException if the index is out of range
1061: * (index < 0 || index >= size()).
1062: */
1063: public BlockTree removeBlockStatement(BlockTree block, int index) {
1064: return delegate.removeBlockStatement(block, index);
1065: }
1066:
1067: // CaseTree
1068: /**
1069: * Appends specified element <tt>statement</tt> to the end of statements
1070: * list.
1071: *
1072: * @param kejs case tree containing statements list.
1073: * @param statement element to be appended to statements list.
1074: * @return case tree with modified statements.
1075: */
1076: public CaseTree addCaseStatement(CaseTree kejs,
1077: StatementTree statement) {
1078: return delegate.addCaseStatement(kejs, statement);
1079: }
1080:
1081: /**
1082: * Inserts the specified element <tt>statement</tt> at the specified
1083: * position in statements list.
1084: *
1085: * @param kejs case tree containing statements list.
1086: * @param index index at which the specified element is to be inserted.
1087: * @param statement element to be inserted to statements list.
1088: * @return case tree with modified statements.
1089: *
1090: * @throws IndexOutOfBoundsException if the index is out of range
1091: * (index < 0 || index > size()).
1092: */
1093: public CaseTree insertCaseStatement(CaseTree kejs, int index,
1094: StatementTree statement) {
1095: return delegate.insertCaseStatement(kejs, index, statement);
1096: }
1097:
1098: /**
1099: * Removes the first occurrence in statements list of the specified
1100: * element. If this list does not contain the element, it is
1101: * unchanged.
1102: *
1103: * @param kejs case tree containing statements list.
1104: * @param statement element to be removed from this list, if present.
1105: * @return case tree with modified statements.
1106: */
1107: public CaseTree removeCaseStatement(CaseTree kejs,
1108: StatementTree statement) {
1109: return delegate.removeCaseStatement(kejs, statement);
1110: }
1111:
1112: /**
1113: * Removes the element at the specified position in statements list.
1114: * Returns the modified case tree.
1115: *
1116: * @param kejs case tree containing statements list.
1117: * @param index the index of the element to be removed.
1118: * @return case tree with modified statements.
1119: *
1120: * @throws IndexOutOfBoundsException if the index is out of range
1121: * (index < 0 || index >= size()).
1122: */
1123: public CaseTree removeCaseStatement(CaseTree kejs, int index) {
1124: return delegate.removeCaseStatement(kejs, index);
1125: }
1126:
1127: // ClassTree
1128: /**
1129: * Appends specified element <tt>member</tt> to the end of members
1130: * list. Consider you want to add such a method to the end of class:
1131: * <pre>
1132: * public void newlyCreatedMethod(int a, float b) throws java.io.IOException {
1133: * }
1134: * </pre>
1135: *
1136: * You can get it e.g. with this code:
1137: * <pre>
1138: * TreeMaker make = workingCopy.getTreeMaker();
1139: * ClassTree node = ...;
1140: * // create method modifiers
1141: * ModifiersTree parMods = make.Modifiers(Collections.EMPTY_SET, Collections.EMPTY_LIST);
1142: * // create parameters
1143: * VariableTree par1 = make.Variable(parMods, "a", make.PrimitiveType(TypeKind.INT), null);
1144: * VariableTree par2 = make.Variable(parMods, "b", make.PrimitiveType(TypeKind.FLOAT), null);
1145: * List<VariableTree> parList = new ArrayList<VariableTree>(2);
1146: * parList.add(par1);
1147: * parList.add(par2);
1148: * // create method
1149: * MethodTree newMethod = make.Method(
1150: * make.Modifiers(
1151: * Collections.singleton(Modifier.PUBLIC), // modifiers
1152: * Collections.EMPTY_LIST // annotations
1153: * ), // modifiers and annotations
1154: * "newlyCreatedMethod", // name
1155: * make.PrimitiveType(TypeKind.VOID), // return type
1156: * Collections.EMPTY_LIST, // type parameters for parameters
1157: * parList, // parameters
1158: * Collections.singletonList(make.Identifier("java.io.IOException")), // throws
1159: * make.Block(Collections.EMPTY_LIST, false), // empty statement block
1160: * null // default value - not applicable here, used by annotations
1161: * );
1162: * // rewrite the original class node with the new one containing newMethod
1163: * workingCopy.rewrite(node, <b>make.addClassMember(node, newMethod)</b>);
1164: * </pre>
1165: *
1166: * @param clazz class tree containing members list.
1167: * @param member element to be appended to members list.
1168: * @return class tree with modified members.
1169: */
1170: public ClassTree addClassMember(ClassTree clazz, Tree member) {
1171: return delegate.addClassMember(clazz, member);
1172: }
1173:
1174: /**
1175: * Inserts the specified element <tt>member</tt> at the specified
1176: * position in members list.
1177: *
1178: * @param clazz class tree with members list
1179: * @param index index at which the specified element is to be inserted.
1180: * @param member element to be inserted to members list.
1181: * @return class tree with modified members.
1182: *
1183: * @throws IndexOutOfBoundsException if the index is out of range
1184: * (index < 0 || index > size()).
1185: */
1186: public ClassTree insertClassMember(ClassTree clazz, int index,
1187: Tree member) {
1188: return delegate.insertClassMember(clazz, index, member);
1189: }
1190:
1191: /**
1192: * Removes the first occurrence in members list of the specified
1193: * element. If this list does not contain the element, it is
1194: * unchanged.
1195: *
1196: * @param clazz class tree with members list
1197: * @param member element to be removed from this list, if present.
1198: * @return class tree with modified members.
1199: */
1200: public ClassTree removeClassMember(ClassTree clazz, Tree member) {
1201: return delegate.removeClassMember(clazz, member);
1202: }
1203:
1204: /**
1205: * Removes the element at the specified position in members list.
1206: * Returns the modified class tree.
1207: *
1208: * @param clazz class tree with members list.
1209: * @param index the index of the element to be removed.
1210: * @return class tree with modified members.
1211: *
1212: * @throws IndexOutOfBoundsException if the index is out of range
1213: * (index < 0 || index >= size()).
1214: */
1215: public ClassTree removeClassMember(ClassTree clazz, int index) {
1216: return delegate.removeClassMember(clazz, index);
1217: }
1218:
1219: /**
1220: * Appends specified element <tt>typeParameter</tt> to the end of type parameters
1221: * list.
1222: *
1223: * @param clazz class tree containing type parameters list.
1224: * @param typeParameter element to be appended to type parameters list.
1225: * @return class tree with modified type parameters.
1226: */
1227: public ClassTree addClassTypeParameter(ClassTree clazz,
1228: TypeParameterTree typeParameter) {
1229: return delegate.addClassTypeParameter(clazz, typeParameter);
1230: }
1231:
1232: /**
1233: * Inserts the specified element <tt>member</tt> at the specified
1234: * position in type parameters list.
1235: *
1236: * @param clazz class tree with type parameters list
1237: * @param index index at which the specified element is to be inserted.
1238: * @param typeParameter element to be inserted to type parameters list.
1239: * @return class tree with modified type parameters.
1240: *
1241: * @throws IndexOutOfBoundsException if the index is out of range
1242: * (index < 0 || index > size()).
1243: */
1244: public ClassTree insertClassTypeParameter(ClassTree clazz,
1245: int index, TypeParameterTree typeParameter) {
1246: return delegate.insertClassTypeParameter(clazz, index,
1247: typeParameter);
1248: }
1249:
1250: /**
1251: * Removes the first occurrence in type parameters list of the specified
1252: * element. If this list does not contain the element, it is
1253: * unchanged.
1254: *
1255: * @param clazz class tree with type parameters list
1256: * @param typeParameter element to be removed from this list, if present.
1257: * @return class tree with modified type parameters.
1258: */
1259: public ClassTree removeClassTypeParameter(ClassTree clazz,
1260: TypeParameterTree typeParameter) {
1261: return delegate.removeClassTypeParameter(clazz, typeParameter);
1262: }
1263:
1264: /**
1265: * Removes the element at the specified position in type parameters list.
1266: * Returns the modified class tree.
1267: *
1268: * @param clazz class tree with type parameters list.
1269: * @param index the index of the element to be removed.
1270: * @return class tree with modified type parameters.
1271: *
1272: * @throws IndexOutOfBoundsException if the index is out of range
1273: * (index < 0 || index >= size()).
1274: */
1275: public ClassTree removeClassTypeParameter(ClassTree clazz, int index) {
1276: return delegate.removeClassTypeParameter(clazz, index);
1277: }
1278:
1279: /**
1280: * Appends specified element <tt>implementsClause</tt> to the end of implements
1281: * list.
1282: *
1283: * @param clazz class tree containing implements list.
1284: * @param implementsClause element to be appended to implements list.
1285: * @return class tree with modified implements.
1286: */
1287: public ClassTree addClassImplementsClause(ClassTree clazz,
1288: Tree implements Clause) {
1289: return delegate.addClassImplementsClause(clazz,
1290: implements Clause);
1291: }
1292:
1293: /**
1294: * Inserts the specified element <tt>implementsClause</tt> at the specified
1295: * position in implements list.
1296: *
1297: * @param clazz class tree with implements list
1298: * @param index index at which the specified element is to be inserted.
1299: * @param implementsClause element to be inserted to implements list.
1300: * @return class tree with modified implements.
1301: *
1302: * @throws IndexOutOfBoundsException if the index is out of range
1303: * (index < 0 || index > size()).
1304: */
1305: public ClassTree insertClassImplementsClause(ClassTree clazz,
1306: int index, Tree implements Clause) {
1307: return delegate.insertClassImplementsClause(clazz, index,
1308: implements Clause);
1309: }
1310:
1311: /**
1312: * Removes the first occurrence in implements list of the specified
1313: * element. If this list does not contain the element, it is
1314: * unchanged.
1315: *
1316: * @param clazz class tree with implements list
1317: * @param implementsClause element to be removed from this list, if present.
1318: * @return class tree with modified implements.
1319: */
1320: public ClassTree removeClassImplementsClause(ClassTree clazz,
1321: Tree implements Clause) {
1322: return delegate.removeClassImplementsClause(clazz,
1323: implements Clause);
1324: }
1325:
1326: /**
1327: * Removes the element at the specified position in implements list.
1328: * Returns the modified class tree.
1329: *
1330: * @param clazz class tree with implements list.
1331: * @param index the index of the element to be removed.
1332: * @return class tree with modified implements.
1333: *
1334: * @throws IndexOutOfBoundsException if the index is out of range
1335: * (index < 0 || index >= size()).
1336: */
1337: public ClassTree removeClassImplementsClause(ClassTree clazz,
1338: int index) {
1339: return delegate.removeClassImplementsClause(clazz, index);
1340: }
1341:
1342: // CompilationUnitTree
1343: /**
1344: * Appends specified element <tt>typeDeclaration</tt> to the end of type
1345: * declarations list.
1346: *
1347: * @param compilationUnit compilation unit tree containing type declarations list.
1348: * @param typeDeclaration element to be appended to type declarations list.
1349: * @return compilation unit tree with modified type declarations.
1350: */
1351: public CompilationUnitTree addCompUnitTypeDecl(
1352: CompilationUnitTree compilationUnit, Tree typeDeclaration) {
1353: return delegate.addCompUnitTypeDecl(compilationUnit,
1354: typeDeclaration);
1355: }
1356:
1357: /**
1358: * Inserts the specified element <tt>typeDeclaration</tt> at the specified
1359: * position in type declarations list.
1360: *
1361: * @param compilationUnit compilation unit tree containing type declarations list.
1362: * @param index index at which the specified element is to be inserted.
1363: * @param typeDeclaration element to be inserted to type declarations list.
1364: * @return compilation unit tree with modified type declarations.
1365: *
1366: * @throws IndexOutOfBoundsException if the index is out of range
1367: * (index < 0 || index > size()).
1368: */
1369: public CompilationUnitTree insertCompUnitTypeDecl(
1370: CompilationUnitTree compilationUnit, int index,
1371: Tree typeDeclaration) {
1372: return delegate.insertCompUnitTypeDecl(compilationUnit, index,
1373: typeDeclaration);
1374: }
1375:
1376: /**
1377: * Removes the first occurrence in type declarations list of the specified
1378: * element. If this list does not contain the element, it is
1379: * unchanged.
1380: *
1381: * @param compilationUnit compilation unit tree containing type declarations list.
1382: * @param typeDeclaration element to be removed from this list, if present.
1383: * @return compilation unit tree with modified type declarations.
1384: */
1385: public CompilationUnitTree removeCompUnitTypeDecl(
1386: CompilationUnitTree compilationUnit, Tree typeDeclaration) {
1387: return delegate.removeCompUnitTypeDecl(compilationUnit,
1388: typeDeclaration);
1389: }
1390:
1391: /**
1392: * Removes the element at the specified position in type declarations list.
1393: * Returns the modified compilation unit tree.
1394: *
1395: * @param compilationUnit compilation unit tree containing type declarations list.
1396: * @param index the index of the element to be removed.
1397: * @return compilation unit tree with modified type declarations.
1398: *
1399: * @throws IndexOutOfBoundsException if the index is out of range (index
1400: * < 0 || index >= size()).
1401: */
1402: public CompilationUnitTree removeCompUnitTypeDecl(
1403: CompilationUnitTree compilationUnit, int index) {
1404: return delegate.removeCompUnitTypeDecl(compilationUnit, index);
1405: }
1406:
1407: /**
1408: * Appends specified element <tt>importt</tt> to the end of imports list.
1409: *
1410: * @param compilationUnit compilation unit tree containing imports list.
1411: * @param importt element to be appended to list of imports.
1412: * @return compilation unit tree with modified imports.
1413: */
1414: public CompilationUnitTree addCompUnitImport(
1415: CompilationUnitTree compilationUnit, ImportTree importt) {
1416: return delegate.addCompUnitImport(compilationUnit, importt);
1417: }
1418:
1419: /**
1420: * Inserts the specified element <tt>importt</tt> at the specified
1421: * position in imports list.
1422: *
1423: * @param compilationUnit compilation unit tree containing imports list.
1424: * @param index index at which the specified element is to be inserted.
1425: * @param importt element to be inserted to list of imports.
1426: * @return compilation unit tree with modified imports.
1427: *
1428: * @throws IndexOutOfBoundsException if the index is out of range
1429: * (index < 0 || index > size()).
1430: */
1431: public CompilationUnitTree insertCompUnitImport(
1432: CompilationUnitTree compilationUnit, int index,
1433: ImportTree importt) {
1434: return delegate.insertCompUnitImport(compilationUnit, index,
1435: importt);
1436: }
1437:
1438: /**
1439: * Removes the first occurrence in imports list of the specified
1440: * element. If this list does not contain the element, it is
1441: * unchanged.
1442: *
1443: * @param compilationUnit compilation unit tree containing import list.
1444: * @param importt element to be removed from this list, if present.
1445: * @return compilation unit tree with modified imports.
1446: */
1447: public CompilationUnitTree removeCompUnitImport(
1448: CompilationUnitTree compilationUnit, ImportTree importt) {
1449: return delegate.removeCompUnitImport(compilationUnit, importt);
1450: }
1451:
1452: /**
1453: * Removes the element at the specified position in import list.
1454: * Returns the modified compilation unit tree.
1455: *
1456: * @param compilationUnit compilation unit tree containing import list.
1457: * @param index the index of the element to be removed.
1458: * @return compilation unit tree with modified imports.
1459: *
1460: * @throws IndexOutOfBoundsException if the index is out of range (index
1461: * < 0 || index >= size()).
1462: */
1463: public CompilationUnitTree removeCompUnitImport(
1464: CompilationUnitTree compilationUnit, int index) {
1465: return delegate.removeCompUnitImport(compilationUnit, index);
1466: }
1467:
1468: /** ErroneousTree */
1469:
1470: // ForLoopInitializer
1471: /**
1472: * Appends specified element <tt>initializer</tt> to the end of initializers
1473: * list.
1474: *
1475: * @param forLoop for loop tree containing initializers list.
1476: * @param initializer element to be appended to initializers list.
1477: * @return for loop tree with modified initializers.
1478: */
1479: public ForLoopTree addForLoopInitializer(ForLoopTree forLoop,
1480: StatementTree initializer) {
1481: return delegate.addForLoopInitializer(forLoop, initializer);
1482: }
1483:
1484: /**
1485: * Inserts the specified element <tt>initializer</tt> at the specified
1486: * position in initializers list.
1487: *
1488: * @param forLoop for loop tree containing initializers list.
1489: * @param index index at which the specified element is to be inserted.
1490: * @param initializer element to be inserted to initializers list.
1491: * @return for loop tree with modified initializers.
1492: *
1493: * @throws IndexOutOfBoundsException if the index is out of range
1494: * (index < 0 || index > size()).
1495: */
1496: public ForLoopTree insertForLoopInitializer(ForLoopTree forLoop,
1497: int index, StatementTree initializer) {
1498: return delegate.insertForLoopInitializer(forLoop, index,
1499: initializer);
1500: }
1501:
1502: /**
1503: * Removes the first occurrence in initializers list of the specified
1504: * element. If this list does not contain the element, it is
1505: * unchanged.
1506: *
1507: * @param forLoop for loop tree containing initializers list.
1508: * @param initializer element to be removed from this list, if present.
1509: * @return for loop tree with modified initializers.
1510: */
1511: public ForLoopTree removeForLoopInitializer(ForLoopTree forLoop,
1512: StatementTree initializer) {
1513: return delegate.removeForLoopInitializer(forLoop, initializer);
1514: }
1515:
1516: /**
1517: * Removes the element at the specified position in initializers list.
1518: * Returns the modified for loop tree.
1519: *
1520: * @param forLoop for loop tree containing initializers list.
1521: * @param index the index of the element to be removed.
1522: * @return for loop tree with modified initializers.
1523: *
1524: * @throws IndexOutOfBoundsException if the index is out of range (index
1525: * < 0 || index >= size()).
1526: */
1527: public ForLoopTree removeForLoopInitializer(ForLoopTree forLoop,
1528: int index) {
1529: return delegate.removeForLoopInitializer(forLoop, index);
1530: }
1531:
1532: // ForLoopUpdate
1533: /**
1534: * Appends specified element <tt>update</tt> to the end of updates
1535: * list.
1536: *
1537: * @param forLoop for loop tree containing updates list.
1538: * @param update element to be appended to updates list.
1539: * @return for loop tree with modified updates.
1540: */
1541: public ForLoopTree addForLoopUpdate(ForLoopTree forLoop,
1542: ExpressionStatementTree update) {
1543: return delegate.addForLoopUpdate(forLoop, update);
1544: }
1545:
1546: /**
1547: * Inserts the specified element <tt>update</tt> at the specified
1548: * position in updates list.
1549: *
1550: * @param forLoop for loop tree containing updates list.
1551: * @param index index at which the specified element is to be inserted.
1552: * @param update element to be inserted to updates list.
1553: * @return for loop tree with modified updates.
1554: *
1555: * @throws IndexOutOfBoundsException if the index is out of range
1556: * (index < 0 || index > size()).
1557: */
1558: public ForLoopTree insertForLoopUpdate(ForLoopTree forLoop,
1559: int index, ExpressionStatementTree update) {
1560: return delegate.insertForLoopUpdate(forLoop, index, update);
1561: }
1562:
1563: /**
1564: * Removes the first occurrence in updates list of the specified
1565: * element. If this list does not contain the element, it is
1566: * unchanged.
1567: *
1568: * @param forLoop for loop tree containing updates list.
1569: * @param update element to be removed from this list, if present.
1570: * @return for loop tree with modified updates.
1571: */
1572: public ForLoopTree removeForLoopUpdate(ForLoopTree forLoop,
1573: ExpressionStatementTree update) {
1574: return delegate.removeForLoopUpdate(forLoop, update);
1575: }
1576:
1577: /**
1578: * Removes the element at the specified position in updates list.
1579: * Returns the modified for loop tree.
1580: *
1581: * @param forLoop for loop tree containing updates list.
1582: * @param index the index of the element to be removed.
1583: * @return for loop tree with modified updates.
1584: *
1585: * @throws IndexOutOfBoundsException if the index is out of range (index
1586: * < 0 || index >= size()).
1587: */
1588: public ForLoopTree removeForLoopUpdate(ForLoopTree forLoop,
1589: int index) {
1590: return delegate.removeForLoopUpdate(forLoop, index);
1591: }
1592:
1593: // MethodInvocation
1594: /**
1595: * Appends specified element <tt>argument</tt>.
1596: *
1597: * @param methodInvocation method invocation tree containing arguments list.
1598: * @param argument element to be appended to arguments list.
1599: * @return method invocation tree with modified arguments and type arguments.
1600: */
1601: public MethodInvocationTree addMethodInvocationArgument(
1602: MethodInvocationTree methodInvocation,
1603: ExpressionTree argument) {
1604: return delegate.addMethodInvocationArgument(methodInvocation,
1605: argument);
1606: }
1607:
1608: /**
1609: * Inserts the specified element <tt>argument</tt>.
1610: *
1611: * @param methodInvocation method invocation tree containing arguments list.
1612: * @param index index at which the specified elements is to be inserted.
1613: * @param argument element to be inserted to arguments list.
1614: * @return method invocation tree with modified type arguments and type arguments.
1615: *
1616: * @throws IndexOutOfBoundsException if the index is out of range
1617: * (index < 0 || index > size()).
1618: */
1619: public MethodInvocationTree insertMethodInvocationArgument(
1620: MethodInvocationTree methodInvocation, int index,
1621: ExpressionTree argument) {
1622: return delegate.insertMethodInvocationArgument(
1623: methodInvocation, index, argument);
1624: }
1625:
1626: /**
1627: * Removes the first occurrence in arguments list of the specified
1628: * element. If this list does not contain the element, it is does not
1629: * change anything.
1630: *
1631: * @param methodInvocation method invocation tree containing arguments list.
1632: * @param argument element to be removed from this list, if present.
1633: * @return method invocation tree with modified arguments and type arguments.
1634: */
1635: public MethodInvocationTree removeMethodInvocationArgument(
1636: MethodInvocationTree methodInvocation,
1637: ExpressionTree argument) {
1638: return delegate.removeMethodInvocationArgument(
1639: methodInvocation, argument);
1640: }
1641:
1642: /**
1643: * Removes the element at the specified position in arguments
1644: * list. Returns the modified method invocation tree.
1645: *
1646: * @param methodInvocation method invocation tree containing arguments list.
1647: * @param index the index of the element to be removed.
1648: * @return method invocation tree with modified arguments and type arguments.
1649: *
1650: * @throws IndexOutOfBoundsException if the index is out of range (index
1651: * < 0 || index >= size()).
1652: */
1653: public MethodInvocationTree removeMethodInvocationArgument(
1654: MethodInvocationTree methodInvocation, int index) {
1655: return delegate.removeMethodInvocationArgument(
1656: methodInvocation, index);
1657: }
1658:
1659: /**
1660: * Appends specified element <tt>type argument</tt>
1661: * to the end of type arguments list.
1662: *
1663: * @param methodInvocation method invocation tree containing arguments list.
1664: * @param typeArgument element to be appended to type arguments list.
1665: * @return method invocation tree with modified arguments and type arguments.
1666: */
1667: public MethodInvocationTree addMethodInvocationTypeArgument(
1668: MethodInvocationTree methodInvocation,
1669: ExpressionTree typeArgument) {
1670: return delegate.addMethodInvocationTypeArgument(
1671: methodInvocation, typeArgument);
1672: }
1673:
1674: /**
1675: * Inserts the specified element <tt>typeArgument</tt>
1676: * at the specified position in type arguments list.
1677: *
1678: * @param methodInvocation method invocation tree containing arguments list.
1679: * @param index index at which the specified elements is to be inserted.
1680: * @param typeArgument element to be inserted to type arguments list.
1681: * @return method invocation tree with modified type arguments and type arguments.
1682: *
1683: * @throws IndexOutOfBoundsException if the index is out of range
1684: * (index < 0 || index > size()).
1685: */
1686: public MethodInvocationTree insertMethodInvocationTypeArgument(
1687: MethodInvocationTree methodInvocation, int index,
1688: ExpressionTree typeArgument) {
1689: return delegate.insertMethodInvocationTypeArgument(
1690: methodInvocation, index, typeArgument);
1691: }
1692:
1693: /**
1694: * Removes the first occurrence in type arguments list of the specified
1695: * elements. If this list does not contain the element, it is method
1696: * does not change anything.
1697: *
1698: * @param methodInvocation method invocation tree containing arguments list.
1699: * @param typeArgument element to be removed from this list, if present.
1700: * @return method invocation tree with modified arguments and type arguments.
1701: */
1702: public MethodInvocationTree removeMethodInvocationTypeArgument(
1703: MethodInvocationTree methodInvocation,
1704: ExpressionTree typeArgument) {
1705: return delegate.removeMethodInvocationTypeArgument(
1706: methodInvocation, typeArgument);
1707: }
1708:
1709: /**
1710: * Removes the element at the specified position in type arguments.
1711: * Returns the modified method invocation tree.
1712: *
1713: * @param methodInvocation method invocation tree containing arguments list.
1714: * @param index the index of the element to be removed.
1715: * @return method invocation tree with modified arguments and type arguments.
1716: *
1717: * @throws IndexOutOfBoundsException if the index is out of range (index
1718: * < 0 || index >= size()).
1719: */
1720: public MethodInvocationTree removeMethodInvocationTypeArgument(
1721: MethodInvocationTree methodInvocation, int index) {
1722: return delegate.removeMethodInvocationTypeArgument(
1723: methodInvocation, index);
1724: }
1725:
1726: // Method
1727: /**
1728: * Appends specified element <tt>parameter</tt>
1729: * to the end of parameters list.
1730: *
1731: * @param method method tree containing parameters list.
1732: * @param parameter element to be appended to parameters list.
1733: * @return method tree with modified parameters.
1734: */
1735: public MethodTree addMethodParameter(MethodTree method,
1736: VariableTree parameter) {
1737: return delegate.addMethodParameter(method, parameter);
1738: }
1739:
1740: /**
1741: * Inserts the specified element <tt>parameter</tt>
1742: * at the specified position in parameters list.
1743: *
1744: * @param method method tree containing parameters list.
1745: * @param index index at which the specified elements is to be inserted.
1746: * @param parameter element to be inserted to parameters list.
1747: * @return method tree with modified parameters.
1748: *
1749: * @throws IndexOutOfBoundsException if the index is out of range
1750: * (index < 0 || index > size()).
1751: */
1752: public MethodTree insertMethodParameter(MethodTree method,
1753: int index, VariableTree parameter) {
1754: return delegate.insertMethodParameter(method, index, parameter);
1755: }
1756:
1757: /**
1758: * Removes the first occurrence in parameters list of the specified
1759: * elements. If this list do not contain the element, it is
1760: * unchanged.
1761: *
1762: * @param method method tree containing parameters list.
1763: * @param parameter element to be removed from this list, if present.
1764: * @return method tree with modified parameters and type parameters.
1765: */
1766: public MethodTree removeMethodParameter(MethodTree method,
1767: VariableTree parameter) {
1768: return delegate.removeMethodParameter(method, parameter);
1769: }
1770:
1771: /**
1772: * Removes the element at the specified position in parameters list.
1773: * Returns the modified method tree.
1774: *
1775: * @param method method tree containing parameters list.
1776: * @param index the index of the element to be removed.
1777: * @return method tree with modified parameters.
1778: *
1779: * @throws IndexOutOfBoundsException if the index is out of range (index
1780: * < 0 || index >= size()).
1781: */
1782: public MethodTree removeMethodParameter(MethodTree method, int index) {
1783: return delegate.removeMethodParameter(method, index);
1784: }
1785:
1786: /**
1787: * Appends specified element <tt>typeParameter</tt>
1788: * to the end of type parameters list.
1789: *
1790: * @param method method tree containing type parameters list.
1791: * @param typeParameter element to be appended to type parameters list.
1792: * @return method tree with modified type parameters.
1793: */
1794: public MethodTree addMethodTypeParameter(MethodTree method,
1795: TypeParameterTree typeParameter) {
1796: return delegate.addMethodTypeParameter(method, typeParameter);
1797: }
1798:
1799: /**
1800: * Inserts the specified element <tt>typeParameter</tt>
1801: * at the specified position in type parameters list.
1802: *
1803: * @param method method tree containing parameters list.
1804: * @param index index at which the specified elements is to be inserted.
1805: * @param typeParameter element to be inserted to type parameters list.
1806: * @return method tree with modified type parameters.
1807: *
1808: * @throws IndexOutOfBoundsException if the index is out of range
1809: * (index < 0 || index > size()).
1810: */
1811: public MethodTree insertMethodTypeParameter(MethodTree method,
1812: int index, TypeParameterTree typeParameter) {
1813: return delegate.insertMethodTypeParameter(method, index,
1814: typeParameter);
1815: }
1816:
1817: /**
1818: * Removes the first occurrence in type parameters list of the specified
1819: * elements. If this list do not contain the element, it is
1820: * unchanged.
1821: *
1822: * @param method method tree containing type parameters list.
1823: * @param typeParameter element to be removed from this list, if present.
1824: * @return method tree with modified type parameters.
1825: */
1826: public MethodTree removeMethodTypeParameter(MethodTree method,
1827: TypeParameterTree typeParameter) {
1828: return delegate
1829: .removeMethodTypeParameter(method, typeParameter);
1830: }
1831:
1832: /**
1833: * Removes the element at the specified position in type parameters list.
1834: * Returns the modified method tree.
1835: *
1836: * @param method method tree containing type parameters list.
1837: * @param index the index of the element to be removed.
1838: * @return method tree with modified type parameters.
1839: *
1840: * @throws IndexOutOfBoundsException if the index is out of range (index
1841: * < 0 || index >= size()).
1842: */
1843: public MethodTree removeMethodTypeParameter(MethodTree method,
1844: int index) {
1845: return delegate.removeMethodTypeParameter(method, index);
1846: }
1847:
1848: /**
1849: * Appends specified element <tt>throwz</tt> to the end of throws
1850: * list.
1851: *
1852: * @param method method tree containing throws list.
1853: * @param throwz element to be appended to throws list.
1854: * @return method tree with modified throws.
1855: */
1856: public MethodTree addMethodThrows(MethodTree method,
1857: ExpressionTree throwz) {
1858: return delegate.addMethodThrows(method, throwz);
1859: }
1860:
1861: /**
1862: * Inserts the specified element <tt>throws</tt> at the specified
1863: * position in throws list.
1864: *
1865: * @param method method tree containing throws list.
1866: * @param index index at which the specified element is to be inserted.
1867: * @param throwz element to be inserted to throws list.
1868: * @return method tree with modified throws.
1869: *
1870: * @throws IndexOutOfBoundsException if the index is out of range
1871: * (index < 0 || index > size()).
1872: */
1873: public MethodTree insertMethodThrows(MethodTree method, int index,
1874: ExpressionTree throwz) {
1875: return delegate.insertMethodThrows(method, index, throwz);
1876: }
1877:
1878: /**
1879: * Removes the first occurrence in throws list of the specified
1880: * element. If this list does not contain the element, it is
1881: * unchanged.
1882: *
1883: * @param method method tree containing throws list.
1884: * @param throwz element to be removed from this list, if present.
1885: * @return method tree with modified throws.
1886: */
1887: public MethodTree removeMethodThrows(MethodTree method,
1888: ExpressionTree throwz) {
1889: return delegate.removeMethodThrows(method, throwz);
1890: }
1891:
1892: /**
1893: * Removes the element at the specified position in throws list.
1894: * Returns the modified method tree.
1895: *
1896: * @param method method tree containing throws list.
1897: * @param index the index of the element to be removed.
1898: * @return method tree with modified throws.
1899: *
1900: * @throws IndexOutOfBoundsException if the index is out of range (index
1901: * < 0 || index >= size()).
1902: */
1903: public MethodTree removeMethodThrows(MethodTree method, int index) {
1904: return delegate.removeMethodThrows(method, index);
1905: }
1906:
1907: // Modifiers
1908: /**
1909: * Appends specified element <tt>annotation</tt> to the end of annotations
1910: * list.
1911: *
1912: * @param modifiers modifiers tree containing annotations list.
1913: * @param annotation element to be appended to annotations list.
1914: * @return modifiers tree with modified annotations.
1915: */
1916: public ModifiersTree addModifiersAnnotation(
1917: ModifiersTree modifiers, AnnotationTree annotation) {
1918: return delegate.addModifiersAnnotation(modifiers, annotation);
1919: }
1920:
1921: /**
1922: * Inserts the specified element <tt>annotation</tt> at the specified
1923: * position in annotations list.
1924: *
1925: * @param modifiers modifiers tree containing annotations list.
1926: * @param index index at which the specified element is to be inserted.
1927: * @param annotation element to be inserted to annotations list.
1928: * @return modifiers tree with modified annotations.
1929: *
1930: * @throws IndexOutOfBoundsException if the index is out of range
1931: * (index < 0 || index > size()).
1932: */
1933: public ModifiersTree insertModifiersAnnotation(
1934: ModifiersTree modifiers, int index,
1935: AnnotationTree annotation) {
1936: return delegate.insertModifiersAnnotation(modifiers, index,
1937: annotation);
1938: }
1939:
1940: /**
1941: * Removes the first occurrence in annotations list of the specified
1942: * element. If this list does not contain the element, it is
1943: * unchanged.
1944: *
1945: * @param modifiers modifiers tree containing annotations list.
1946: * @param annotation element to be removed from this list, if present.
1947: * @return modifiers tree with modified annotations.
1948: */
1949: public ModifiersTree removeModifiersAnnotation(
1950: ModifiersTree modifiers, AnnotationTree annotation) {
1951: return delegate
1952: .removeModifiersAnnotation(modifiers, annotation);
1953: }
1954:
1955: /**
1956: * Removes the element at the specified position in annotations list.
1957: * Returns the modified modifiers tree.
1958: *
1959: * @param modifiers modifiers tree containing annotations list.
1960: * @param index the index of the element to be removed.
1961: * @return modifiers tree with modified annotations.
1962: *
1963: * @throws IndexOutOfBoundsException if the index is out of range (index
1964: * < 0 || index >= size()).
1965: */
1966: public ModifiersTree removeModifiersAnnotation(
1967: ModifiersTree modifiers, int index) {
1968: return delegate.removeModifiersAnnotation(modifiers, index);
1969: }
1970:
1971: public ModifiersTree addModifiersModifier(ModifiersTree modifiers,
1972: Modifier modifier) {
1973: long c = ((JCModifiers) modifiers).flags;
1974: switch (modifier) {
1975: case ABSTRACT:
1976: c = c | Flags.ABSTRACT;
1977: break;
1978: case FINAL:
1979: c = c | Flags.FINAL;
1980: break;
1981: case NATIVE:
1982: c = c | Flags.NATIVE;
1983: break;
1984: case PRIVATE:
1985: c = c | Flags.PRIVATE;
1986: break;
1987: case PROTECTED:
1988: c = c | Flags.PROTECTED;
1989: break;
1990: case PUBLIC:
1991: c = c | Flags.PUBLIC;
1992: break;
1993: case STATIC:
1994: c = c | Flags.STATIC;
1995: break;
1996: case STRICTFP:
1997: c = c | Flags.STRICTFP;
1998: break;
1999: case SYNCHRONIZED:
2000: c = c | Flags.SYNCHRONIZED;
2001: break;
2002: case TRANSIENT:
2003: c = c | Flags.TRANSIENT;
2004: break;
2005: case VOLATILE:
2006: c = c | Flags.VOLATILE;
2007: break;
2008: default:
2009: break;
2010: }
2011: return Modifiers(c, modifiers.getAnnotations());
2012: }
2013:
2014: public ModifiersTree removeModifiersModifier(
2015: ModifiersTree modifiers, Modifier modifier) {
2016: long c = ((JCModifiers) modifiers).flags;
2017: switch (modifier) {
2018: case ABSTRACT:
2019: c = c & ~Flags.ABSTRACT;
2020: break;
2021: case FINAL:
2022: c = c & ~Flags.FINAL;
2023: break;
2024: case NATIVE:
2025: c = c & ~Flags.NATIVE;
2026: break;
2027: case PRIVATE:
2028: c = c & ~Flags.PRIVATE;
2029: break;
2030: case PROTECTED:
2031: c = c & ~Flags.PROTECTED;
2032: break;
2033: case PUBLIC:
2034: c = c & ~Flags.PUBLIC;
2035: break;
2036: case STATIC:
2037: c = c & ~Flags.STATIC;
2038: break;
2039: case STRICTFP:
2040: c = c & ~Flags.STRICTFP;
2041: break;
2042: case SYNCHRONIZED:
2043: c = c & ~Flags.SYNCHRONIZED;
2044: break;
2045: case TRANSIENT:
2046: c = c & ~Flags.TRANSIENT;
2047: break;
2048: case VOLATILE:
2049: c = c & ~Flags.VOLATILE;
2050: break;
2051: default:
2052: break;
2053: }
2054: return Modifiers(c, modifiers.getAnnotations());
2055: }
2056:
2057: // NewArray
2058: /**
2059: * Appends specified element <tt>dimension</tt> to the end of dimensions
2060: * list.
2061: *
2062: * @param newArray new array tree containing dimensions list.
2063: * @param dimension element to be appended to dimensions list.
2064: * @return new array tree with modified dimensions.
2065: */
2066: public NewArrayTree addNewArrayDimension(NewArrayTree newArray,
2067: ExpressionTree dimension) {
2068: return delegate.addNewArrayDimension(newArray, dimension);
2069: }
2070:
2071: /**
2072: * Inserts the specified element <tt>dimension</tt> at the specified
2073: * position in dimensions list.
2074: *
2075: * @param newArray new array tree containing dimensions list.
2076: * @param index index at which the specified element is to be inserted.
2077: * @param dimension element to be inserted to dimensions list.
2078: * @return new array tree with modified dimensions.
2079: *
2080: * @throws IndexOutOfBoundsException if the index is out of range
2081: * (index < 0 || index > size()).
2082: */
2083: public NewArrayTree insertNewArrayDimension(NewArrayTree newArray,
2084: int index, ExpressionTree dimension) {
2085: return delegate.insertNewArrayDimension(newArray, index,
2086: dimension);
2087: }
2088:
2089: /**
2090: * Removes the first occurrence in dimensions list of the specified
2091: * element. If this list does not contain the element, it is
2092: * unchanged.
2093: *
2094: * @param newArray new array tree containing dimensions list.
2095: * @param dimension element to be removed from this list, if present.
2096: * @return new array tree with modified dimensions.
2097: */
2098: public NewArrayTree removeNewArrayDimension(NewArrayTree newArray,
2099: ExpressionTree dimension) {
2100: return delegate.removeNewArrayDimension(newArray, dimension);
2101: }
2102:
2103: /**
2104: * Removes the element at the specified position in dimensions list.
2105: * Returns the modified new array tree.
2106: *
2107: * @param newArray new array tree containing dimensions list.
2108: * @param index the index of the element to be removed.
2109: * @return new array tree with modified dimensions.
2110: *
2111: * @throws IndexOutOfBoundsException if the index is out of range (index
2112: * < 0 || index >= size()).
2113: */
2114: public NewArrayTree removeNewArrayDimension(NewArrayTree newArray,
2115: int index) {
2116: return delegate.removeNewArrayDimension(newArray, index);
2117: }
2118:
2119: // NewArrayTree
2120: /**
2121: * Appends specified element <tt>initializer</tt> to the end of initializers
2122: * list.
2123: *
2124: * @param newArray new array tree containing initializers list.
2125: * @param initializer element to be appended to initializers list.
2126: * @return new array tree with modified initializers.
2127: */
2128: public NewArrayTree addNewArrayInitializer(NewArrayTree newArray,
2129: ExpressionTree initializer) {
2130: return delegate.addNewArrayInitializer(newArray, initializer);
2131: }
2132:
2133: /**
2134: * Inserts the specified element <tt>initializer</tt> at the specified
2135: * position in initializers list.
2136: *
2137: * @param newArray new array tree containing initializers list.
2138: * @param index index at which the specified element is to be inserted.
2139: * @param initializer element to be inserted to initializers list.
2140: * @return new array tree with modified initializers.
2141: *
2142: * @throws IndexOutOfBoundsException if the index is out of range
2143: * (index < 0 || index > size()).
2144: */
2145: public NewArrayTree insertNewArrayInitializer(
2146: NewArrayTree newArray, int index, ExpressionTree initializer) {
2147: return delegate.insertNewArrayInitializer(newArray, index,
2148: initializer);
2149: }
2150:
2151: /**
2152: * Removes the first occurrence in initializers list of the specified
2153: * element. If this list does not contain the element, it is
2154: * unchanged.
2155: *
2156: * @param newArray new array tree containing initializers list.
2157: * @param initializer element to be removed from this list, if present.
2158: * @return new array tree with modified initializers.
2159: */
2160: public NewArrayTree removeNewArrayInitializer(
2161: NewArrayTree newArray, ExpressionTree initializer) {
2162: return delegate
2163: .removeNewArrayInitializer(newArray, initializer);
2164: }
2165:
2166: /**
2167: * Removes the element at the specified position in initializers list.
2168: * Returns the modified new array tree.
2169: *
2170: * @param newArray new array tree containinginitializers list.
2171: * @param index the index of the element to be removed.
2172: * @return new array tree with modified initializers.
2173: *
2174: * @throws IndexOutOfBoundsException if the index is out of range (index
2175: * < 0 || index >= size()).
2176: */
2177: public NewArrayTree removeNewArrayInitializer(
2178: NewArrayTree newArray, int index) {
2179: return delegate.removeNewArrayInitializer(newArray, index);
2180: }
2181:
2182: // NewClass
2183: /**
2184: * Appends specified element <tt>argument</tt>
2185: * to the end of arguments list.
2186: *
2187: * @param newClass new class tree containing arguments list.
2188: * @param argument element to be appended to arguments list.
2189: * @return new class tree with modified arguments and type arguments.
2190: */
2191: public NewClassTree addNewClassArgument(NewClassTree newClass,
2192: ExpressionTree argument) {
2193: return delegate.addNewClassArgument(newClass, argument);
2194: }
2195:
2196: /**
2197: * Inserts the specified element <tt>argument</tt>
2198: * at the specified position in type arguments list.
2199: *
2200: * @param newClass new class tree containing type arguments list.
2201: * @param index index at which the specified elements is to be inserted.
2202: * @param argument element to be inserted to arguments list.
2203: * @return new class tree with modified type arguments and type arguments.
2204: *
2205: * @throws IndexOutOfBoundsException if the index is out of range
2206: * (index < 0 || index > size()).
2207: */
2208: public NewClassTree insertNewClassArgument(NewClassTree newClass,
2209: int index, ExpressionTree argument) {
2210: return delegate.insertNewClassArgument(newClass, index,
2211: argument);
2212: }
2213:
2214: /**
2215: * Removes the first occurrence in arguments of the specified elements.
2216: * If this list does not contain the element, it is unchanged.
2217: *
2218: * @param newClass new class tree containing type arguments list.
2219: * @param argument element to be removed from this list, if present.
2220: * @return new class tree with modified arguments and type arguments.
2221: */
2222: public NewClassTree removeNewClassArgument(NewClassTree newClass,
2223: ExpressionTree argument) {
2224: return delegate.removeNewClassArgument(newClass, argument);
2225: }
2226:
2227: /**
2228: * Removes the element at the specified position in arguments
2229: * list. Returns the modified new class tree.
2230: *
2231: * @param newClass new class tree containing type arguments list.
2232: * @param index the index of the element to be removed.
2233: * @return new class tree with modified arguments and type arguments.
2234: *
2235: * @throws IndexOutOfBoundsException if the index is out of range (index
2236: * < 0 || index >= size()).
2237: */
2238: public NewClassTree removeNewClassArgument(NewClassTree newClass,
2239: int index) {
2240: return delegate.removeNewClassArgument(newClass, index);
2241: }
2242:
2243: /**
2244: * Appends specified element <tt>typeArgument</tt>
2245: * to the end of type arguments list.
2246: *
2247: * @param newClass new class tree containing arguments list.
2248: * @param typeArgument element to be appended to type arguments list.
2249: * @return new class tree with modified arguments and type arguments.
2250: */
2251: public NewClassTree addNewClassTypeArgument(NewClassTree newClass,
2252: ExpressionTree typeArgument) {
2253: return delegate.addNewClassTypeArgument(newClass, typeArgument);
2254: }
2255:
2256: /**
2257: * Inserts the specified element <tt>typeArgument</tt>
2258: * at the specified position in type arguments list.
2259: *
2260: * @param newClass new class tree containing type arguments list.
2261: * @param index index at which the specified elements is to be inserted.
2262: * @param typeArgument element to be inserted to type arguments list.
2263: * @return new class tree with modified type arguments and type arguments.
2264: *
2265: * @throws IndexOutOfBoundsException if the index is out of range
2266: * (index < 0 || index > size()).
2267: */
2268: public NewClassTree insertNewClassTypeArgument(
2269: NewClassTree newClass, int index,
2270: ExpressionTree typeArgument) {
2271: return delegate.insertNewClassTypeArgument(newClass, index,
2272: typeArgument);
2273: }
2274:
2275: /**
2276: * Removes the first occurrence in type arguments list of the specified elements.
2277: * If this list does not contain the element, it is unchanged.
2278: *
2279: * @param newClass new class tree containing type arguments list.
2280: * @param typeArgument element to be removed from this list, if present.
2281: * @return new class tree with modified arguments and type arguments.
2282: */
2283: public NewClassTree removeNewClassTypeArgument(
2284: NewClassTree newClass, ExpressionTree typeArgument) {
2285: return delegate.removeNewClassTypeArgument(newClass,
2286: typeArgument);
2287: }
2288:
2289: /**
2290: * Removes the element at the specified position in type arguments
2291: * list. Returns the modified new class tree.
2292: *
2293: * @param newClass new class tree containing type arguments list.
2294: * @param index the index of the element to be removed.
2295: * @return new class tree with modified arguments and type arguments.
2296: *
2297: * @throws IndexOutOfBoundsException if the index is out of range (index
2298: * < 0 || index >= size()).
2299: */
2300: public NewClassTree removeNewClassTypeArgument(
2301: NewClassTree newClass, int index) {
2302: return delegate.removeNewClassTypeArgument(newClass, index);
2303: }
2304:
2305: // ParameterizedType
2306: /**
2307: * Appends specified element <tt>argument</tt> to the end of type arguments
2308: * list.
2309: *
2310: * @param parameterizedType parameterized type tree containing type arguments list.
2311: * @param argument element to be appended to type arguments list.
2312: * @return parameterized type tree with modified type arguments.
2313: */
2314: public ParameterizedTypeTree addParameterizedTypeTypeArgument(
2315: ParameterizedTypeTree parameterizedType,
2316: ExpressionTree argument) {
2317: return delegate.addParameterizedTypeTypeArgument(
2318: parameterizedType, argument);
2319: }
2320:
2321: /**
2322: * Inserts the specified element <tt>argument</tt> at the specified
2323: * position in type arguments list.
2324: *
2325: * @param parameterizedType parameterized type tree containing type arguments list.
2326: * @param index index at which the specified element is to be inserted.
2327: * @param argument element to be inserted to type arguments list.
2328: * @return parameterized type tree with modified type arguments.
2329: *
2330: * @throws IndexOutOfBoundsException if the index is out of range
2331: * (index < 0 || index > size()).
2332: */
2333: public ParameterizedTypeTree insertParameterizedTypeTypeArgument(
2334: ParameterizedTypeTree parameterizedType, int index,
2335: ExpressionTree argument) {
2336: return delegate.insertParameterizedTypeTypeArgument(
2337: parameterizedType, index, argument);
2338: }
2339:
2340: /**
2341: * Removes the first occurrence in type arguments list of the specified
2342: * element. If this list does not contain the element, it is
2343: * unchanged.
2344: *
2345: * @param parameterizedType parameterized type tree containing type arguments list.
2346: * @param argument element to be removed from this list, if present.
2347: * @return parameterized type tree with modified type arguments.
2348: */
2349: public ParameterizedTypeTree removeParameterizedTypeTypeArgument(
2350: ParameterizedTypeTree parameterizedType,
2351: ExpressionTree argument) {
2352: return delegate.removeParameterizedTypeTypeArgument(
2353: parameterizedType, argument);
2354: }
2355:
2356: /**
2357: * Removes the element at the specified position in type arguments list.
2358: * Returns the modified parameterized type tree.
2359: *
2360: * @param parameterizedType parameterized type tree containing type arguments list.
2361: * @param index the index of the element to be removed.
2362: * @return parameterized type tree with modified type arguments.
2363: *
2364: * @throws IndexOutOfBoundsException if the index is out of range (index
2365: * < 0 || index >= size()).
2366: */
2367: public ParameterizedTypeTree removeParameterizedTypeTypeArgument(
2368: ParameterizedTypeTree parameterizedType, int index) {
2369: return delegate.removeParameterizedTypeTypeArgument(
2370: parameterizedType, index);
2371: }
2372:
2373: // Switch
2374: /**
2375: * Appends specified element <tt>kejs</tt> to the end of cases
2376: * list.
2377: *
2378: * @param swic switch tree containing cases list.
2379: * @param kejs element to be appended to cases list.
2380: * @return switch tree with modified cases.
2381: */
2382: public SwitchTree addSwitchCase(SwitchTree swic, CaseTree kejs) {
2383: return delegate.addSwitchCase(swic, kejs);
2384: }
2385:
2386: /**
2387: * Inserts the specified element <tt>kejs</tt> at the specified
2388: * position in cases list.
2389: *
2390: * @param swic switch tree containing cases list.
2391: * @param index index at which the specified element is to be inserted.
2392: * @param kejs element to be inserted to cases list.
2393: * @return switch tree with modified cases.
2394: *
2395: * @throws IndexOutOfBoundsException if the index is out of range
2396: * (index < 0 || index > size()).
2397: */
2398: public SwitchTree insertSwitchCase(SwitchTree swic, int index,
2399: CaseTree kejs) {
2400: return delegate.insertSwitchCase(swic, index, kejs);
2401: }
2402:
2403: /**
2404: * Removes the first occurrence in cases list of the specified
2405: * element. If this list does not contain the element, it is
2406: * unchanged.
2407: *
2408: * @param swic switch tree containing cases list.
2409: * @param kejs element to be removed from this list, if present.
2410: * @return switch tree with modified cases.
2411: */
2412: public SwitchTree removeSwitchCase(SwitchTree swic, CaseTree kejs) {
2413: return delegate.removeSwitchCase(swic, kejs);
2414: }
2415:
2416: /**
2417: * Removes the element at the specified position in cases list.
2418: * Returns the modified switch tree.
2419: *
2420: * @param swic switch tree containing cases list.
2421: * @param index the index of the element to be removed.
2422: * @return switch tree with modified cases.
2423: *
2424: * @throws IndexOutOfBoundsException if the index is out of range (index
2425: * < 0 || index >= size()).
2426: */
2427: public SwitchTree removeSwitchCase(SwitchTree swic, int index) {
2428: return delegate.removeSwitchCase(swic, index);
2429: }
2430:
2431: // Try
2432: /**
2433: * Appends specified element <tt>kec</tt> to the end of catches
2434: * list.
2435: *
2436: * @param traj try tree containing catches list.
2437: * @param kec element to be appended to catches list.
2438: * @return try tree with modified catches.
2439: */
2440: public TryTree addTryCatch(TryTree traj, CatchTree kec) {
2441: return delegate.addTryCatch(traj, kec);
2442: }
2443:
2444: /**
2445: * Inserts the specified element <tt>kec</tt> at the specified
2446: * position in catches list.
2447: *
2448: * @param traj try tree containing catches list.
2449: * @param index index at which the specified element is to be inserted.
2450: * @param kec element to be inserted to catches list.
2451: * @return try tree with modified catches.
2452: *
2453: * @throws IndexOutOfBoundsException if the index is out of range
2454: * (index < 0 || index > size()).
2455: */
2456: public TryTree insertTryCatch(TryTree traj, int index, CatchTree kec) {
2457: return delegate.insertTryCatch(traj, index, kec);
2458: }
2459:
2460: /**
2461: * Removes the first occurrence in catches list of the specified
2462: * element. If this list does not contain the element, it is
2463: * unchanged.
2464: *
2465: * @param traj try tree containing catches list.
2466: * @param kec element to be removed from this list, if present.
2467: * @return try tree with modified catches.
2468: */
2469: public TryTree removeTryCatch(TryTree traj, CatchTree kec) {
2470: return delegate.removeTryCatch(traj, kec);
2471: }
2472:
2473: /**
2474: * Removes the element at the specified position in catches list.
2475: * Returns the modified try tree.
2476: *
2477: * @param traj try tree containing catches list.
2478: * @param index the index of the element to be removed.
2479: * @return try tree with modified catches.
2480: *
2481: * @throws IndexOutOfBoundsException if the index is out of range (index
2482: * < 0 || index >= size()).
2483: */
2484: public TryTree removeTryCatch(TryTree traj, int index) {
2485: return delegate.removeTryCatch(traj, index);
2486: }
2487:
2488: /**
2489: * Appends specified element <tt>bound</tt> to the end of bounds
2490: * list.
2491: *
2492: * @param typeParameter type parameter tree containing bounds list.
2493: * @param bound element to be appended to bounds list.
2494: * @return type parameter tree with modified bounds.
2495: */
2496: public TypeParameterTree addTypeParameterBound(
2497: TypeParameterTree typeParameter, ExpressionTree bound) {
2498: return delegate.addTypeParameterBound(typeParameter, bound);
2499: }
2500:
2501: /**
2502: * Inserts the specified element <tt>bound</tt> at the specified
2503: * position in bounds list.
2504: *
2505: * @param typeParameter type parameter tree containing bounds list.
2506: * @param index index at which the specified element is to be inserted.
2507: * @param bound element to be inserted to bounds list.
2508: * @return type parameter tree with modified bounds.
2509: *
2510: * @throws IndexOutOfBoundsException if the index is out of range
2511: * (index < 0 || index > size()).
2512: */
2513: public TypeParameterTree insertTypeParameterBound(
2514: TypeParameterTree typeParameter, int index,
2515: ExpressionTree bound) {
2516: return delegate.insertTypeParameterBound(typeParameter, index,
2517: bound);
2518: }
2519:
2520: /**
2521: * Removes the first occurrence in bounds list of the specified
2522: * element. If this list does not contain the element, it is
2523: * unchanged.
2524: *
2525: * @param typeParameter type parameter tree containing bounds list.
2526: * @param bound element to be removed from this list, if present.
2527: * @return type parameter tree with modified bounds.
2528: */
2529: public TypeParameterTree removeTypeParameterBound(
2530: TypeParameterTree typeParameter, ExpressionTree bound) {
2531: return delegate.removeTypeParameterBound(typeParameter, bound);
2532: }
2533:
2534: /**
2535: * Removes the element at the specified position in bounds list.
2536: * Returns the modified type parameter tree.
2537: *
2538: * @param typeParameter type parameter tree containing bounds list.
2539: * @param index the index of the element to be removed.
2540: * @return type parameter tree with modified bounds.
2541: *
2542: * @throws IndexOutOfBoundsException if the index is out of range (index
2543: * < 0 || index >= size()).
2544: */
2545: public TypeParameterTree removeTypeParameterBound(
2546: TypeParameterTree typeParameter, int index) {
2547: return delegate.removeTypeParameterBound(typeParameter, index);
2548: }
2549:
2550: /**
2551: * Replaces the original <tt>node</tt>'s label with new one provided in
2552: * <tt>aLabel</tt> argument. Throws <tt>IllegalArgumentException</tt> if
2553: * <tt>node</tt>'s kind is invalid. Valid <tt>node</tt>'s kinds are:<br>
2554: * BREAK, CLASS, CONTINUE, IDENTIFIER, LABELED_STATEMENT,
2555: * MEMBER_SELECT, METHOD, TYPE_PARAMETER, VARIABLE.<p>
2556: *
2557: * Consider you want to change name of method <tt>fooMet</tt> to
2558: * <tt>fooMethod</tt>:
2559: *
2560: * <pre>
2561: * public void fooMet() throws java.io.IOException {
2562: * ...
2563: * }
2564: * </pre>
2565: *
2566: * You can get it e.g. with this code:
2567: * <pre>
2568: * MethodTree footMet = <I>contains footMet tree</I>;
2569: * MethodTree fooMethod = make.setLabel(fooMet, "fooMethod");
2570: * workingCopy.rewrite(node, njuMethod);
2571: * </pre>
2572: *
2573: * This code will result to:
2574: * <pre>
2575: * public void fooMethod() throws java.io.IOException {
2576: * ...
2577: * }
2578: * </pre>
2579: *
2580: * @param node argument will be duplicated and its label replaced
2581: * with <tt>aLabel</tt>
2582: * @param aLabel represents new <tt>node</tt>'s name or other label
2583: * @throws java.lang.IllegalArgumentException if the user provides
2584: * illegal <tt>node</tt>'s kind, i.e. if the provided
2585: * <tt>node</tt> does not contain any name or <tt>String</tt>.
2586: * @return duplicated <tt>node</tt> with a new name
2587: */
2588: public <N extends Tree> N setLabel(final N node,
2589: final CharSequence aLabel) {
2590: return delegate.setLabel(node, aLabel);
2591: }
2592:
2593: /**
2594: * Replaces extends clause in class declaration. Consider you want to make
2595: * <code>Matricale</code> class extending class <code>Yerba</code>.
2596: *
2597: * You have the class available:
2598: *
2599: * <pre>
2600: * public class Matricale {
2601: * ...
2602: * }
2603: * </pre>
2604: *
2605: * Running following code:
2606: * <pre>
2607: * TreeMaker make = workingCopy.getTreeMaker();
2608: * ClassTree matricale = <i>contains Matricale class</i>;
2609: * ClassTree modified = make.setExtends(matricale, make.Identifier("Yerba"));
2610: * workingCopy.rewrite(matricale, modified);
2611: * </pre>
2612: *
2613: * will result to:
2614: *
2615: * <pre>
2616: * public class Matricale extends Yerba {
2617: * ....
2618: * }
2619: * </pre>
2620: *
2621: * Note: It does not apply for interface declaration. For interfaces
2622: * declaration, use implements clause in <code>ClassTree</code> for
2623: * changed extends clause. It is a workaround allowing to extends more
2624: * interfaces.
2625: *
2626: * @param node class where the extends clause will be replaced
2627: * @param extendz new extends identifier or member select.
2628: * @return node's copy with new extends clause
2629: */
2630: public ClassTree setExtends(final ClassTree node,
2631: final ExpressionTree extendz) {
2632: @SuppressWarnings("unchecked")
2633: ClassTree result = Class(node.getModifiers(), node
2634: .getSimpleName(), node.getTypeParameters(), extendz,
2635: (List<ExpressionTree>) node.getImplementsClause(), // bug
2636: node.getMembers());
2637: return result;
2638: }
2639:
2640: /**
2641: * Replaces initializer in appropriate element. Allowed types for node
2642: * are <code>MethodTree</code> and <code>VariableTree</code>. Initial
2643: * value is available for variables except the parameters. Fields and
2644: * local variables can be passed to the method. In addition to, annotation
2645: * attribute represented by <code>MethodTree</code> is also valid value.
2646: *
2647: * Consider you have declaration:
2648: *
2649: * <pre>
2650: * public static String cedron;
2651: * </pre>
2652: *
2653: * Running following code:
2654: * <pre>
2655: * TreeMaker make = workingCopy.getTreeMaker();
2656: * VariableTree cedron = <i>contains cedron field</i>;
2657: * Literal initialValue = make.Literal("This is a cedron.");
2658: * VariableTree modified = make.setInitialValue(cedron, literal);
2659: * workingCopy.rewrite(matricale, modified);
2660: * </pre>
2661: *
2662: * will result to:
2663: *
2664: * <pre>
2665: * public static String cedron = "This is a cedron.";
2666: * </pre>
2667: *
2668: * @param node replace the initial value in node
2669: * @param initializer new initial value
2670: * @throws java.lang.IllegalArgumentException if the user provides
2671: * illegal <code>node</code>'s kind, i.e. if the provided
2672: * <code>node</code> is neither <code>MethodTree</code> nor
2673: * <code>VariableTree</code>
2674: * @return node's copy with new initializer
2675: */
2676: public <N extends Tree> N setInitialValue(final N node,
2677: ExpressionTree initializer) {
2678: switch (node.getKind()) {
2679: case VARIABLE: {
2680: VariableTree t = (VariableTree) node;
2681: @SuppressWarnings("unchecked")
2682: N clone = (N) Variable(t.getModifiers(), t.getName(), t
2683: .getType(), initializer);
2684: return clone;
2685: }
2686: case METHOD: {
2687: MethodTree t = (MethodTree) node;
2688: @SuppressWarnings("unchecked")
2689: N clone = (N) Method(t.getModifiers(), t.getName(), t
2690: .getReturnType(), t.getTypeParameters(), t
2691: .getParameters(), t.getThrows(), t.getBody(),
2692: initializer);
2693: return clone;
2694: }
2695: default:
2696: throw new IllegalArgumentException("Invalid kind "
2697: + node.getKind());
2698: }
2699: }
2700:
2701: //comment handling:
2702: /**Append a comment to the list of comments attached to a given tree.
2703: *
2704: * @param tree to which comment should added
2705: * @param comment to add
2706: * @param preceding true if preceding comments should be added, false if trailing comments should be added.
2707: *
2708: * @throws IllegalStateException if the method is called outside the runModificationTask
2709: */
2710: public void addComment(Tree tree, Comment comment, boolean preceding)
2711: throws IllegalStateException {
2712: insertComment(tree, comment, -1, preceding);
2713: }
2714:
2715: /**Insert a comment to the list of comments attached to a given tree (to a specified position).
2716: *
2717: * @param tree to which comment should added
2718: * @param comment to add
2719: * @param index -1 to add comment to the end of the list or index at which the comment should be added
2720: * @param preceding true if preceding comments should be added, false if trailing comments should be added.
2721: *
2722: * @throws IllegalStateException if the method is called outside the runModificationTask
2723: */
2724: public void insertComment(Tree tree, Comment comment, int index,
2725: boolean preceding) throws IllegalStateException {
2726: if (handler == null) {
2727: throw new IllegalStateException(
2728: "Cannot modify comments outside runModificationTask.");
2729: }
2730:
2731: CommentSet set = handler.getComments(tree);
2732:
2733: if (set == null) {
2734: if (index != 0 && index != (-1))
2735: throw new IllegalArgumentException(
2736: "Index out of bounds: " + index);
2737:
2738: handler.addComment(tree, comment);
2739:
2740: if (!preceding) {
2741: set = handler.getComments(tree);
2742:
2743: assert set != null;
2744:
2745: set.addTrailingComment(comment);
2746: set.getPrecedingComments().remove(comment);
2747: }
2748: } else {
2749: if (index == (-1)) {
2750: if (preceding)
2751: set.addPrecedingComment(comment);
2752: else
2753: set.addTrailingComment(comment);
2754: } else {
2755: List<Comment> comments;
2756:
2757: if (preceding) {
2758: comments = set.getPrecedingComments();
2759: } else {
2760: comments = set.getTrailingComments();
2761: }
2762:
2763: if (comments.size() > index) {
2764: comments.add(index, comment);
2765: } else {
2766: throw new IllegalArgumentException(
2767: "Index out of bounds, index=" + index
2768: + ", length=" + comments.size());
2769: }
2770: }
2771: }
2772: }
2773:
2774: /**Remove a comment from the list of comments attached to a given tree.
2775: *
2776: * @param tree to which comment should added
2777: * @param index comment to remove
2778: *
2779: * @throws IllegalStateException if the method is called outside the runModificationTask
2780: */
2781: public void removeComment(Tree tree, int index, boolean preceding)
2782: throws IllegalStateException {
2783: if (handler == null) {
2784: throw new IllegalStateException(
2785: "Cannot modify comments outside runModificationTask.");
2786: }
2787:
2788: CommentSet set = handler.getComments(tree);
2789:
2790: if (set == null) {
2791: throw new IllegalArgumentException("Index out of bounds: "
2792: + index);
2793: }
2794:
2795: List<Comment> comments;
2796:
2797: if (preceding) {
2798: comments = set.getPrecedingComments();
2799: } else {
2800: comments = set.getTrailingComments();
2801: }
2802:
2803: if (comments.size() > index) {
2804: comments.remove(index);
2805: } else {
2806: throw new IllegalArgumentException(
2807: "Index out of bounds, index=" + index + ", length="
2808: + comments.size());
2809: }
2810: }
2811:
2812: /**
2813: * Creates a new BlockTree for provided <tt>bodyText</tt>.
2814: *
2815: * @param method figures out the scope for attribution.
2816: * @param bodyText text which will be used for method body creation.
2817: * @return a new tree for <tt>bodyText</tt>.
2818: */
2819: public BlockTree createMethodBody(MethodTree method, String bodyText) {
2820: SourcePositions[] positions = new SourcePositions[1];
2821: final TreeUtilities treeUtils = copy.getTreeUtilities();
2822: StatementTree body = treeUtils.parseStatement(bodyText,
2823: positions);
2824: assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!";
2825: Scope scope = copy.getTrees().getScope(
2826: TreePath.getPath(copy.getCompilationUnit(), method));
2827: treeUtils.attributeTree(body, scope);
2828: mapComments((BlockTree) body, bodyText, copy, handler);
2829: return (BlockTree) body;
2830: }
2831:
2832: /**
2833: * Creates a new MethodTree.
2834: *
2835: * @param modifiers the modifiers of this method.
2836: * @param name the name of the method.
2837: * @param returnType the return type for this method.
2838: * @param typeParameters the list of generic type parameters, or an empty list.
2839: * @param parameters the list of parameters, or an empty list.
2840: * @param throwsList the list of throws clauses, or an empty list.
2841: * @param bodyText the method's code block provided as a plain text
2842: * @param defaultValue the default value, used by annotation types.
2843: * @see com.sun.source.tree.MethodTree
2844: *
2845: */
2846: public MethodTree Method(ModifiersTree modifiers,
2847: CharSequence name, Tree returnType,
2848: List<? extends TypeParameterTree> typeParameters,
2849: List<? extends VariableTree> parameters,
2850: List<? extends ExpressionTree> throwsList, String bodyText,
2851: ExpressionTree defaultValue) {
2852: SourcePositions[] positions = new SourcePositions[1];
2853: StatementTree body = copy.getTreeUtilities().parseStatement(
2854: bodyText, positions);
2855: assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!";
2856: mapComments((BlockTree) body, bodyText, copy, handler);
2857: return delegate.Method(modifiers, name, returnType,
2858: typeParameters, parameters, throwsList,
2859: (BlockTree) body, defaultValue);
2860: }
2861:
2862: private void mapComments(BlockTree block, String inputText,
2863: WorkingCopy copy, CommentHandler comments) {
2864: TokenSequence<JavaTokenId> seq = TokenHierarchy.create(
2865: inputText, JavaTokenId.language()).tokenSequence(
2866: JavaTokenId.language());
2867: List<? extends StatementTree> trees = block.getStatements();
2868: SourcePositions pos = copy.getTrees().getSourcePositions();
2869: for (StatementTree statement : trees) {
2870: seq.move((int) pos.getStartPosition(null, statement));
2871: PositionEstimator
2872: .moveToSrcRelevant(seq, Direction.BACKWARD);
2873: int indent = NOPOS;
2874: while (seq.moveNext()
2875: && nonRelevant.contains(seq.token().id())) {
2876: switch (seq.token().id()) {
2877: case LINE_COMMENT:
2878: comments.addComment(statement, Comment.create(
2879: Style.LINE, NOPOS, NOPOS, indent, seq
2880: .token().toString()));
2881: indent = 0;
2882: break;
2883: case BLOCK_COMMENT:
2884: comments.addComment(statement, Comment.create(
2885: Style.BLOCK, NOPOS, NOPOS, indent, seq
2886: .token().toString()));
2887: indent = NOPOS;
2888: break;
2889: case JAVADOC_COMMENT:
2890: comments.addComment(statement, Comment.create(
2891: Style.JAVADOC, NOPOS, NOPOS, indent, seq
2892: .token().toString()));
2893: indent = NOPOS;
2894: break;
2895: case WHITESPACE:
2896: String tokenText = seq.token().toString();
2897: comments.addComment(statement, Comment.create(
2898: Style.WHITESPACE, NOPOS, NOPOS, NOPOS,
2899: tokenText));
2900: int newLinePos = tokenText.lastIndexOf('\n');
2901: if (newLinePos < 0) {
2902: if (indent >= 0)
2903: indent += tokenText.length();
2904: } else {
2905: indent = tokenText.length() - newLinePos - 1;
2906: }
2907: break;
2908: }
2909: }
2910: }
2911: }
2912: }
|