1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Bug 371165 - Invalid formatting of newly created classes.

This commit is contained in:
Sergey Prigogin 2012-02-09 18:47:09 -08:00
parent 5b8296109c
commit 143bc1aea0

View file

@ -15,8 +15,10 @@
package org.eclipse.cdt.internal.ui.wizards.classwizard; package org.eclipse.cdt.internal.ui.wizards.classwizard;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -44,6 +46,7 @@ import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeReference; import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.QualifiedTypeName; import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.formatter.CodeFormatter; import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICContainer;
@ -352,17 +355,19 @@ public class NewClassCodeGenerator {
*/ */
private String formatSource(String content, ITranslationUnit tu) throws CModelException { private String formatSource(String content, ITranslationUnit tu) throws CModelException {
String lineDelimiter= StubUtility.getLineDelimiterUsed(tu); String lineDelimiter= StubUtility.getLineDelimiterUsed(tu);
TextEdit edit= CodeFormatterUtil.format(CodeFormatter.K_TRANSLATION_UNIT, content, 0, lineDelimiter, Map<String, Object> options = new HashMap<String, Object>(tu.getCProject().getOptions(true));
tu.getCProject().getOptions(true)); options.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
TextEdit edit= CodeFormatterUtil.format(CodeFormatter.K_TRANSLATION_UNIT, content, 0,
lineDelimiter, options);
if (edit != null) { if (edit != null) {
IDocument doc= new Document(content); IDocument doc= new Document(content);
try { try {
edit.apply(doc); edit.apply(doc);
content= doc.get(); content= doc.get();
} catch (MalformedTreeException exc) { } catch (MalformedTreeException e) {
CUIPlugin.log(exc); CUIPlugin.log(e);
} catch (BadLocationException exc) { } catch (BadLocationException e) {
CUIPlugin.log(exc); CUIPlugin.log(e);
} }
} }
return content; return content;