void () { // Inspired by IDEA-60304. doTextTest( "java", """ class Foo { void test() { if (foo()) { } else {<caret> if (bar()) { quux(); } } }""", """ class Foo { void test() { if (foo()) { } else { if (bar()) { quux(); } } } }""" ); } public void testStringLiteralAsReferenceExpression() { doTextTest("java", """ public class Test { { String q = "abcdef<caret>ghijkl".replaceAll("KEY", "key"); } }""", """ public class Test { { String q = ("abcdef" + "<caret>ghijkl").replaceAll("KEY", "key"); } }""" ); } public void testInsideFor() { CodeStyleSettings settings = getCodeStyleSettings(); settings.getCommonSettings(JavaLanguage.INSTANCE).ALIGN_MULTILINE_FOR = true; doTextTest("java", """ class Foo { void foo() { for(int i = 0;<caret> } }""", """ class Foo { void foo() { for(int i = 0; <caret> } }"""); doTextTest("java", """ class Foo { void foo() { for(int i = 0; i < 10;<caret> } }""", """ class Foo { void foo() { for(int i = 0; i < 10; <caret> } }"""); } public void testSCR1696() { doTextTest("java", """ class Foo { void foo() { for(;;)<caret> foo(); } }""", """ class Foo { void foo() { for(;;) <caret> foo(); } }"""); doTextTest("java", """ class Foo { void foo() { for(;;) {<caret> foo();} } }""", """ class Foo { void foo() { for(;;) { <caret> foo();} } }"""); doTextTest("java", """ class Foo { void foo() { for(;;) <caret>{ foo();} } }""", """ class Foo { void foo() { for(;;)\s <caret>{ foo();} } }"""); doTextTest("java", """ class Foo { void foo() { for(;<caret>;) { foo();} } }""", """ class Foo { void foo() { for(; <caret>;) { foo();} } }"""); doTextTest("java", """ class Foo { void foo() { for(;;)<caret> } }""", """ class Foo { void foo() { for(;;) <caret> } }"""); } public void testSplitLiteral() { configureByFile("/codeInsight/enterAction/splitLiteral/Before.java"); performAction(); checkResultByFile("/codeInsight/enterAction/splitLiteral/After.java"); } public void testWithinBracesWithSpaceAfterCaret() { String path = "/codeInsight/enterAction/afterLbrace/"; configureByFile(path + "WithinBracesWithSpaceAfterCaret.java"); performAction(); checkResultByFile(path + "WithinBracesWithSpaceAfterCaret_after.java"); } public void testSCR26493() { configureByFile("/codeInsight/enterAction/SCR26493/before1.java"); performAction(); checkResultByFile("/codeInsight/enterAction/SCR26493/after1.java"); } public void testGetLineIndent() { CodeStyleSettings settings = getCodeStyleSettings(); final CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptions(JavaFileType.INSTANCE); indentOptions.USE_TAB_CHARACTER = true; indentOptions.SMART_TABS = true; indentOptions.TAB_SIZE = 2; indentOptions.INDENT_SIZE = 2; indentOptions.CONTINUATION_INDENT_SIZE = 8; settings.getCommonSettings(JavaLanguage.INSTANCE).ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; String text = """ class Foo { \tint \t\t\t\t\tmyField; \tvoid foo (int i, \t int j ) { \t}}"""; PsiFileFactory factory = PsiFileFactory.getInstance(PsiManager.getInstance(getProject()).getProject()); final PsiFile file = factory.createFileFromText("a.java", JavaFileType.INSTANCE, text, LocalTimeCounter.currentTime(), true); doGetIndentTest(file, 2, "\t\t\t\t\t"); doGetIndentTest(file, 4, "\t"); doGetIndentTest(file, 6, "\t "); } public void testEnterInImplementsList() { CodeStyleSettings settings = CodeStyle.getSettings(getProject()); settings.getCommonSettings(JavaLanguage.INSTANCE).ALIGN_MULTILINE_EXTENDS_LIST = false; doTextTest("java", """ class A implements B,<caret> { }""", """ class A implements B, <caret> { }"""); } public void testInsideJavadocParameter() { // Inspired by IDEA-IDEA-70194 doTextTest( "java", """ abstract class Test { /** * @param i this is my <caret>description */ void test(int i) { } }""", """ abstract class Test { /** * @param i this is my\s * <caret>description */ void test(int i) { } }""" ); } public void testAfterLbrace3() { String path = "/codeInsight/enterAction/afterLbrace/"; configureByFile(path + "Before3.java"); performAction(); checkResultByFile(path + "After3.java"); } public void testIdea108112() { CodeStyleSettings settings = CodeStyle.getSettings(getProject()); CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE); javaSettings.ALIGN_MULTILINE_BINARY_OPERATION = true; doTextTest( "java", """ public class Test { public void bar() { boolean abc; while (abc &&<caret>) { } } }""", """ public class Test { public void bar() { boolean abc; while (abc && <caret>) { } } }""" ); } public void testIdea115696() { doTextTest( "java", """ class T { private void someMethod() { System.out.println("foo" +<caret>); } }""", """ class T { private void someMethod() { System.out.println("foo" + <caret>); } }""" ); } public void testIdea153628() { CodeStyleSettings settings = CodeStyle.getSettings(getProject()); CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE); javaSettings.ALIGN_MULTILINE_BINARY_OPERATION = true; doTextTest( "java", """ public class Test { public boolean hasInvalidResults() { return foo ||<caret>; } }""", """ public class Test { public boolean hasInvalidResults() { return foo || <caret>; } }""" ); } public void testIdea188397() { doTextTest( "java", """ public class Test { public static void main(String[] args) { System.out.println("Hello World!");}<caret> }""", """ public class Test { public static void main(String[] args) { System.out.println("Hello World!");} <caret> }""" ); } public void testLineCommentInJavadoc() { doTextTest("java", """ abstract class Test { /**<caret>Foo//bar */ public abstract void foo(); }\ """, """ abstract class Test { /** * <caret>Foo//bar */ public abstract void foo(); }\ """ ); } public void testIdea235221() { doTextTest( "java", """ package test; public class Crush { void crush() { assertThat() /* Then */ .isNotNull()<caret> } }""", """ package test; public class Crush { void crush() { assertThat() /* Then */ .isNotNull() <caret> } }""" ); } public void testAfterDocComment() { doTextTest("java", """ class Test { /* * */<caret>void m() {} }""", """ class Test { /* * */ <caret>void m() {} }"""); } public void testInsideParameterList() { CodeStyleSettings settings = getCodeStyleSettings(); settings.getCommonSettings(JavaLanguage.INSTANCE).ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false; doTextTest("java", """ class Foo { void foo() { foo(1,<caret>); } }""", """ class Foo { void foo() { foo(1, <caret>); } }"""); doTextTest("java", """ class Foo { void foo() { foo(1,<caret> } }""", """ class Foo { void foo() { foo(1, <caret> } }"""); } public void _testSCR1488() { JavaCodeStyleSettings.getInstance(getProject()).JD_LEADING_ASTERISKS_ARE_ENABLED = false; doTextTest("java", """ class Foo { /**<caret> public int foo(int i, int j, int k) throws IOException { }}""", """ class Foo { /** <caret> @param i @param j @param k @return @throws IOException */ public int foo(int i, int j, int k) throws IOException { }}"""); } public void testJavaDocSplitWhenLeadingAsterisksAreDisabled() throws Exception { JavaCodeStyleSettings.getInstance(getProject()).JD_LEADING_ASTERISKS_ARE_ENABLED = false; doTest(); } public void testInsideJavadocParameterWithCodeStyleToAvoidAlignment() { // Inspired by IDEA-75802 JavaCodeStyleSettings.getInstance(getProject()).JD_ALIGN_PARAM_COMMENTS = false; doTextTest( "java", """ abstract class Test { /** * @param i this is my <caret>description */ void test(int i) { } }""", """ abstract class Test { /** * @param i this is my\s * <caret>description */ void test(int i) { } }""" ); } public void testEnterInsideAnnotationParameters() { JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject()); javaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS = true; doTextTest("java", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class, <caret>) public void run() { } \s \s }""", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class,\s <caret>) public void run() { } \s \s }"""); doTextTest("java", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class, <caret> ) public void run() { } \s \s }""", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class,\s <caret> ) public void run() { } \s \s }"""); } public void testEnterInsideAnnotationParameters_AfterNameValuePairBeforeLparenth() { JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject()); javaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS = true; doTextTest("java", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class<caret>) public void run() { } \s \s }""", """ public class T { @Configurable(order = 25,\s validator = BigDecimalPercentValidator.class <caret>) public void run() { } \s \s }"""); } }