1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 190184: [Formater] space before the open the opening brace in method declaration

This commit is contained in:
Anton Leherbauer 2007-05-31 14:37:15 +00:00
parent 65b9130f64
commit b93703b14f
3 changed files with 80 additions and 2 deletions

View file

@ -819,6 +819,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTStandardFunctionDeclarator node) {
final List parameters = Arrays.asList(node.getParameters());
final ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration);
align.fSpaceBeforeOpeningParen= preferences.insert_space_before_opening_paren_in_method_declaration;
align.fSpaceAfterOpeningParen= preferences.insert_space_after_opening_paren_in_method_declaration;
align.fSpaceBeforeClosingParen= preferences.insert_space_before_closing_paren_in_method_declaration;
align.fSpaceBeforeComma= preferences.insert_space_before_comma_in_method_declaration_parameters;
@ -1903,7 +1904,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_while);
formatAction(line, node.getBody(), preferences.brace_position_for_method_declaration, preferences.insert_space_before_opening_brace_in_method_declaration);
formatAction(line, node.getBody(), preferences.brace_position_for_block, preferences.insert_space_before_opening_brace_in_block);
return PROCESS_SKIP;
}

View file

@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestSuite;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
/**
* Tests for the CodeFormatter.
*
* @since 4.0
*/
public class CodeFormatterTest extends BaseUITestCase {
private Map fOptions;
private Map fDefaultOptions;
public static TestSuite suite() {
return suite(CodeFormatterTest.class, "_");
}
protected void setUp() throws Exception {
super.setUp();
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
fOptions= new HashMap(fDefaultOptions);
}
protected void tearDown() throws Exception {
super.tearDown();
}
protected void assertFormatterResult() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
String before= contents[0].toString();
IDocument document= new Document(before);
String expected= contents[1].toString();
TextEdit edit= CodeFormatterUtil.format(CodeFormatter.K_COMPILATION_UNIT, before, 0, TextUtilities.getDefaultLineDelimiter(document), fOptions);
assertNotNull(edit);
edit.apply(document);
assertEquals(expected, document.get());
}
//void foo(int arg);
//void foo(int arg){}
//void foo (int arg);
//void foo (int arg) {
//}
public void testInsertSpaceBeforeOpeningParen_Bug190184() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_PAREN_IN_METHOD_DECLARATION, CCorePlugin.INSERT);
assertFormatterResult();
}
}

View file

@ -32,7 +32,8 @@ public class TextTestSuite extends TestSuite {
addTest(BracketInserterTest.suite());
addTest(IndentActionTest.suite());
addTest(FormatActionTest.suite());
addTest(CodeFormatterTest.suite());
// Break iterator tests.
addTest(CBreakIteratorTest.suite());
addTest(CWordIteratorTest.suite());