Create function quick fix: fix visibility from inline method #KT-25228 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-07-30 11:02:18 +09:00
committed by Alexey Sedunov
parent e2945b1d12
commit dc57887a4d
10 changed files with 95 additions and 1 deletions
@@ -275,7 +275,17 @@ sealed class CreateCallableFromCallActionFactory<E : KtExpression>(
} else {
TypeInfo(fullCallExpression, Variance.OUT_VARIANCE)
}
return FunctionInfo(name, receiverType, returnType, possibleContainers, parameters, typeParameters)
val parentFunction = expression.getStrictParentOfType<KtNamedFunction>()
val modifierList = if (parentFunction?.hasModifier(KtTokens.INLINE_KEYWORD) == true) {
when {
parentFunction.isPublic -> KtPsiFactory(expression).createModifierList(KtTokens.PUBLIC_KEYWORD)
parentFunction.isProtected() -> KtPsiFactory(expression).createModifierList(KtTokens.PROTECTED_KEYWORD)
else -> null
}
} else {
null
}
return FunctionInfo(name, receiverType, returnType, possibleContainers, parameters, typeParameters, modifierList = modifierList)
}
object Default : Function()
@@ -0,0 +1,6 @@
// "Create function 'g'" "true"
class C {
internal inline fun f() {
<caret>g()
}
}
@@ -0,0 +1,10 @@
// "Create function 'g'" "true"
class C {
internal inline fun f() {
g()
}
private fun g() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -0,0 +1,6 @@
// "Create function 'g'" "true"
class C {
private inline fun f() {
<caret>g()
}
}
@@ -0,0 +1,10 @@
// "Create function 'g'" "true"
class C {
private inline fun f() {
g()
}
private fun g() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -0,0 +1,6 @@
// "Create function 'g'" "true"
class C {
protected inline fun f() {
<caret>g()
}
}
@@ -0,0 +1,10 @@
// "Create function 'g'" "true"
class C {
protected inline fun f() {
g()
}
protected fun g() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -0,0 +1,6 @@
// "Create function 'g'" "true"
class C {
inline fun f() {
<caret>g()
}
}
@@ -0,0 +1,10 @@
// "Create function 'g'" "true"
class C {
inline fun f() {
g()
}
fun g() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -3101,6 +3101,26 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funExtraArgs.kt");
}
@TestMetadata("funInInlineInternalFun.kt")
public void testFunInInlineInternalFun() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funInInlineInternalFun.kt");
}
@TestMetadata("funInInlinePrivateFun.kt")
public void testFunInInlinePrivateFun() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funInInlinePrivateFun.kt");
}
@TestMetadata("funInInlineProtectedFun.kt")
public void testFunInInlineProtectedFun() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funInInlineProtectedFun.kt");
}
@TestMetadata("funInInlinePublicFun.kt")
public void testFunInInlinePublicFun() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funInInlinePublicFun.kt");
}
@TestMetadata("funMissingArgs.kt")
public void testFunMissingArgs() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funMissingArgs.kt");