Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-02-11 13:36:01 -0500
committerSergey Prigogin2012-02-11 13:36:01 -0500
commit12c72ed17e8b3ebf6775319f9851c34f07ab1b36 (patch)
tree8ef3607cb26822033eefdacb84b495f178d02706 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent5db78a20c84976de899c8516e8038d209bbacb84 (diff)
downloadorg.eclipse.cdt-12c72ed17e8b3ebf6775319f9851c34f07ab1b36.tar.gz
org.eclipse.cdt-12c72ed17e8b3ebf6775319f9851c34f07ab1b36.tar.xz
org.eclipse.cdt-12c72ed17e8b3ebf6775319f9851c34f07ab1b36.zip
Let formatter know about the translation unit so that it can resolve
includes.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java22
1 files changed, 13 insertions, 9 deletions
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 40eb821584..eb35b998fb 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
@@ -51,7 +51,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
@@ -63,7 +65,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeExcepti
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
@@ -122,10 +123,12 @@ public class ChangeGenerator extends ASTVisitor {
change = new CompositeChange(ChangeGeneratorMessages.ChangeGenerator_compositeChange);
classifyModifications();
rootNode.accept(pathProvider);
- for (IFile currentFile : changes.keySet()) {
- MultiTextEdit edit = changes.get(currentFile);
- edit = formatChangedCode(edit, rootNode.getTranslationUnit().getRawSignature(), currentFile.getProject());
- TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile);
+ for (IFile file : changes.keySet()) {
+ MultiTextEdit edit = changes.get(file);
+ IASTTranslationUnit ast = rootNode.getTranslationUnit();
+ ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
+ edit = formatChangedCode(edit, ast.getRawSignature(), tu);
+ TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(file);
subchange.setEdit(edit);
change.add(subchange);
}
@@ -317,11 +320,11 @@ public class ChangeGenerator extends ASTVisitor {
*
* @param multiEdit The text edit produced by refactoring.
* @param code The code being modified.
- * @param project The project containing the code.
+ * @param tu The translation unit containing the code.
* @return The text edit containing formatted refactoring changes, or the original text edit
* in case of errors.
*/
- private MultiTextEdit formatChangedCode(MultiTextEdit multiEdit, String code, IProject project) {
+ private MultiTextEdit formatChangedCode(MultiTextEdit multiEdit, String code, ITranslationUnit tu) {
IDocument document = new Document(code);
try {
// Apply refactoring changes to a temporary document.
@@ -364,8 +367,9 @@ public class ChangeGenerator extends ASTVisitor {
}
// Calculate formatting changes for the regions after the refactoring changes.
- ICProject proj = CCorePlugin.getDefault().getCoreModel().create(project);
- Map<String, String> options = proj.getOptions(true);
+ ICProject project = tu.getCProject();
+ Map<String, Object> options = new HashMap<String, Object>(project.getOptions(true));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
// Allow all comments to be indented.
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
DefaultCodeFormatterConstants.FALSE);

Back to the top