Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-09 11:51:43 +0000
committerMarkus Schorn2008-04-09 11:51:43 +0000
commitd5ad391d97ba12401eca1f34188c7ab985aea0c6 (patch)
tree8230bd25415166c8971eef29222d23aafe9470cd
parente4ae8a89a70887c66370ec6060322c6ee99b7fcd (diff)
downloadorg.eclipse.cdt-d5ad391d97ba12401eca1f34188c7ab985aea0c6.tar.gz
org.eclipse.cdt-d5ad391d97ba12401eca1f34188c7ab985aea0c6.tar.xz
org.eclipse.cdt-d5ad391d97ba12401eca1f34188c7ab985aea0c6.zip
Comments in ChangeGenerator, by Emanuel Graf, bug 226251.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java20
2 files changed, 14 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java
index 9192543bbfe..ed44c473795 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java
@@ -35,8 +35,8 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override
protected void setUp() throws Exception {
- source = "void foo(int parameter) throw (float){\n}\n\n"; //$NON-NLS-1$
- expectedSource = "void foo(int parameter) throw (int, float){\n}\n\n"; //$NON-NLS-1$
+ source = "void foo(int parameter) throw (/*Test*/float) /*Test2*/{\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter) throw (int, /*Test*/float) /*Test2*/{\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
index 231733a9ee7..4129be85926 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
@@ -33,6 +33,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
import org.eclipse.core.resources.IFile;
@@ -56,6 +58,7 @@ public class ChangeGenerator extends CPPASTVisitor {
private CompositeChange change;
private final ASTModificationStore modificationStore;
+ private NodeCommentMap commentMap;
{
shouldVisitExpressions = true;
@@ -97,6 +100,7 @@ public class ChangeGenerator extends CPPASTVisitor {
throws ProblemRuntimeException {
change = new CompositeChange(Messages.ChangeGenerator_compositeChange);
initParentModList();
+ commentMap = ASTCommenter.getCommentedNodeMap(rootNode.getTranslationUnit());
rootNode.accept(pathProvider);
for (IFile currentFile : changes.keySet()) {
@@ -161,12 +165,13 @@ public class ChangeGenerator extends CPPASTVisitor {
String indent = getIndent(synthNode);
ASTWriter synthWriter = new ASTWriter(indent);
synthWriter.setModificationStore(modificationStore);
- String synthSource = synthWriter.write(synthNode);
- reformatSynthCode(synthNode, synthSource); /*XXX resultat wird nicht verwendet?*/
+
+ String synthSource = synthWriter.write(synthNode, fileScope, commentMap);
+ reformatSynthCode(synthNode, synthSource); /*XXX resultat wird nicht verwendet?*/
int newOffset = synthNode.getFileLocation().getNodeOffset()
- + synthNode.getFileLocation().getNodeLength();
+ + synthNode.getFileLocation().getNodeLength();
sourceOffsets.put(synthNode.getFileLocation().getFileName(), Integer.valueOf(newOffset));
}
@@ -177,11 +182,11 @@ public class ChangeGenerator extends CPPASTVisitor {
for (ASTModification modification : modificationParent.get(synthTU)) {
IASTFileLocation targetLocation = modification.getTargetNode()
- .getFileLocation();
+ .getFileLocation();
String currentFile = targetLocation.getFileName();
IPath implPath = new Path(currentFile);
IFile relevantFile = ResourcesPlugin.getWorkspace().getRoot()
- .getFileForLocation(implPath);
+ .getFileForLocation(implPath);
MultiTextEdit edit;
if (changes.containsKey(relevantFile)) {
edit = changes.get(relevantFile);
@@ -189,8 +194,8 @@ public class ChangeGenerator extends CPPASTVisitor {
edit = new MultiTextEdit();
changes.put(relevantFile, edit);
}
+ String newNodeCode = synthWriter.write(modification.getNewNode(), null, commentMap);
- String newNodeCode = synthWriter.write(modification.getNewNode());
switch (modification.getKind()) {
case REPLACE:
edit.addChild(new ReplaceEdit(targetLocation.getNodeOffset(),
@@ -555,9 +560,8 @@ public class ChangeGenerator extends CPPASTVisitor {
: synthCode.length());
if (replacementStart < replacementEnd) {
return synthCode.substring(replacementStart, replacementEnd);
- } else {
- return ""; //$NON-NLS-1$
}
+ return ""; //$NON-NLS-1$
}
}

Back to the top