diff options
4 files changed, 45 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java index 03d06574d37..b3f17609b50 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java @@ -11,18 +11,21 @@ ******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; -import java.util.Vector; +import java.util.ArrayList; +import java.util.TreeMap; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; /** - * This is the startpoint of the whole comment handling process. The creation of the + * This is the starting point of the entire comment handling process. The creation of the * NodeCommentMap is based on the IASTTranslationUnit. From this TranslationUnit the comments * are extracted and skipped if they belong not to the same workspace. An ASTCommenterVisitor * is initialized with this collection of comments. And the visit process can start. @@ -45,16 +48,25 @@ public class ASTCommenter { if(transUnit== null) { return new NodeCommentMap(); } - Vector<IASTComment> comments = getCommentsInWorkspace(transUnit); + ArrayList<IASTComment> comments = removeNotNeededComments(transUnit); if(comments == null || comments.size() == 0) { return new NodeCommentMap(); } return addCommentsToCommentMap(transUnit, comments); } - private static Vector<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) { + private static ArrayList<IASTComment> removeNotNeededComments(IASTTranslationUnit transUnit) { + ArrayList<IASTComment> comments = getCommentsInWorkspace(transUnit); + if (comments == null || comments.size() == 0) { + return null; + } + ArrayList<IASTComment> com = removeAllPreprocessorComments(transUnit, comments); + return com; + } + + private static ArrayList<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) { IASTComment[] comments = tu.getComments(); - Vector<IASTComment> commentsInWorksapce = new Vector<IASTComment>(); + ArrayList<IASTComment> commentsInWorksapce = new ArrayList<IASTComment>(); if (comments == null || comments.length == 0) { return null; @@ -68,6 +80,27 @@ public class ASTCommenter { return commentsInWorksapce; } + private static ArrayList<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, ArrayList<IASTComment> comments) { + IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements(); + TreeMap<Integer,Object> treeOfPreProcessorLines = new TreeMap<Integer,Object>(); + + for (IASTPreprocessorStatement statement : preprocessorStatements) { + if (isInWorkspace(statement)) { + treeOfPreProcessorLines.put(OffsetHelper.getStartingLineNumber(statement),null); + } + } + + ArrayList<IASTComment> commentsInCode = new ArrayList<IASTComment>(); + for (IASTComment comment : comments) { + int comStartLineNumber = OffsetHelper.getStartingLineNumber(comment); + if (treeOfPreProcessorLines.containsKey(comStartLineNumber)) { + continue; + } + commentsInCode.add(comment); + } + return commentsInCode; + } + private static boolean isInWorkspace(IASTNode node) { IPath workspacePath = Platform.getLocation(); IPath nodePath = new Path(node.getContainingFilename()); @@ -75,7 +108,7 @@ public class ASTCommenter { } - private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode, Vector<IASTComment> comments){ + private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode, ArrayList<IASTComment> comments){ NodeCommentMap commentMap = new NodeCommentMap(); CommentHandler commHandler = new CommentHandler(comments); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java index 2203d36a34a..9299f42963b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; -import java.util.Vector; +import java.util.ArrayList; import org.eclipse.cdt.core.dom.ast.IASTComment; @@ -24,9 +24,9 @@ import org.eclipse.cdt.core.dom.ast.IASTComment; */ public class CommentHandler { - private final Vector<IASTComment> comments; + private final ArrayList<IASTComment> comments; - public CommentHandler(Vector<IASTComment> comments) { + public CommentHandler(ArrayList<IASTComment> comments) { super(); this.comments = comments; } @@ -40,6 +40,6 @@ public class CommentHandler { } public IASTComment getFirst() { - return comments.firstElement(); + return comments.get(0); } } diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 17b686626ed..26d35f88f4e 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -159,7 +159,7 @@ Refactoring.menu.label= Refac&tor Refactoring.renameAction.label=Re&name... Refactoring.extractConstant.label=Extr&act Constant... Refactoring.extractFunction.label=Extract &Function... (work in progress) -Refactoring.hideMethod.label=Hide Member Function... (work in progress) +Refactoring.hideMethod.label=Hide Method... Refactoring.implementMethod.label=Impl&ement Method... (work in progress) Refactoring.gettersAndSetters.label=Generate Getters and Setters... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties index 52d03bcbb77..5257a3fcb90 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties @@ -13,5 +13,5 @@ CRenameAction_label=Rename... ExtractConstantAction_label=Extract Constant... GettersAndSetters_label=Generate Getters and Setters... ImplementMethodAction_label=Implement Method... (work in progress) -HideMethodAction_label=Hide Member Function... (work in progress) +HideMethodAction_label=Hide Method... ExtractFunctionAction_label=Extract Function... (work in progress) |