Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuel Graf2009-02-17 05:37:22 -0500
committerEmanuel Graf2009-02-17 05:37:22 -0500
commit251c37e865dff4b6aacbf9c7a2ca591e1fcbe23d (patch)
tree237147524e9c6ddbfcf9c9003040dbce7668afa8 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler
parentb749b3efe5b302f04b8bda6daf4ee899f62d9e02 (diff)
downloadorg.eclipse.cdt-251c37e865dff4b6aacbf9c7a2ca591e1fcbe23d.tar.gz
org.eclipse.cdt-251c37e865dff4b6aacbf9c7a2ca591e1fcbe23d.tar.xz
org.eclipse.cdt-251c37e865dff4b6aacbf9c7a2ca591e1fcbe23d.zip
FIXED - bug 264712: Refactor extract function deletes comments in header
https://bugs.eclipse.org/bugs/show_bug.cgi?id=264712
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java39
1 files changed, 26 insertions, 13 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 bb01cae2de..f07aeafd01 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
@@ -85,24 +85,31 @@ public class ASTCommenter {
private static ArrayList<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, ArrayList<IASTComment> comments) {
IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements();
TreeMap<Integer,String> treeOfPreProcessorLines = new TreeMap<Integer,String>();
- ArrayList<Integer> listOfPreProcessorOffset = new ArrayList<Integer>();
+ TreeMap<String, ArrayList<Integer>> ppOffsetForFiles = new TreeMap<String, ArrayList<Integer>>();
for (IASTPreprocessorStatement statement : preprocessorStatements) {
if (isInWorkspace(statement)) {
- treeOfPreProcessorLines.put(OffsetHelper.getStartingLineNumber(statement), statement.getFileLocation().getFileName());
- listOfPreProcessorOffset.add(statement.getFileLocation().getNodeOffset());
+ String fileName = statement.getFileLocation().getFileName();
+ treeOfPreProcessorLines.put(OffsetHelper.getStartingLineNumber(statement), fileName);
+ ArrayList<Integer> offsetList = ppOffsetForFiles.get(fileName);
+ if(offsetList == null) {
+ offsetList = new ArrayList<Integer>();
+ ppOffsetForFiles.put(fileName, offsetList);
+ }
+ offsetList.add(statement.getFileLocation().getNodeOffset());
}
}
ArrayList<IASTComment> commentsInCode = new ArrayList<IASTComment>();
for (IASTComment comment : comments) {
int comStartLineNumber = OffsetHelper.getStartingLineNumber(comment);
+ String fileName = comment.getFileLocation().getFileName();
if (treeOfPreProcessorLines.containsKey(comStartLineNumber)
- && treeOfPreProcessorLines.get(comStartLineNumber).equals(comment.getFileLocation().getFileName()
+ && treeOfPreProcessorLines.get(comStartLineNumber).equals(fileName
)) {
continue;
}
- if(commentIsAtTheBeginningBeforePreprocessorStatements(comment, listOfPreProcessorOffset)) {
+ if(commentIsAtTheBeginningBeforePreprocessorStatements(comment, ppOffsetForFiles.get(fileName))) {
continue;
}
commentsInCode.add(comment);
@@ -113,27 +120,33 @@ public class ASTCommenter {
private static boolean commentIsAtTheBeginningBeforePreprocessorStatements(
IASTComment comment,
ArrayList<Integer> listOfPreProcessorOffset) {
- if(listOfPreProcessorOffset.size() <1) {
+ if(listOfPreProcessorOffset == null) {
return false;
}
if(comment.getTranslationUnit()==null || comment.getTranslationUnit().getDeclarations().length < 1) {
return true;
}
- IASTDeclaration decl = comment.getTranslationUnit().getDeclarations()[0];
- if(decl.getFileLocation().getNodeOffset() < comment.getFileLocation().getNodeOffset()) {
- return false;
+ IASTDeclaration decl = comment.getTranslationUnit().getDeclarations()[0];
+ boolean sameFile = decl.getFileLocation().getFileName().equals(comment.getFileLocation().getFileName());
+ if(sameFile) {
+ if(decl.getFileLocation().getNodeOffset() < comment.getFileLocation().getNodeOffset()) {
+ return false;
+ }
}
-
Collections.sort(listOfPreProcessorOffset);
if(listOfPreProcessorOffset.get(0) < comment.getFileLocation().getNodeOffset()) {
return false;
}
- if(listOfPreProcessorOffset.get(0) < decl.getFileLocation().getNodeOffset()) {
- return true;
+ if(sameFile) {
+ if(listOfPreProcessorOffset.get(0) < decl.getFileLocation().getNodeOffset()) {
+ return true;
+ }
+ }else {
+ return true;
}
-
+
return false;
}

Back to the top