diff --git a/java/java-tests/testSrc/com/intellij/psi/codeStyle/autodetect/DetectIndentAndTypeTest.java b/java/java-tests/testSrc/com/intellij/psi/codeStyle/autodetect/DetectIndentAndTypeTest.java index 0a13972a6be4..7e0d14563ce3 100644 --- a/java/java-tests/testSrc/com/intellij/psi/codeStyle/autodetect/DetectIndentAndTypeTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/codeStyle/autodetect/DetectIndentAndTypeTest.java @@ -25,6 +25,11 @@ import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCa public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTestCase { private CodeStyleSettings mySettings; + private String myText = "public class T {\n" + + "\tvoid run() {\n" + + "\t\tint t = 1 + 2;\n" + + "\t}\n" + + "}"; @Override public void setUp() throws Exception { @@ -72,6 +77,51 @@ public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTest "}\n"); } + public void testContinuationTab_AsTabSize() { + CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE); + mySettings.ALIGN_MULTILINE_BINARY_OPERATION = false; + CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions(); + + assert indentOptions != null; + + indentOptions.TAB_SIZE = 2; + indentOptions.INDENT_SIZE = 2; + indentOptions.CONTINUATION_INDENT_SIZE = 2; + + myFixture.configureByText(JavaFileType.INSTANCE, myText); + myFixture.type('\n'); + + myFixture.checkResult( + "public class T {\n" + + "\tvoid run() {\n" + + "\t\tint t = 1 + \n" + + "\t\t\t2;\n" + + "\t}\n" + + "}"); + } + + public void testContinuationTabs_AsDoubleTabSize() { + CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE); + mySettings.ALIGN_MULTILINE_BINARY_OPERATION = false; + CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions(); + + assert indentOptions != null; + + indentOptions.TAB_SIZE = 2; + indentOptions.INDENT_SIZE = 2; + indentOptions.CONTINUATION_INDENT_SIZE = 4; + myFixture.configureByText(JavaFileType.INSTANCE, myText); + myFixture.type('\n'); + + myFixture.checkResult( + "public class T {\n" + + "\tvoid run() {\n" + + "\t\tint t = 1 + \n" + + "\t\t\t\t2;\n" + + "\t}\n" + + "}"); + } + public void testWhenTabsDetected_SetContinuationIndentSizeToDoubleTabSize() { CommonCodeStyleSettings common = mySettings.getCommonSettings(JavaLanguage.INSTANCE); CommonCodeStyleSettings.IndentOptions indentOptions = common.getIndentOptions(); @@ -80,7 +130,7 @@ public class DetectIndentAndTypeTest extends LightPlatformCodeInsightFixtureTest indentOptions.INDENT_SIZE = 1; indentOptions.TAB_SIZE = 2; - indentOptions.CONTINUATION_INDENT_SIZE = 8; + indentOptions.CONTINUATION_INDENT_SIZE = 2; myFixture.configureByText(JavaFileType.INSTANCE, "public class T {\n" + diff --git a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/IndentOptionsDetectorImpl.java b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/IndentOptionsDetectorImpl.java index cb57d8372f2e..23e5e98fdb3f 100644 --- a/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/IndentOptionsDetectorImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/codeStyle/autodetect/IndentOptionsDetectorImpl.java @@ -76,8 +76,11 @@ public class IndentOptionsDetectorImpl implements IndentOptionsDetector { private void adjustIndentOptions(@NotNull IndentOptions indentOptions, @NotNull IndentUsageStatistics stats) { if (isTabsUsed(stats)) { setUseTabs(indentOptions, true); + int continuationRatio = indentOptions.INDENT_SIZE == 0 ? 1 + : indentOptions.CONTINUATION_INDENT_SIZE / indentOptions.INDENT_SIZE; + indentOptions.INDENT_SIZE = indentOptions.TAB_SIZE; - indentOptions.CONTINUATION_INDENT_SIZE = indentOptions.TAB_SIZE * 2; + indentOptions.CONTINUATION_INDENT_SIZE = indentOptions.TAB_SIZE * continuationRatio; } else if (isSpacesUsed(stats)) { setUseTabs(indentOptions, false);