mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Comments in ChangeGenerator, by Emanuel Graf, bug 226251.
This commit is contained in:
parent
e4ae8a89a7
commit
d5ad391d97
2 changed files with 14 additions and 10 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
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$
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue