~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2013-10-03 20:30:16 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20131003203016-d4ug6l0xgosasumq
Tags: 8.2.1-1
* New upstream release.
* Updated autotools documentation sources.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import java.util.Map;
18
18
 
19
19
import org.eclipse.cdt.core.dom.ast.IASTComment;
 
20
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
20
21
import org.eclipse.cdt.core.dom.ast.IASTNode;
 
22
import org.eclipse.cdt.internal.core.dom.rewrite.util.ASTNodes;
21
23
 
22
24
/**
23
25
 * The NodeCommentMap is the map where all the comments are assigned to a node. For better 
147
149
                comment.addAll(getTrailingCommentsForNode(node));
148
150
                return comment;
149
151
        }
 
152
 
 
153
        public int getOffsetIncludingComments(IASTNode node) {
 
154
                int offset = ASTNodes.offset(node);
 
155
 
 
156
                // TODO(sprigogin): Iterate backwards and stop at the first blank line.
 
157
                List<IASTComment> comments = leadingMap.get(node);
 
158
                if (comments != null && !comments.isEmpty()) {
 
159
                        for (IASTComment comment : comments) {
 
160
                                int commentOffset = ASTNodes.offset(comment);
 
161
                                if (commentOffset < offset) {
 
162
                                        offset = commentOffset;
 
163
                                }
 
164
                        }
 
165
                }
 
166
                return offset;
 
167
        }
 
168
 
 
169
        public int getEndOffsetIncludingComments(IASTNode node) {
 
170
                int endOffset = 0;
 
171
                while (true) {
 
172
                        IASTFileLocation fileLocation = node.getFileLocation();
 
173
                        if (fileLocation != null)
 
174
                                endOffset = Math.max(endOffset, fileLocation.getNodeOffset() + fileLocation.getNodeLength());
 
175
                        List<IASTComment> comments = trailingMap.get(node);
 
176
                        if (comments != null && !comments.isEmpty()) {
 
177
                                for (IASTComment comment : comments) {
 
178
                                        int commentEndOffset = ASTNodes.endOffset(comment);
 
179
                                        if (commentEndOffset >= endOffset) {
 
180
                                                endOffset = commentEndOffset;
 
181
                                        }
 
182
                                }
 
183
                        }
 
184
                        IASTNode[] children = node.getChildren();
 
185
                        if (children.length == 0)
 
186
                                break;
 
187
                        node = children[children.length - 1];
 
188
                }
 
189
                return endOffset;
 
190
        }
150
191
}