Extract Function: Do not suggest "unit" as function name

#KT-6402 Fixed
This commit is contained in:
Alexey Sedunov
2014-12-26 15:51:52 +03:00
parent 64ddd52e60
commit 86d5bd9365
38 changed files with 79 additions and 79 deletions
@@ -731,7 +731,8 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
)
controlFlowMessage?.let { messages.add(it) }
controlFlow.outputValueBoxer.returnType.processTypeIfExtractable(paramsInfo.typeParameters, paramsInfo.nonDenotableTypes)
val returnType = controlFlow.outputValueBoxer.returnType
returnType.processTypeIfExtractable(paramsInfo.typeParameters, paramsInfo.nonDenotableTypes)
if (paramsInfo.nonDenotableTypes.isNotEmpty()) {
val typeStr = paramsInfo.nonDenotableTypes.map {it.renderForMessage()}.sort()
@@ -751,10 +752,9 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
if (targetSibling is JetClassInitializer) targetSibling.getParent() else targetSibling,
JetNameValidatorImpl.Target.FUNCTIONS_AND_CLASSES
)
val functionName = JetNameSuggester.suggestNames(
controlFlow.outputValueBoxer.returnType,
functionNameValidator, DEFAULT_FUNCTION_NAME
).first()
val functionName = if (returnType.isDefault()) "" else {
JetNameSuggester.suggestNames(returnType, functionNameValidator, DEFAULT_FUNCTION_NAME).first()
}
controlFlow.jumpOutputValue?.elementToInsertAfterCall?.accept(
object : JetTreeVisitorVoid() {
@@ -81,7 +81,7 @@ fun ExtractableCodeDescriptor.getDeclarationText(
receiverParameter?.let { builder.receiver(descriptorRenderer.renderType(it.parameterType)) }
builder.name(name)
builder.name(if (name != "") name else DEFAULT_FUNCTION_NAME)
parameters.forEach { parameter ->
builder.param(parameter.name, descriptorRenderer.renderType(parameter.parameterType))
@@ -2,9 +2,9 @@
// PARAM_DESCRIPTOR: internal fun <T> kotlin.Array<T>.test(): kotlin.Unit defined in root package
// SIBLING:
fun <T> Array<T>.test() {
unit()
__dummyTestFun__()
}
private fun <T> Array<T>.unit() {
private fun <T> Array<T>.__dummyTestFun__() {
this.isEmpty()
}
}
@@ -6,13 +6,13 @@
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
__dummyTestFun__(a, b)
break
}
return 1
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a + b > 0) return
println(a - b)
return
@@ -6,13 +6,13 @@
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
__dummyTestFun__(a, b)
break
}
return 1
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a + b > 0) return
else {
println(a - b)
@@ -6,13 +6,13 @@
fun foo(a: Int): Int {
val b: Int = 1
for (n in 1..a) {
unit(a, b)
__dummyTestFun__(a, b)
break
}
return 1
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
when {
a + b > 0 -> return
a - b > 0 -> return
@@ -7,10 +7,10 @@
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
__dummyTestFun__(a, b)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a > 0) {
println(a)
}
@@ -8,13 +8,13 @@ fun foo(a: Int) {
val b: Int = 1
val c: Int
unit(a, b)
__dummyTestFun__(a, b)
c = 1
println(c)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a > 0) {
println(a)
}
@@ -4,10 +4,10 @@
fun foo(a: Int) {
val b: Int = 1
unit(a)
__dummyTestFun__(a)
}
private fun unit(a: Int) {
private fun __dummyTestFun__(a: Int) {
var t = a
while (t > 0) {
if (t == 2) continue
@@ -11,11 +11,11 @@ fun bar(a: Int): Int {
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
__dummyTestFun__(a, b)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a > 0) {
bar(a)
} else {
@@ -11,9 +11,9 @@ fun bar(a: Int): Int {
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
__dummyTestFun__(a, b)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
if (a > 0) bar(a) else b
}
@@ -11,11 +11,11 @@ fun bar(a: Int): Int {
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
__dummyTestFun__(a, b)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
when {
a > 0 -> {
bar(a)
@@ -11,11 +11,11 @@ fun bar(a: Int): Int {
fun foo(a: Int) {
val b: Int = 1
unit(a, b)
__dummyTestFun__(a, b)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
when {
a > 0 -> bar(a)
else -> b
@@ -2,10 +2,10 @@ class T(val n: Int)
// SIBLING:
fun foo() {
unit()
__dummyTestFun__()
}
private fun unit() {
private fun __dummyTestFun__() {
bar { t ->
val k = 1
t.n + k + 1
@@ -2,10 +2,10 @@ class T(val n: Int)
// SIBLING:
fun foo() {
unit()
__dummyTestFun__()
}
private fun unit() {
private fun __dummyTestFun__() {
if (true) {
val k = 1
T().n + k + 1
@@ -5,17 +5,17 @@
// SIBLING:
fun foo(a: Int, b: Int) {
unit(a, b)
__dummyTestFun__(a, b)
}
fun bar() {
val x = 1
val y = 2
unit(x, y)
__dummyTestFun__(x, y)
}
private fun unit(a: Int, b: Int) {
private fun __dummyTestFun__(a: Int, b: Int) {
println("a = $a")
println("b = $b")
println(a + b * a)
@@ -3,13 +3,13 @@
fun foo() {
val (a, b) =
if (true) {
unit()
__dummyTestFun__()
1 to 2
} else {
2 to 3
}
}
private fun unit() {
private fun __dummyTestFun__() {
1 + 1
}
@@ -5,10 +5,10 @@
// SIBLING:
val x = object {
fun test() {
unit()
__dummyTestFun__()
}
}
private fun Any.unit() {
private fun Any.__dummyTestFun__() {
println(this)
}
@@ -13,9 +13,9 @@ fun foo(a: A) {
// SIBLING:
fun test() {
val x = object: A() { }
unit(x)
__dummyTestFun__(x)
}
private fun unit(x: A) {
private fun __dummyTestFun__(x: A) {
foo(x)
}
@@ -11,10 +11,10 @@ class X<T> {
// SIBLING:
fun foo(s: String?, x: X<Any>) {
when {
s != null -> unit(s, x)
s != null -> __dummyTestFun__(s, x)
}
}
private fun unit(s: String, x: X<Any>) {
private fun __dummyTestFun__(s: String, x: X<Any>) {
x.add(s)
}
@@ -11,10 +11,10 @@ class X<T> {
// SIBLING:
fun foo(s: String?, x: X<Any?>) {
when {
s != null -> unit(s, x)
s != null -> __dummyTestFun__(s, x)
}
}
private fun unit(s: String?, x: X<Any?>) {
private fun __dummyTestFun__(s: String?, x: X<Any?>) {
x.add(s)
}
@@ -30,11 +30,11 @@ class C: AImpl(), B {
// SIBLING:
fun foo(c: C) {
unit(c)
__dummyTestFun__(c)
c.doB()
c.doC()
}
private fun unit(c: C) {
private fun __dummyTestFun__(c: C) {
c.doA()
}
@@ -31,10 +31,10 @@ class C: AImpl(), B {
// SIBLING:
fun foo(c: C) {
c.doA()
unit(c)
__dummyTestFun__(c)
c.doC()
}
private fun unit(c: C) {
private fun __dummyTestFun__(c: C) {
c.doB()
}
@@ -32,9 +32,9 @@ class C: AImpl(), B {
fun foo(c: C) {
c.doA()
c.doB()
unit(c)
__dummyTestFun__(c)
}
private fun unit(c: C) {
private fun __dummyTestFun__(c: C) {
c.doC()
}
@@ -30,11 +30,11 @@ class C: AImpl(), B {
// SIBLING:
fun foo(c: C) {
unit(c)
__dummyTestFun__(c)
c.doC()
}
private fun unit(c: C) {
private fun __dummyTestFun__(c: C) {
c.doA()
c.doB()
}
@@ -3,10 +3,10 @@
// SIBLING:
fun main(args: Array<String>) {
val (a, b) = Data(1, 2)
unit(a)
__dummyTestFun__(a)
}
private fun unit(a: Int) {
private fun __dummyTestFun__(a: Int) {
a
}
@@ -1,13 +1,13 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public annotation class P
}
private fun unit() {
private fun __dummyTestFun__() {
[MyClass.P] val t: Int = 1
t
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public class P {
@@ -12,7 +12,7 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
MyClass.P.foo()
MyClass.P.a
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
enum class P {
@@ -12,7 +12,7 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
MyClass.P.A.foo()
MyClass.P.A.a
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
object P {
@@ -10,7 +10,7 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
MyClass.P.foo()
MyClass.P.a
}
@@ -6,11 +6,11 @@ fun foo() = 1
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
}
private fun unit() {
private fun __dummyTestFun__() {
foo()
a
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public class P<T> {
@@ -11,6 +11,6 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
val t: MyClass.P<MyClass.P.Q>? = null
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public class P<T> {
@@ -15,7 +15,7 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
val a: Any = MyClass.P.Q()
val t = MyClass.P.R<MyClass.P.Q>(a as MyClass.P.Q)
}
@@ -1,7 +1,7 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public class P {
@@ -11,7 +11,7 @@ class MyClass {
}
}
private fun unit() {
private fun __dummyTestFun__() {
val t: MyClass.P.Q = MyClass.P.Q()
t
}
@@ -4,10 +4,10 @@ package p
object O {
val a = 1
fun test() {
unit()
__dummyTestFun__()
}
}
private fun unit() {
private fun __dummyTestFun__() {
O.a
}
@@ -1,13 +1,13 @@
// SIBLING:
class MyClass {
fun test() {
unit()
__dummyTestFun__()
}
public class P
}
private fun unit() {
private fun __dummyTestFun__() {
val t: MyClass.P = MyClass.P()
t
}
@@ -6,9 +6,9 @@ class A {
// SIBLING:
fun testProp() {
val foo = A()
unit(foo)
__dummyTestFun__(foo)
}
private fun unit(foo: A) {
private fun __dummyTestFun__(foo: A) {
foo()
}
@@ -125,7 +125,7 @@ public abstract class AbstractJetExtractionTest() : JetLightCodeInsightFixtureTe
assertEquals(expectedDescriptors, actualDescriptors, "Expected descriptors mismatch.")
assertEquals(expectedTypes, actualTypes, "Expected types mismatch.")
return descriptor
return if (descriptor.name == "") descriptor.copy(name = "__dummyTestFun__") else descriptor
}
}
).doInvoke(editor, file, elements, explicitPreviousSibling ?: previousSibling)