Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-02-10 00:17:43 -0500
committerSergey Prigogin2012-02-10 00:17:43 -0500
commitff94f47a9e2d77282bb3545d7d4a0ba07c676ebe (patch)
treec0f9f42770d313b0a4026b4584443e7d6bb147d0 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent143bc1aea02cf3e4bad202c4f519e8801195a55f (diff)
downloadorg.eclipse.cdt-ff94f47a9e2d77282bb3545d7d4a0ba07c676ebe.tar.gz
org.eclipse.cdt-ff94f47a9e2d77282bb3545d7d4a0ba07c676ebe.tar.xz
org.eclipse.cdt-ff94f47a9e2d77282bb3545d7d4a0ba07c676ebe.zip
Revert "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.java14
1 files changed, 6 insertions, 8 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 166f25e155..40eb821584 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
@@ -52,7 +52,6 @@ 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.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;
@@ -64,6 +63,7 @@ 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;
@@ -124,8 +124,7 @@ public class ChangeGenerator extends ASTVisitor {
rootNode.accept(pathProvider);
for (IFile currentFile : changes.keySet()) {
MultiTextEdit edit = changes.get(currentFile);
- IASTTranslationUnit ast = rootNode.getTranslationUnit();
- edit = formatChangedCode(edit, ast.getRawSignature(), ast.getOriginatingTranslationUnit());
+ edit = formatChangedCode(edit, rootNode.getTranslationUnit().getRawSignature(), currentFile.getProject());
TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile);
subchange.setEdit(edit);
change.add(subchange);
@@ -318,11 +317,11 @@ public class ChangeGenerator extends ASTVisitor {
*
* @param multiEdit The text edit produced by refactoring.
* @param code The code being modified.
- * @param tu The translation unit containing the code.
+ * @param project The project 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, ITranslationUnit tu) {
+ private MultiTextEdit formatChangedCode(MultiTextEdit multiEdit, String code, IProject project) {
IDocument document = new Document(code);
try {
// Apply refactoring changes to a temporary document.
@@ -365,9 +364,8 @@ public class ChangeGenerator extends ASTVisitor {
}
// Calculate formatting changes for the regions after the refactoring changes.
- ICProject project = tu.getCProject();
- Map<String, Object> options = new HashMap<String, Object>(project.getOptions(true));
- options.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
+ ICProject proj = CCorePlugin.getDefault().getCoreModel().create(project);
+ Map<String, String> options = proj.getOptions(true);
// Allow all comments to be indented.
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
DefaultCodeFormatterConstants.FALSE);

Back to the top