1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 443436 - Auto indenter uses spaces where it should use tabs

This change makes auto indentation following a new line use tabs where
possible when "Use tabs only for leading indentations" is disabled.

Change-Id: I97d787a003763697e281bb4a8af0f4760cbd81fb
Signed-off-by: Daisuke Nojiri <dai.nojiri@gmail.com>
Reviewed-on: https://git.eclipse.org/r/32955
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Daisuke Nojiri 2014-09-05 11:04:42 -07:00 committed by Sergey Prigogin
parent 3a00410195
commit 58af86640b
3 changed files with 22 additions and 10 deletions

View file

@ -59,6 +59,7 @@ public class CHeuristicScannerTest extends TestCase {
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, indentOnColumn);
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST, indentOnColumn);
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");
options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, DefaultCodeFormatterConstants.TRUE);
CCorePlugin.setOptions(options);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2014 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
@ -45,12 +45,12 @@ public class CIndenterTest extends BaseUITestCase {
protected void setUp() throws Exception {
super.setUp();
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
fOptions= new HashMap<String, String>();
fOptions= new HashMap<>();
}
@Override
protected void tearDown() throws Exception {
CCorePlugin.setOptions(new HashMap<String, String>(fDefaultOptions));
CCorePlugin.setOptions(new HashMap<>(fDefaultOptions));
super.tearDown();
}
@ -254,15 +254,19 @@ public class CIndenterTest extends BaseUITestCase {
assertIndenterResult();
}
//void test() {
//new pair<int, int>(a,
//b);
//}
//new pair<int, int>(a,
// b);
//void test() {
// new pair<int, int>(a,
// b);
//}
public void testCallOfTemplateFunction() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "2");
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "2");
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4");
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT,
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

View file

@ -79,6 +79,7 @@ public final class CIndenter {
final int prefContinuationIndent;
final boolean prefHasTemplates;
final String prefTabChar;
final boolean prefTabsOnlyForLeadingIndents;
private final IPreferencesService preferenceService;
private final IScopeContext[] preferenceContexts;
@ -143,8 +144,9 @@ public final class CIndenter {
prefIndentBracesForTypes= prefIndentBracesForTypes();
prefHasTemplates= hasTemplates();
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
prefTabsOnlyForLeadingIndents = prefTabsOnlyForLeadingIndents();
}
private boolean prefUseTabs() {
return !CCorePlugin.SPACE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
}
@ -378,6 +380,11 @@ public final class CIndenter {
private boolean hasTemplates() {
return true;
}
private boolean prefTabsOnlyForLeadingIndents() {
return DefaultCodeFormatterConstants.TRUE.equals(
getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS));
}
}
/** The document being scanned. */
@ -500,7 +507,7 @@ public final class CIndenter {
// a special case has been detected.
IRegion line= fDocument.getLineInformationOfOffset(fAlign);
int lineOffset= line.getOffset();
return createIndent(lineOffset, fAlign, false);
return createIndent(lineOffset, fAlign, !fPrefs.prefTabsOnlyForLeadingIndents);
} catch (BadLocationException e) {
return null;
}