Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaisuke Nojiri2014-09-05 18:04:42 +0000
committerSergey Prigogin2014-09-05 22:47:18 +0000
commit0234c6c601cc92fe7537af4dbb4b40d5e44298c1 (patch)
tree4c43bf6e9cd2aa0f6bcf7eb7ca5e0c44f6673207
parenta6265b01d4cd3bef3f4f20f7a42816ebf4d846b6 (diff)
downloadorg.eclipse.cdt-0234c6c601cc92fe7537af4dbb4b40d5e44298c1.tar.gz
org.eclipse.cdt-0234c6c601cc92fe7537af4dbb4b40d5e44298c1.tar.xz
org.eclipse.cdt-0234c6c601cc92fe7537af4dbb4b40d5e44298c1.zip
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>
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java1
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java20
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java11
3 files changed, 22 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
index 870b06c7f4d..a6c7e41938a 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
@@ -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);
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
index e1389e636aa..3dfd19832b7 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
@@ -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));
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
index 14fe12bf58d..ed22ab5c7f1 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
@@ -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;
}

Back to the top