Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-03-13 05:49:37 -0400
committerMarkus Schorn2008-03-13 05:49:37 -0400
commit2ee490ecf38060997a582bd9ec0d87f3b2afe6be (patch)
tree625618c0541d7af4ad6448054b6300d59de5b48d /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler
parentda521c277ce97865a927d4efa64aa06541fffb07 (diff)
downloadorg.eclipse.cdt-2ee490ecf38060997a582bd9ec0d87f3b2afe6be.tar.gz
org.eclipse.cdt-2ee490ecf38060997a582bd9ec0d87f3b2afe6be.tar.xz
org.eclipse.cdt-2ee490ecf38060997a582bd9ec0d87f3b2afe6be.zip
Improved comment assignment for the NodeCommenter, by Guido Zgraggen, bug 222529.
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/ASTCommenterVisitor.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java28
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java19
3 files changed, 21 insertions, 30 deletions
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 6856c23494..d72bf39136 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
@@ -139,6 +139,10 @@ public class ASTCommenterVisitor extends CPPASTVisitor {
return PROCESS_CONTINUE;
}
@Override
+ public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
+ return nodeCommenter.appendFreestandingComments((ASTNode)namespaceDefinition);
+ }
+ @Override
public int leave(IASTInitializer initializer) {
nodeCommenter.appendComments((ASTNode)initializer);
return PROCESS_CONTINUE;
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 08fc854912..42aa07ee72 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
@@ -22,34 +22,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
*
*/
public class NodeCommentMap {
-
- protected final HashMap<IASTNode, ArrayList<IASTComment>> map = new HashMap<IASTNode, ArrayList<IASTComment>>();
-
- public void addCommentToNode(IASTNode node, IASTComment comment){
- ArrayList<IASTComment> comments = map.get(node);
- if(comments == null){
- comments = new ArrayList<IASTComment>();
- }
- comments.add(comment);
- map.put(node, comments);
- }
-
- public ArrayList<IASTComment> getCommentsForNode(IASTNode node){
- if(map.get(node) == null) {
- return new ArrayList<IASTComment>();
- }
- return map.get(node);
- }
-
- //needed for testing
- public HashMap<IASTNode, ArrayList<IASTComment>> getMap() {
- return map;
- }
-
-
- //===
- //Erst nur einmal zu test zwecken
- // Wenn wircklich gebraucht refactorn
protected final HashMap<IASTNode, ArrayList<IASTComment>> leadingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
protected final HashMap<IASTNode, ArrayList<IASTComment>> trailingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
protected final HashMap<IASTNode, ArrayList<IASTComment>> freestandingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
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 09677a232b..2fbd7d1763 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
@@ -24,12 +24,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTForStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIfStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLabelStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLinkageSpecification;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSwitchStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -164,12 +168,12 @@ public class NodeCommenter {
return true;
}else if(parent instanceof IASTTranslationUnit) {
return true;
- }else if(parent instanceof ICPPASTBaseSpecifier) {
- parent = (ASTNode) parent.getParent();
}else if(parent instanceof ICPPASTTemplateDeclaration) {
return true;
}else if(parent instanceof CPPASTIfStatement) {
return true;
+ }else if(parent instanceof ICPPASTBaseSpecifier) {
+ parent = (ASTNode) parent.getParent();
}
return !(OffsetHelper.getNodeOffset(com) >= OffsetHelper.getNodeEndPoint(parent));
}
@@ -193,6 +197,14 @@ public class NodeCommenter {
return true;
}else if(node instanceof CPPASTWhileStatement) {
return true;
+ }else if(node instanceof CPPASTTemplateDeclaration) {
+ return true;
+ }else if(node instanceof CPPASTLinkageSpecification) {
+ return true;
+ }else if(node instanceof GPPASTExplicitTemplateInstantiation) {
+ return true;
+ }else if(node instanceof CPPASTExplicitTemplateInstantiation) {
+ return true;
}
return false;
}
@@ -234,6 +246,9 @@ public class NodeCommenter {
public void appendRemainingComments(IASTDeclaration declaration) {
while(commHandler.hasMore()) {
IASTComment comment = commHandler.getFirst();
+ if(appendComment((ASTNode)declaration, comment)) {
+ continue;
+ }
addFreestandingCommentToMap((ASTNode) declaration, comment);
}
}

Back to the top