diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/ASTRewrite.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/ASTRewrite.java index d4e6affabbf..ec1ee98719e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/ASTRewrite.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/rewrite/ASTRewrite.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.rewrite; @@ -29,31 +29,30 @@ import org.eclipse.text.edits.TextEditGroup; /** * Infrastructure for modifying code by describing changes to AST nodes. The AST rewriter collects - * descriptions of modifications to nodes and translates these descriptions into text edits that can then be - * applied to the original source. This is all done without actually modifying the original AST. The rewrite - * infrastructure tries to generate minimal text changes, preserve existing comments and indentation, and - * follow code formatter settings. A {@link IASTComment} can be removed from or added to a node. + * descriptions of modifications to nodes and translates these descriptions into text edits that can + * then be applied to the original source. This is all done without actually modifying the original + * AST. The rewrite infrastructure tries to generate minimal text changes, preserve existing + * comments and indentation, and follow code formatter settings. A {@link IASTComment} can be + * removed from or added to a node. *
- * The initial implementation does not support nodes that implement {@link IASTPreprocessorStatement} or - * {@link IASTProblem}. + * The initial implementation does not support nodes that implement + * {@link IASTPreprocessorStatement} or {@link IASTProblem}. *
- * EXPERIMENTAL. This class or interface has been added as part of a work in progress. There - * is no guarantee that this API will work or that it will remain the same. Please do not use this API without - * consulting with the CDT team. + * EXPERIMENTAL. This class or interface has been added as part of a work in + * progress. There is no guarantee that this API will work or that it will remain the same. + * Please do not use this API without consulting with the CDT team. *
* * @since 5.0 * @noinstantiate This class is not intended to be instantiated by clients. */ public final class ASTRewrite { - /** * Defines the positions of the comment. * * @since 5.3 */ - public enum CommentPosition{ - + public enum CommentPosition { /** * Comments before a statement, declaration, or definition */ @@ -63,8 +62,8 @@ public final class ASTRewrite { */ trailing, /** - * Comments before a closing brace such as they occur in namespace-, class- and method-definitions or - * at the end of a file + * Comments before a closing brace such as they occur in namespace-, class- and + * method-definitions or at the end of a file */ freestanding } @@ -82,13 +81,14 @@ public final class ASTRewrite { private final ASTModification fParentMod; private final NodeCommentMap fCommentMap; - private enum Operation{ + private enum Operation { insertBefore, replace, remove } - private ASTRewrite(IASTNode root, ASTModificationStore modStore, ASTModification parentMod, NodeCommentMap commentMap) { + private ASTRewrite(IASTNode root, ASTModificationStore modStore, ASTModification parentMod, + NodeCommentMap commentMap) { fRoot= root; fModificationStore= modStore; fParentMod= parentMod; @@ -115,9 +115,9 @@ public final class ASTRewrite { * * @param node the node being removed * @param editGroup the edit group in which to collect the corresponding - * text edits, ornull
+ * text edits, or null
* @throws IllegalArgumentException if the node is null, the node is not
- * part of this rewriter's AST.
+ * part of this rewriter's AST.
*/
public final void remove(IASTNode node, TextEditGroup editGroup) {
checkBelongsToAST(node);
@@ -134,11 +134,11 @@ public final class ASTRewrite {
*
* @param node the node being replaced
* @param replacement the node replacing the given one
- * @param editGroup the edit group in which to collect the corresponding
- * text edits, or null
+ * @param editGroup the edit group in which to collect the corresponding text edits,
+ * or null
* @return a rewriter for further rewriting the replacement node.
- * @throws IllegalArgumentException if the node or the replacement is null, or if the node is not
- * part of this rewriter's AST
+ * @throws IllegalArgumentException if the node or the replacement is null, or if the node is
+ * not part of this rewriter's AST
*/
public final ASTRewrite replace(IASTNode node, IASTNode replacement, TextEditGroup editGroup) {
if (replacement == null) {
@@ -158,15 +158,17 @@ public final class ASTRewrite {
* The new node can be part of a translation-unit or it is a synthetic
* (newly created) node.
* @param parent the parent the new node is added to.
- * @param insertionPoint the node before which the insertion shall be done, or null
for inserting after the last child.
+ * @param insertionPoint the node before which the insertion shall be done, or null
+ * for inserting after the last child.
* @param newNode the node being inserted
* @param editGroup the edit group in which to collect the corresponding
- * text edits, or null
+ * text edits, or null
* @return a rewriter for further rewriting the inserted node.
- * @throws IllegalArgumentException if the parent or the newNode is null, or if the parent is not
- * part of this rewriter's AST, or the insertionPoint is not a child of the parent.
+ * @throws IllegalArgumentException if the parent or the newNode is null, or if the parent is
+ * not part of this rewriter's AST, or the insertionPoint is not a child of the parent.
*/
- public final ASTRewrite insertBefore(IASTNode parent, IASTNode insertionPoint, IASTNode newNode, TextEditGroup editGroup) {
+ public final ASTRewrite insertBefore(IASTNode parent, IASTNode insertionPoint, IASTNode newNode,
+ TextEditGroup editGroup) {
if (parent != fRoot) {
checkBelongsToAST(parent);
}
@@ -180,8 +182,7 @@ public final class ASTRewrite {
ASTModification mod;
if (insertionPoint == null) {
mod= new ASTModification(ModificationKind.APPEND_CHILD, parent, newNode, editGroup);
- }
- else {
+ } else {
if (insertionPoint.getParent() != parent) {
throw new IllegalArgumentException();
}
@@ -192,12 +193,13 @@ public final class ASTRewrite {
}
/**
- * Converts all modifications recorded by this rewriter into the change object required by the
- * refactoring framework.
+ * Converts all modifications recorded by this rewriter into the change object required by
+ * the refactoring framework.
* * Calling this methods does not discard the modifications on record. Subsequence modifications * are added to the ones already on record. If this method is called again later, - * the resulting text edit object will accurately reflect the net cumulative affect of all those changes. + * the resulting text edit object will accurately reflect the net cumulative affect of all those + * changes. *
* * @return Change object describing the changes to the @@ -223,7 +225,7 @@ public final class ASTRewrite { private void checkSupportedNode(IASTNode node, Operation op) { if (node instanceof IASTComment) { - if(op != Operation.remove) { + if (op != Operation.remove) { throw new IllegalArgumentException("Rewriting comments is not yet supported"); //$NON-NLS-1$ } } @@ -235,13 +237,12 @@ public final class ASTRewrite { } } - /** * Assigns the comment to the node. * - * @param node - * @param comment - * @param pos + * @param node the node. + * @param comment the comment to be attached to the node at the given position. + * @param pos the position of the comment. * @since 5.3 */ public void addComment(IASTNode node, IASTComment comment, CommentPosition pos) { @@ -258,13 +259,10 @@ public final class ASTRewrite { } } - - /** + /** * - * @param node - * the node - * @param pos - * the position + * @param node the node + * @param pos the position * @return All comments assigned to the node at this position * @since 5.3 */ @@ -276,7 +274,6 @@ public final class ASTRewrite { return fCommentMap.getTrailingCommentsForNode(node); case freestanding: return fCommentMap.getFreestandingCommentsForNode(node); - } return fCommentMap.getLeadingCommentsForNode(node); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java index 6085c977fad..ea35926d435 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite; @@ -20,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; /** - * Represents a list of modifications to an ast-node. If there are nested modifications + * Represents a list of modifications to an AST node. If there are nested modifications * to nodes introduced by insertions or replacements, these modifications are collected * in separate modification maps. I.e. a modification map represents one level of * modifications. @@ -28,51 +28,51 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin * @since 5.0 */ public class ASTModificationMap { - - private HashMap