From 8cfcd7e5a6c65a41fbf6c3f5f1915ed08f8ad76c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 30 Mar 2017 17:21:46 +0300 Subject: [PATCH] Inline function: add extra tests taken from intellij-community --- .../function/fromIntellij/ArrayAccess.kt | 10 ++ .../fromIntellij/ArrayAccess.kt.after | 7 + ...idMultipleSubstitutionsInParameterTypes.kt | 14 ++ ...ipleSubstitutionsInParameterTypes.kt.after | 10 ++ .../inline/function/fromIntellij/CallInFor.kt | 19 +++ .../function/fromIntellij/CallInFor.kt.after | 15 +++ .../function/fromIntellij/CallUnderIf.kt | 17 +++ .../fromIntellij/CallUnderIf.kt.after | 14 ++ .../function/fromIntellij/EnumConstructor.kt | 7 + .../function/fromIntellij/FieldInitializer.kt | 7 + .../fromIntellij/FieldInitializer.kt.after | 4 + .../function/fromIntellij/FlatVarargs.kt | 13 ++ .../fromIntellij/FlatVarargs.kt.after | 9 ++ .../InaccessibleFieldInSuperclass.kt | 13 ++ .../InaccessibleFieldInSuperclass.kt.after | 10 ++ .../function/fromIntellij/InferredType.kt | 15 +++ .../fromIntellij/InferredType.kt.after | 10 ++ .../InlineAnonymousClassWithPrivateMethod.kt | 23 ++++ ...neAnonymousClassWithPrivateMethod.kt.after | 22 ++++ ...neMultipleOccurrencesInFieldInitializer.kt | 14 ++ ...ipleOccurrencesInFieldInitializer.kt.after | 8 ++ .../fromIntellij/InlineWithQualifier.kt | 31 +++++ .../fromIntellij/InlineWithQualifier.kt.after | 29 +++++ .../function/fromIntellij/InlineWithTry.kt | 17 +++ .../function/fromIntellij/NotAStatement.kt | 22 ++++ .../fromIntellij/NotAStatement.kt.after | 18 +++ .../ParamNameConflictsWithLocalVar.kt | 13 ++ .../ParamNameConflictsWithLocalVar.kt.after | 9 ++ .../function/fromIntellij/SideEffect.kt | 13 ++ .../function/fromIntellij/SideEffect.kt.after | 9 ++ .../function/fromIntellij/Substitution.kt | 39 ++++++ .../fromIntellij/Substitution.kt.after | 34 +++++ .../function/fromIntellij/VoidWithReturn.kt | 8 ++ .../fromIntellij/VoidWithReturn.kt.after | 4 + .../function/fromIntellij/WithSuperInside.kt | 17 +++ .../fromIntellij/WithSuperInside.kt.after | 14 ++ .../inline/InlineTestGenerated.java | 123 ++++++++++++++++++ 37 files changed, 661 insertions(+) create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/EnumConstructor.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/InlineWithTry.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt.after create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt create mode 100644 idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt.after diff --git a/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt b/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt new file mode 100644 index 00000000000..e8c7401eced --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt @@ -0,0 +1,10 @@ +fun usage(arr: IntArray) { + val array: IntArray + for (i in array.indices) { + method(array[i]) + } +} + +fun method(i: Int) { + println(i) +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt.after new file mode 100644 index 00000000000..e342083b46b --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt.after @@ -0,0 +1,7 @@ +fun usage(arr: IntArray) { + val array: IntArray + for (i in array.indices) { + println(array[i]) + } +} + diff --git a/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt b/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt new file mode 100644 index 00000000000..b22eea3f0a3 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt @@ -0,0 +1,14 @@ +import java.util.LinkedHashSet + +class A { + fun bar(root: List, list: LinkedHashSet>) { + addIfNotNull(root, list) + } + + private fun addIfNotNull(element: T, result: Collection) { + nested(result, element) + } + + + private fun nested(result: Collection, element: S) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt.after new file mode 100644 index 00000000000..5d3577b3a49 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt.after @@ -0,0 +1,10 @@ +import java.util.LinkedHashSet + +class A { + fun bar(root: List, list: LinkedHashSet>) { + nested(list, root) + } + + + private fun nested(result: Collection, element: S) {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt b/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt new file mode 100644 index 00000000000..07f1a76e6b6 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt @@ -0,0 +1,19 @@ +class C { + fun doSomething() { + val it = getSomeObjects().iterator() + while (it.hasNext()) { + println("text = " + it.next()) + } + } + + private fun getSomeObjects(): Collection { + val text = "hello" + return getSomeObjects(text) + } + + private fun getSomeObjects(text: String): Collection { + val list = arrayListOf() + list.add(text) + return list + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt.after new file mode 100644 index 00000000000..38eb533de9a --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt.after @@ -0,0 +1,15 @@ +class C { + fun doSomething() { + val text = "hello" + val it = getSomeObjects(text).iterator() + while (it.hasNext()) { + println("text = " + it.next()) + } + } + + private fun getSomeObjects(text: String): Collection { + val list = arrayListOf() + list.add(text) + return list + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt b/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt new file mode 100644 index 00000000000..3d2a6b8e1e6 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt @@ -0,0 +1,17 @@ +class Foo { + fun getComponent(i: Int?): String? { + return null + } + + var myI: Int? = null + + fun usage() { + if (myI != null) + method(myI) + } + + fun method(i: Int?) { + println(getComponent(myI)!! + getComponent(i)!!) + } + +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt.after new file mode 100644 index 00000000000..14cd476329f --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt.after @@ -0,0 +1,14 @@ +class Foo { + fun getComponent(i: Int?): String? { + return null + } + + var myI: Int? = null + + fun usage() { + if (myI != null) { + println(getComponent(myI)!! + getComponent(myI)!!) + } + } + +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/EnumConstructor.kt b/idea/testData/refactoring/inline/function/fromIntellij/EnumConstructor.kt new file mode 100644 index 00000000000..af1c9a9d554 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/EnumConstructor.kt @@ -0,0 +1,7 @@ +// ERROR: Cannot perform refactoring.\nInline Function is not supported for functions with multiple return statements. + +enum class EnumWithConstructor(s: String, s2: String) { + Test("1"), Rest("2", "b"); + + constructor(s: String): this(s, "") +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt b/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt new file mode 100644 index 00000000000..0da2f8e8dc2 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt @@ -0,0 +1,7 @@ +class A { + val field = foo() + + fun foo(): Int { + return 1 + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt.after new file mode 100644 index 00000000000..37df39b6150 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt.after @@ -0,0 +1,4 @@ +class A { + val field = 1 + +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt b/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt new file mode 100644 index 00000000000..b8f0615c5cf --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt @@ -0,0 +1,13 @@ +fun xxx() { + foo(*arrayOf("aa", "hh")) +} + +fun foo(vararg ss: String) { + bar(*ss) +} + +fun bar(s: String, ss: String) { + +} + +fun bar(vararg ss: String) {} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt.after new file mode 100644 index 00000000000..417e6f7dd63 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt.after @@ -0,0 +1,9 @@ +fun xxx() { + bar("aa", "hh") +} + +fun bar(s: String, ss: String) { + +} + +fun bar(vararg ss: String) {} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt b/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt new file mode 100644 index 00000000000..397c5a82787 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt @@ -0,0 +1,13 @@ +class A { + private val i = 0 + + fun foo() { + i.toString() + } +} + +class B : A() { + fun bar() { + foo() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt.after new file mode 100644 index 00000000000..270ae00c49f --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt.after @@ -0,0 +1,10 @@ +class A { + private val i = 0 + +} + +class B : A() { + fun bar() { + i.toString() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt b/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt new file mode 100644 index 00000000000..9fa6ce0ae5a --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt @@ -0,0 +1,15 @@ +import java.util.* + +object Test { + private fun foo(): List { + return emptyList() + } + + private fun bar(xs: List): List { + return xs + } + + private fun gazonk() { + val ss = bar(Test.foo()) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt.after new file mode 100644 index 00000000000..23d2ea4d344 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt.after @@ -0,0 +1,10 @@ +object Test { + + private fun bar(xs: List): List { + return xs + } + + private fun gazonk() { + val ss = bar(emptyList()) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt b/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt new file mode 100644 index 00000000000..f2d51c5dcbe --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt @@ -0,0 +1,23 @@ +object Foo { + fun foo() { + bar(object : Runnable { + override fun run() { + doRun() + } + + private fun doRun() { + // Woo-hoo + } + }) + } + + fun bar(runnable: Runnable) { + runnable.run() + } +} + +internal object Bar { + @JvmStatic fun main(args: Array) { + Foo.foo() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt.after new file mode 100644 index 00000000000..8eefb877dca --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt.after @@ -0,0 +1,22 @@ +import Foo.bar + +object Foo { + + fun bar(runnable: Runnable) { + runnable.run() + } +} + +internal object Bar { + @JvmStatic fun main(args: Array) { + bar(object : Runnable { + override fun run() { + Foo.doRun() + } + + private fun doRun() { + // Woo-hoo + } + }) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt b/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt new file mode 100644 index 00000000000..2b41054cdc0 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt @@ -0,0 +1,14 @@ +object Foo { + + val bars = arrayOf(Bar.callMe("a", 0, "A", "B", "C"), Bar.callMe("b", 1, "A", "B")) +} + + +class Bar(a: String, nr: Int, vararg args: String) { + companion object { + + fun callMe(a: String, nr: Int, vararg args: String): Bar { + return Bar(a, nr, *args) + } + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt.after new file mode 100644 index 00000000000..8fea7c2fb63 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt.after @@ -0,0 +1,8 @@ +object Foo { + + val bars = arrayOf(Bar("a", 0, "A", "B", "C"), Bar("b", 1, "A", "B")) +} + + +class Bar(a: String, nr: Int, vararg args: String) { +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt new file mode 100644 index 00000000000..4cd16bd390f --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt @@ -0,0 +1,31 @@ +class Element { + var id: String? = null + + fun getName(): String = id + + fun method(element: Element): String { + return getName() + element.getName() + } + + fun staticMethod(element: Element): String { + val buffer = StringBuffer() + buffer.append(element.getName()) + return buffer.toString() + } + + companion object { + fun toXML(element: Element): Element { + val el = X("El") + el.setAttribute("attr", element.getName()) + return el + } + } +} + +class Usage { + fun staticMethod(element: Element): String { + val buffer = StringBuffer() + buffer.append(element.getName()) + return buffer.toString() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt.after new file mode 100644 index 00000000000..4e91ec067cd --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt.after @@ -0,0 +1,29 @@ +class Element { + var id: String? = null + + fun method(element: Element): String { + return id + element.id + } + + fun staticMethod(element: Element): String { + val buffer = StringBuffer() + buffer.append(element.id) + return buffer.toString() + } + + companion object { + fun toXML(element: Element): Element { + val el = X("El") + el.setAttribute("attr", element.id) + return el + } + } +} + +class Usage { + fun staticMethod(element: Element): String { + val buffer = StringBuffer() + buffer.append(element.id) + return buffer.toString() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/InlineWithTry.kt b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithTry.kt new file mode 100644 index 00000000000..0de7deb7e74 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/InlineWithTry.kt @@ -0,0 +1,17 @@ +// ERROR: Cannot perform refactoring.\nInline Function is not supported for functions with return statements not at the end of the body. + +class A { + init { + g() + } + + fun g(): Int { + try { + return 0 + } + catch (e: Error) { + throw e + } + + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt b/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt new file mode 100644 index 00000000000..ae5b9684ea9 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt @@ -0,0 +1,22 @@ +class AAA { + fun fff(myProject: Project) { + ensureFilesWritable(myProject, *Array(1) { "2" }) + } + + private fun ensureFilesWritable(project: Project, vararg strings: String): Boolean { + return !ensureFilesWritable(strings).hasReadonlyFiles() + } + + private fun ensureFilesWritable(strings: Array): Status { + return Status(strings) + } + + inner class Status(strings: Array) { + + fun hasReadonlyFiles(): Boolean { + return true + } + } + + inner class Project +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt.after new file mode 100644 index 00000000000..482938c04c6 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt.after @@ -0,0 +1,18 @@ +class AAA { + fun fff(myProject: Project) { + !ensureFilesWritable(Array(1) { "2" }).hasReadonlyFiles() + } + + private fun ensureFilesWritable(strings: Array): Status { + return Status(strings) + } + + inner class Status(strings: Array) { + + fun hasReadonlyFiles(): Boolean { + return true + } + } + + inner class Project +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt b/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt new file mode 100644 index 00000000000..8bcc268bdc9 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt @@ -0,0 +1,13 @@ +fun foo(fe: Int) { + println(fe) +} + +fun bar(br: Boolean) { + val fe = 0 + if (br) { + foo(fe) + } + else { + foo(11) + } +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt.after new file mode 100644 index 00000000000..3dcb8c0e2d3 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt.after @@ -0,0 +1,9 @@ +fun bar(br: Boolean) { + val fe = 0 + if (br) { + println(fe) + } + else { + println(11) + } +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt b/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt new file mode 100644 index 00000000000..342ab90a6c4 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt @@ -0,0 +1,13 @@ +class Test { + private var s: String? = null + + fun method(): String { + s = "Hello" + return s + } + + fun test() { + println(method()) + println(s) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt.after new file mode 100644 index 00000000000..06375d9d3f6 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt.after @@ -0,0 +1,9 @@ +class Test { + private var s: String? = null + + fun test() { + s = "Hello" + println(s) + println(s) + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt b/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt new file mode 100644 index 00000000000..16be33bafcb --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt @@ -0,0 +1,39 @@ +class Foo { + + fun method(b: Boolean, + elementComputable: Computable, + processingContext: Any): WeighingComparable { + return weigh(WEIGHER_KEY, elementComputable, ProximityLocation()) + } + + companion object { + fun weigh( + key: Key>?, element: Computable, location: Loc + ): WeighingComparable { + return WeighingComparable(element, location, Array>(0) { null!! }) + } + + val WEIGHER_KEY: Key? = null + } +} + +abstract class ProximityWeigher : Weigher() + +class ProximityLocation + +class Key

+ +open class Weigher + +class Computable + +class WeighingComparable(element: Computable, location: Loc, weighers: Array>) : Comparable> { + + override fun compareTo(other: WeighingComparable): Int { + return 0 + } + + private fun getWeight(index: Int): Comparable<*>? { + return null + } +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt.after new file mode 100644 index 00000000000..05186b22430 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt.after @@ -0,0 +1,34 @@ +class Foo { + + fun method(b: Boolean, + elementComputable: Computable, + processingContext: Any): WeighingComparable { + return WeighingComparable(elementComputable, ProximityLocation(), Array>(0) { null!! }) + } + + companion object { + + val WEIGHER_KEY: Key? = null + } +} + +abstract class ProximityWeigher : Weigher() + +class ProximityLocation + +class Key

+ +open class Weigher + +class Computable + +class WeighingComparable(element: Computable, location: Loc, weighers: Array>) : Comparable> { + + override fun compareTo(other: WeighingComparable): Int { + return 0 + } + + private fun getWeight(index: Int): Comparable<*>? { + return null + } +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt b/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt new file mode 100644 index 00000000000..ad2a374ecd9 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt @@ -0,0 +1,8 @@ +fun method() { + otherMethod() + println("Here") +} + +fun otherMethod() { + return +} diff --git a/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt.after new file mode 100644 index 00000000000..f8a9dac5213 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt.after @@ -0,0 +1,4 @@ +fun method() { + println("Here") +} + diff --git a/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt b/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt new file mode 100644 index 00000000000..73d9c8801d7 --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt @@ -0,0 +1,17 @@ +class Usage { + fun foo() { + bar() + } + + fun bar() { + object : W() { + override fun www() { + super.www() + } + } + } +} + +class W { + protected fun www() {} +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt.after b/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt.after new file mode 100644 index 00000000000..f23d0e99bfe --- /dev/null +++ b/idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt.after @@ -0,0 +1,14 @@ +class Usage { + fun foo() { + object : W() { + override fun www() { + super.www() + } + } + } + +} + +class W { + protected fun www() {} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java index f22b8a1edf6..f319d2bf5e9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java @@ -173,6 +173,129 @@ public class InlineTestGenerated extends AbstractInlineTest { } } + @TestMetadata("idea/testData/refactoring/inline/function/fromIntellij") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FromIntellij extends AbstractInlineTest { + public void testAllFilesPresentInFromIntellij() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/refactoring/inline/function/fromIntellij"), Pattern.compile("^(\\w+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("ArrayAccess.kt") + public void testArrayAccess() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/ArrayAccess.kt"); + doTest(fileName); + } + + @TestMetadata("AvoidMultipleSubstitutionsInParameterTypes.kt") + public void testAvoidMultipleSubstitutionsInParameterTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/AvoidMultipleSubstitutionsInParameterTypes.kt"); + doTest(fileName); + } + + @TestMetadata("CallInFor.kt") + public void testCallInFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/CallInFor.kt"); + doTest(fileName); + } + + @TestMetadata("CallUnderIf.kt") + public void testCallUnderIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/CallUnderIf.kt"); + doTest(fileName); + } + + @TestMetadata("EnumConstructor.kt") + public void testEnumConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/EnumConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("FieldInitializer.kt") + public void testFieldInitializer() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/FieldInitializer.kt"); + doTest(fileName); + } + + @TestMetadata("FlatVarargs.kt") + public void testFlatVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/FlatVarargs.kt"); + doTest(fileName); + } + + @TestMetadata("InaccessibleFieldInSuperclass.kt") + public void testInaccessibleFieldInSuperclass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InaccessibleFieldInSuperclass.kt"); + doTest(fileName); + } + + @TestMetadata("InferredType.kt") + public void testInferredType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InferredType.kt"); + doTest(fileName); + } + + @TestMetadata("InlineAnonymousClassWithPrivateMethod.kt") + public void testInlineAnonymousClassWithPrivateMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InlineAnonymousClassWithPrivateMethod.kt"); + doTest(fileName); + } + + @TestMetadata("InlineMultipleOccurrencesInFieldInitializer.kt") + public void testInlineMultipleOccurrencesInFieldInitializer() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InlineMultipleOccurrencesInFieldInitializer.kt"); + doTest(fileName); + } + + @TestMetadata("InlineWithQualifier.kt") + public void testInlineWithQualifier() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InlineWithQualifier.kt"); + doTest(fileName); + } + + @TestMetadata("InlineWithTry.kt") + public void testInlineWithTry() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/InlineWithTry.kt"); + doTest(fileName); + } + + @TestMetadata("NotAStatement.kt") + public void testNotAStatement() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/NotAStatement.kt"); + doTest(fileName); + } + + @TestMetadata("ParamNameConflictsWithLocalVar.kt") + public void testParamNameConflictsWithLocalVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/ParamNameConflictsWithLocalVar.kt"); + doTest(fileName); + } + + @TestMetadata("SideEffect.kt") + public void testSideEffect() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/SideEffect.kt"); + doTest(fileName); + } + + @TestMetadata("Substitution.kt") + public void testSubstitution() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/Substitution.kt"); + doTest(fileName); + } + + @TestMetadata("VoidWithReturn.kt") + public void testVoidWithReturn() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/VoidWithReturn.kt"); + doTest(fileName); + } + + @TestMetadata("WithSuperInside.kt") + public void testWithSuperInside() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/fromIntellij/WithSuperInside.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/refactoring/inline/function/returnAtEnd") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)