mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-90860 Reformat Code breaks Copyright/Header
1. Block.getSpacing() contract is refined; 2. Java formatter tests don't strip line feeds and trailing spaces now; 3. Test data is corrected;
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
foo(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
public class A {
|
||||
private void foo() {
|
||||
Runnable a = new Runnable() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
someVariable = x =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
for (int i = 0;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
int someVariable = (y +
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class A {
|
||||
A IMPL = new A() {
|
||||
void f(boolean b) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
public class A {
|
||||
void f() {
|
||||
new My() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
assert false;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
if (a) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void a() {
|
||||
if (b) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
if (a) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class A {
|
||||
void foo() {
|
||||
continue;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class C {
|
||||
{
|
||||
for (String s : collection) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
if (a) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
if (a) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
if (a)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
bar_call(new Runnable() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
public class Test {
|
||||
void anotherMethod(String s);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
ClassBar bar =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class C {
|
||||
public static final C1 ourC =
|
||||
new C2(new C3(),
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
try
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class TestFormat {
|
||||
public void test(boolean isA, boolean isB, boolean isC) {
|
||||
if (isA)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
if (AAA == BBB ||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
public class Y implements X {
|
||||
public void doSomething() // this does something
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class A {
|
||||
{
|
||||
y = x+++6;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
switch (a) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
LOG.bar();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
int someVariable = a ?
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
void foo() {
|
||||
int someVariable = a ?
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Foo {
|
||||
public void foo() {
|
||||
assertEquals(map.get(new File("C:\\PerforceTest1\\created2.txt")), );
|
||||
|
||||
+2
-28
@@ -20,7 +20,6 @@ import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
@@ -161,9 +160,9 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase {
|
||||
fail("Don't expect the document to be null");
|
||||
return;
|
||||
}
|
||||
assertEquals(prepareText(textAfter), prepareText(document.getText()));
|
||||
assertEquals(textAfter, document.getText());
|
||||
manager.commitDocument(document);
|
||||
assertEquals(prepareText(textAfter), prepareText(file.getText()));
|
||||
assertEquals(textAfter, file.getText());
|
||||
|
||||
}
|
||||
|
||||
@@ -183,31 +182,6 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
private static String prepareText(String actual) {
|
||||
if (actual.startsWith("\n")) {
|
||||
actual = actual.substring(1);
|
||||
}
|
||||
if (actual.startsWith("\n")) {
|
||||
actual = actual.substring(1);
|
||||
}
|
||||
|
||||
// Strip trailing spaces
|
||||
final Document doc = EditorFactory.getInstance().createDocument(actual);
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((DocumentImpl)doc).stripTrailingSpaces();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "formatting", null);
|
||||
|
||||
return doc.getText();
|
||||
}
|
||||
|
||||
private static String loadFile(String name) throws Exception {
|
||||
String fullName = BASE_PATH + File.separatorChar + name;
|
||||
String text = FileUtil.loadFile(new File(fullName));
|
||||
|
||||
+3
-3
@@ -103,12 +103,12 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
|
||||
"void foo() {\n" +
|
||||
"}",
|
||||
"@Override\n" +
|
||||
"public int hashCode() \n" +
|
||||
"public int hashCode()\n" +
|
||||
"{\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"@Deprecated\n" +
|
||||
"void foo() \n" +
|
||||
"void foo()\n" +
|
||||
"{\n" +
|
||||
"}"
|
||||
);
|
||||
@@ -147,7 +147,7 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
|
||||
getSettings().CLASS_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
String text =
|
||||
"class Test \n" +
|
||||
"class Test\n" +
|
||||
"{\n" +
|
||||
" void foo() {\n" +
|
||||
" bind(new TypeLiteral<MyType>() {}).toProvider(MyProvider.class);\n" +
|
||||
|
||||
+10
-10
@@ -321,14 +321,14 @@ public class JavaFormatterIndentationTest extends AbstractJavaFormatterTest {
|
||||
"} \n" +
|
||||
"); ",
|
||||
"foo(\"long string as the first argument\", new Runnable() {\n" +
|
||||
" public void run() { \n" +
|
||||
" } \n" +
|
||||
" }, \n" +
|
||||
" new Runnable() { \n" +
|
||||
" public void run() { \n" +
|
||||
" } \n" +
|
||||
" } \n" +
|
||||
"); "
|
||||
" public void run() {\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" new Runnable() {\n" +
|
||||
" public void run() {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
");"
|
||||
);
|
||||
|
||||
doMethodTest(
|
||||
@@ -343,7 +343,7 @@ public class JavaFormatterIndentationTest extends AbstractJavaFormatterTest {
|
||||
" @Override\n" +
|
||||
" public void run() {\n" +
|
||||
" }\n" +
|
||||
"}); "
|
||||
"});"
|
||||
);
|
||||
|
||||
doMethodTest(
|
||||
@@ -504,7 +504,7 @@ public class JavaFormatterIndentationTest extends AbstractJavaFormatterTest {
|
||||
);
|
||||
}
|
||||
|
||||
public void testMultilineComment() {
|
||||
public void testMultilineCommentAtFileStart() {
|
||||
// IDEA-90860
|
||||
String text =
|
||||
"\n" +
|
||||
|
||||
@@ -242,8 +242,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
settings.ALIGN_MULTILINE_ASSIGNMENT = true;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" + ccc + eee + ddd;\n" +
|
||||
@@ -252,8 +251,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
settings.ALIGN_MULTILINE_ASSIGNMENT = false;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" + ccc + eee + ddd;\n" +
|
||||
@@ -263,8 +261,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = false;
|
||||
settings.ALIGN_MULTILINE_ASSIGNMENT = true;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" + ccc + eee + ddd;\n" +
|
||||
@@ -274,8 +271,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.ALIGN_MULTILINE_ASSIGNMENT = false;
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = false;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" + ccc + eee + ddd;\n" +
|
||||
@@ -285,8 +281,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
settings.ALIGN_MULTILINE_ASSIGNMENT = false;
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = false;
|
||||
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" + ccc + eee + ddd;\n" +
|
||||
@@ -297,7 +292,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
settings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
|
||||
doTextTest("class Foo {\n" + " void foo () {\n" + " xxx = aaa + bbb \n" + " - ccc + eee + ddd;\n" + " }\n" + "}",
|
||||
"\nclass Foo {\n" +
|
||||
"class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" - ccc + eee + ddd;\n" +
|
||||
@@ -305,7 +300,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
"}");
|
||||
|
||||
doTextTest("class Foo {\n" + " void foo () {\n" + " xxx = aaa + bbb \n" + " * ccc + eee + ddd;\n" + " }\n" + "}",
|
||||
"\nclass Foo {\n" +
|
||||
"class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" xxx = aaa + bbb\n" +
|
||||
" * ccc + eee + ddd;\n" +
|
||||
@@ -347,7 +342,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
doTextTest("class Foo {\n" + " void foo () {\n" + "String s = \"abc\" +\n" + "\"def\";" + " }\n" + "}",
|
||||
|
||||
"\nclass Foo {\n" +
|
||||
"class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" String s = \"abc\" +\n" +
|
||||
" \"def\";\n" +
|
||||
@@ -379,8 +374,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo() {\n" +
|
||||
" if (a) {\n" +
|
||||
" int i = 0;\n" +
|
||||
@@ -390,8 +384,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo()\n" +
|
||||
" {\n" +
|
||||
" if (a)\n" +
|
||||
@@ -404,8 +397,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
|
||||
settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo()\n" +
|
||||
" {\n" +
|
||||
" if (a)\n" +
|
||||
@@ -417,8 +409,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
|
||||
settings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo()\n" +
|
||||
" {\n" +
|
||||
" if (a) {\n" +
|
||||
@@ -430,8 +421,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
settings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED2;
|
||||
settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED2;
|
||||
doTextTest(text, "\n" +
|
||||
"class Foo {\n" +
|
||||
doTextTest(text, "class Foo {\n" +
|
||||
" void foo()\n" +
|
||||
" {\n" +
|
||||
" if (a)\n" +
|
||||
@@ -538,7 +528,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
public void testTwoJavaDocs() throws Exception {
|
||||
doTextTest("/**\n" + " * \n" + " */\n" + " class Test {\n" + " /**\n" + " */\n" + " public void foo();\n" + "}",
|
||||
"/**\n" + " * \n" + " */\n" + "class Test {\n" + " /**\n" + " */\n" + " public void foo();\n" + "}");
|
||||
"/**\n" + " *\n" + " */\n" + "class Test {\n" + " /**\n" + " */\n" + " public void foo();\n" + "}");
|
||||
}
|
||||
|
||||
public void testJavaDocLinksWithParameterNames() throws Exception {
|
||||
@@ -595,7 +585,7 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
|
||||
|
||||
public void testDocComment() throws Exception {
|
||||
doTextTest("public class TestClass {\n" + "/**\n" + "* \n" + "*/\n" + " public void f1() {\n" + " }\n" + "}",
|
||||
"public class TestClass {\n" + " /**\n" + " * \n" + " */\n" + " public void f1() {\n" + " }\n" + "}");
|
||||
"public class TestClass {\n" + " /**\n" + " *\n" + " */\n" + " public void f1() {\n" + " }\n" + "}");
|
||||
}
|
||||
|
||||
public void testDocComment2() throws Exception {
|
||||
|
||||
@@ -179,12 +179,12 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
|
||||
" public String s = \"this is a string that is long enough to be wrapped\"\n" +
|
||||
"}",
|
||||
"class TestClass {\n" +
|
||||
" // Single line comment that is long enough\n" +
|
||||
" // Single line comment that is long enough \n" +
|
||||
" // to exceed right margin\n" +
|
||||
" /* Multi line comment that is long enough\n" +
|
||||
" /* Multi line comment that is long enough \n" +
|
||||
" to exceed right margin*/\n" +
|
||||
" /**\n" +
|
||||
" * Javadoc comment that is long enough to\n" +
|
||||
" * Javadoc comment that is long enough to \n" +
|
||||
" * exceed right margin\n" +
|
||||
" */\n" +
|
||||
" public String s = \"this is a string that is\" +\n" +
|
||||
@@ -205,7 +205,7 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
|
||||
"\t \t //This is a comment\n" +
|
||||
"}",
|
||||
"class TestClass {\n" +
|
||||
"\t//This is a\n" +
|
||||
"\t//This is a \n" +
|
||||
"\t// comment\n" +
|
||||
"}"
|
||||
);
|
||||
@@ -231,7 +231,7 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest {
|
||||
doTextTest(
|
||||
initial,
|
||||
"class TestClass {\n" +
|
||||
" //This is a\n" +
|
||||
" //This is a \n" +
|
||||
" // comment\n" +
|
||||
" //This is another comment\n" +
|
||||
"}"
|
||||
|
||||
@@ -33,7 +33,7 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest {
|
||||
"class Foo {\n" +
|
||||
"}",
|
||||
"/**\n" +
|
||||
" * Here is one-line java-doc\n" +
|
||||
" * Here is one-line java-doc \n" +
|
||||
" * comment\n" +
|
||||
" */\n" +
|
||||
"class Foo {\n" +
|
||||
|
||||
Reference in New Issue
Block a user