diff options
author | Sergey Prigogin | 2013-02-22 18:58:19 +0000 |
---|---|---|
committer | Sergey Prigogin | 2013-02-27 01:36:45 +0000 |
commit | 361aa35205c8e56623d423656249452aef47aba7 (patch) | |
tree | e843bf02719133f6a4f245eb50cee6091e5ef8c8 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler | |
parent | d3b06fadd2f4f82561ca655ec94a4a87d5285fac (diff) | |
download | org.eclipse.cdt-361aa35205c8e56623d423656249452aef47aba7.tar.gz org.eclipse.cdt-361aa35205c8e56623d423656249452aef47aba7.tar.xz org.eclipse.cdt-361aa35205c8e56623d423656249452aef47aba7.zip |
Cosmetics.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler')
3 files changed, 37 insertions, 56 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 00a703461af..f78c870b83f 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 @@ -65,7 +65,7 @@ public class ASTCommenter { } private int checkOffsets(IASTNode node) { - int offset = ((ASTNode)node).getOffset(); + int offset = ((ASTNode) node).getOffset(); int status = PROCESS_CONTINUE; if (isCommentOnSameLine(node) @@ -169,33 +169,29 @@ public class ASTCommenter { } /** - * Creates a NodeCommentMap for the given TranslationUnit. This is the only way - * to get a NodeCommentMap which contains all the comments mapped against nodes. + * Creates a NodeCommentMap for the given AST. This is the only way to get a NodeCommentMap + * which contains all the comments mapped against nodes. * - * @param tu TranslationUnit + * @param ast the AST * @return NodeCommentMap */ - public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit tu){ + public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit ast) { NodeCommentMap commentMap = new NodeCommentMap(); - if (tu == null) { + if (ast == null) { return commentMap; } - IASTComment[] commentsArray = tu.getComments(); - if (commentsArray == null) { - return commentMap; - } - List<IASTComment> comments = filterNonTuComments(commentsArray); - return addCommentsToCommentMap(tu, comments); - } - - private static List<IASTComment> filterNonTuComments(IASTComment[] comments) { - List<IASTComment> filtered = new ArrayList<IASTComment>(comments.length); - for (IASTComment comment : comments) { + IASTComment[] commentsArray = ast.getComments(); + List<IASTComment> comments = new ArrayList<IASTComment>(commentsArray.length); + for (IASTComment comment : commentsArray) { if (comment.isPartOfTranslationUnitFile()) { - filtered.add(comment); + comments.add(comment); } } - return filtered; + assignPreprocessorComments(commentMap, comments, ast); + CommentHandler commentHandler = new CommentHandler(comments); + ASTCommenterVisitor commenter = new ASTCommenterVisitor(commentHandler, commentMap); + ast.accept(commenter); + return commentMap; } private static boolean isCommentDirectlyBeforePreprocessorStatement(IASTComment comment, @@ -204,11 +200,11 @@ public class ASTCommenter { return true; } IASTFileLocation commentLocation = comment.getFileLocation(); - int preprcessorOffset = statement.getFileLocation().getNodeOffset(); - if (preprcessorOffset > commentLocation.getNodeOffset()) { - PreprocessorRangeChecker vister = new PreprocessorRangeChecker(preprcessorOffset, commentLocation); - tu.accept(vister); - return vister.isPreStatementComment; + int preprocessorOffset = statement.getFileLocation().getNodeOffset(); + if (preprocessorOffset > commentLocation.getNodeOffset()) { + PreprocessorRangeChecker visitor = new PreprocessorRangeChecker(preprocessorOffset, commentLocation); + tu.accept(visitor); + return visitor.isPreStatementComment; } return false; } @@ -218,22 +214,7 @@ public class ASTCommenter { } /** - * Puts leading and training comments to the returned map and removes them from - * the {@code comments} list. - */ - private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit tu, - List<IASTComment> comments) { - NodeCommentMap commentMap = new NodeCommentMap(); - CommentHandler commHandler = new CommentHandler(comments); - - assignPreprocessorComments(commentMap, comments, tu); - ASTCommenterVisitor commenter = new ASTCommenterVisitor(commHandler, commentMap); - tu.accept(commenter); - return commentMap; - } - - /** - * Puts leading and training comments to {@code commentMap} and removes them from + * Puts leading and trailing comments to {@code commentMap} and removes them from * the {@code comments} list. */ private static void assignPreprocessorComments(NodeCommentMap commentMap, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java index a8a97e9dbb8..030b99f16d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java @@ -39,7 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier * @author Guido Zgraggen IFS */ public class ASTCommenterVisitor extends ASTVisitor { - protected CommentHandler commHandler; + protected CommentHandler commentHandler; protected NodeCommentMap commentMap; private NodeCommenter nodeCommenter; @@ -61,14 +61,14 @@ public class ASTCommenterVisitor extends ASTVisitor { shouldVisitTranslationUnit = true; } - public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) { - this.commHandler = commHandler; + public ASTCommenterVisitor(CommentHandler commentHandler, NodeCommentMap commentMap) { + this.commentHandler = commentHandler; this.commentMap = commentMap; init(); } private void init() { - nodeCommenter = new NodeCommenter(this, commHandler, commentMap); + nodeCommenter = new NodeCommenter(this, commentHandler, commentMap); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java index ec0d9f9afc8..589a67b2510 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java @@ -62,13 +62,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement; */ public class NodeCommenter { protected ASTVisitor visitor; - protected CommentHandler commHandler; + protected CommentHandler commentHandler; protected NodeCommentMap commentMap; protected List<IASTNode> children; public NodeCommenter(ASTVisitor visitor, CommentHandler commHandler, NodeCommentMap commentMap) { this.visitor = visitor; - this.commHandler = commHandler; + this.commentHandler = commHandler; this.commentMap = commentMap; this.children = new ArrayList<IASTNode>(); } @@ -122,17 +122,17 @@ public class NodeCommenter { private void addLeadingCommentToMap(ASTNode node, IASTComment comment) { commentMap.addLeadingCommentToNode(node, comment); - commHandler.allreadyAdded(comment); + commentHandler.allreadyAdded(comment); } private void addTrailingCommentToMap(ASTNode node, IASTComment comment) { commentMap.addTrailingCommentToNode(node, comment); - commHandler.allreadyAdded(comment); + commentHandler.allreadyAdded(comment); } private void addFreestandingCommentToMap(ASTNode node, IASTComment comment) { commentMap.addFreestandingCommentToNode(node, comment); - commHandler.allreadyAdded(comment); + commentHandler.allreadyAdded(comment); } private boolean isTrailing(ASTNode node, ASTNode com, int nodeLineNumber, int commentLineNumber) { @@ -200,8 +200,8 @@ public class NodeCommenter { } protected int appendComments(ASTNode node) { - while (commHandler.hasMore()) { - IASTComment comment = commHandler.getFirst(); + while (commentHandler.hasMore()) { + IASTComment comment = commentHandler.getFirst(); if (isNotSameFile(node, comment)) { return ASTVisitor.PROCESS_SKIP; @@ -215,8 +215,8 @@ public class NodeCommenter { } protected int appendFreestandingComments(ASTNode node) { - while (commHandler.hasMore()) { - IASTComment comment = commHandler.getFirst(); + while (commentHandler.hasMore()) { + IASTComment comment = commentHandler.getFirst(); if (isNotSameFile(node, comment)) { return ASTVisitor.PROCESS_SKIP; @@ -234,9 +234,9 @@ public class NodeCommenter { } public void appendRemainingComments(IASTDeclaration declaration) { - while (commHandler.hasMore()) { - IASTComment comment = commHandler.getFirst(); - if (appendComment((ASTNode)declaration, comment)) { + while (commentHandler.hasMore()) { + IASTComment comment = commentHandler.getFirst(); + if (appendComment((ASTNode) declaration, comment)) { continue; } addFreestandingCommentToMap((ASTNode) declaration, comment); |