mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +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:
parent
3a00410195
commit
58af86640b
3 changed files with 22 additions and 10 deletions
|
@ -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_PARAMETERS_IN_METHOD_DECLARATION, indentOnColumn);
|
||||||
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST, indentOnColumn);
|
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_INITIALIZER_LIST, indentOnColumn);
|
||||||
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");
|
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");
|
||||||
|
options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, DefaultCodeFormatterConstants.TRUE);
|
||||||
CCorePlugin.setOptions(options);
|
CCorePlugin.setOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -45,12 +45,12 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
|
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
|
||||||
fOptions= new HashMap<String, String>();
|
fOptions= new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
CCorePlugin.setOptions(new HashMap<String, String>(fDefaultOptions));
|
CCorePlugin.setOptions(new HashMap<>(fDefaultOptions));
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,15 +254,19 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void test() {
|
||||||
//new pair<int, int>(a,
|
//new pair<int, int>(a,
|
||||||
//b);
|
//b);
|
||||||
|
//}
|
||||||
|
|
||||||
//new pair<int, int>(a,
|
//void test() {
|
||||||
// b);
|
// new pair<int, int>(a,
|
||||||
|
// b);
|
||||||
|
//}
|
||||||
public void testCallOfTemplateFunction() throws Exception {
|
public void testCallOfTemplateFunction() throws Exception {
|
||||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
|
||||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "2");
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
|
||||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "2");
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4");
|
||||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
|
||||||
DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT,
|
DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT,
|
||||||
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
|
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
|
||||||
|
|
|
@ -79,6 +79,7 @@ public final class CIndenter {
|
||||||
final int prefContinuationIndent;
|
final int prefContinuationIndent;
|
||||||
final boolean prefHasTemplates;
|
final boolean prefHasTemplates;
|
||||||
final String prefTabChar;
|
final String prefTabChar;
|
||||||
|
final boolean prefTabsOnlyForLeadingIndents;
|
||||||
|
|
||||||
private final IPreferencesService preferenceService;
|
private final IPreferencesService preferenceService;
|
||||||
private final IScopeContext[] preferenceContexts;
|
private final IScopeContext[] preferenceContexts;
|
||||||
|
@ -143,8 +144,9 @@ public final class CIndenter {
|
||||||
prefIndentBracesForTypes= prefIndentBracesForTypes();
|
prefIndentBracesForTypes= prefIndentBracesForTypes();
|
||||||
prefHasTemplates= hasTemplates();
|
prefHasTemplates= hasTemplates();
|
||||||
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
|
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
|
||||||
|
prefTabsOnlyForLeadingIndents = prefTabsOnlyForLeadingIndents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean prefUseTabs() {
|
private boolean prefUseTabs() {
|
||||||
return !CCorePlugin.SPACE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
|
return !CCorePlugin.SPACE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
|
||||||
}
|
}
|
||||||
|
@ -378,6 +380,11 @@ public final class CIndenter {
|
||||||
private boolean hasTemplates() {
|
private boolean hasTemplates() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean prefTabsOnlyForLeadingIndents() {
|
||||||
|
return DefaultCodeFormatterConstants.TRUE.equals(
|
||||||
|
getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The document being scanned. */
|
/** The document being scanned. */
|
||||||
|
@ -500,7 +507,7 @@ public final class CIndenter {
|
||||||
// a special case has been detected.
|
// a special case has been detected.
|
||||||
IRegion line= fDocument.getLineInformationOfOffset(fAlign);
|
IRegion line= fDocument.getLineInformationOfOffset(fAlign);
|
||||||
int lineOffset= line.getOffset();
|
int lineOffset= line.getOffset();
|
||||||
return createIndent(lineOffset, fAlign, false);
|
return createIndent(lineOffset, fAlign, !fPrefs.prefTabsOnlyForLeadingIndents);
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue