diff options
author | Thomas Corbat | 2018-07-13 14:08:24 +0000 |
---|---|---|
committer | Thomas Corbat | 2018-07-16 11:16:49 +0000 |
commit | adbaa608cb32833c944931c3811fe6897aa12727 (patch) | |
tree | ad19b5f4b754e83991f39d7eeffa93d959c01bb2 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal | |
parent | 1a8f399b8b82c5dd11bdaa170d7b26dc06c32bfb (diff) | |
download | org.eclipse.cdt-adbaa608cb32833c944931c3811fe6897aa12727.tar.gz org.eclipse.cdt-adbaa608cb32833c944931c3811fe6897aa12727.tar.xz org.eclipse.cdt-adbaa608cb32833c944931c3811fe6897aa12727.zip |
Bug 537013 - Comment is replaced along with node
Provide functionality to remove a specific comment from ASTRewrite.
Change-Id: I5e0b3c521616d2dd900f59b0863e45fb01f34df8
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal')
-rw-r--r-- | core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java index 333fd408db1..7cb88108721 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -205,4 +206,60 @@ public class NodeCommentMap { public boolean isASTCovered(IASTTranslationUnit ast) { return coveredUnits.contains(ast); } + + /** + * Removes a given <code>comment</code> from a node, regardless of its position. + * + * @param node The key to remove the <code>comment</code> from. + * @param comment The comment is the value to be removed. + */ + public void removeCommentFromNode(IASTNode node, IASTComment comment) { + List<IASTComment> leadingComments = getLeadingCommentsForNode(node); + leadingComments.removeAll(Collections.singleton(comment)); + List<IASTComment> trailingComments = getTrailingCommentsForNode(node); + trailingComments.removeAll(Collections.singleton(comment)); + List<IASTComment> freestandingComments = getFreestandingCommentsForNode(node); + freestandingComments.removeAll(Collections.singleton(comment)); + } + + /** + * Removes all leading comments from a node. + * + * @param node The key to remove the leading comments from. + */ + public void removeLeadingCommentsFromNode(IASTNode node) { + List<IASTComment> leadingComments = getLeadingCommentsForNode(node); + leadingComments.clear(); + } + + /** + * Removes all trailing comments from a node. + * + * @param node The key to remove the trailing comments from. + */ + public void removeTrailingCommentsFromNode(IASTNode node) { + List<IASTComment> trailingComments = getTrailingCommentsForNode(node); + trailingComments.clear(); + } + + /** + * Removes all freestanding comments from a node. + * + * @param node The key to remove the freestanding comments from. + */ + public void removeFreestandingCommentsFromNode(IASTNode node) { + List<IASTComment> freestandingComments = getFreestandingCommentsForNode(node); + freestandingComments.clear(); + } + + /** + * Removes all comments from a node. + * + * @param node The key to remove all comments from. + */ + public void removeAllComments(IASTNode node) { + removeLeadingCommentsFromNode(node); + removeTrailingCommentsFromNode(node); + removeFreestandingCommentsFromNode(node); + } } |