Extract Function: Use 'public' visibility for function extracted from public inline
#KT-15228 Fixed
This commit is contained in:
+4
-1
@@ -56,6 +56,7 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
|||||||
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
|
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.util.isResolvableInScope
|
import org.jetbrains.kotlin.idea.util.isResolvableInScope
|
||||||
|
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
@@ -608,7 +609,9 @@ private fun ExtractionData.getLocalInstructions(pseudocode: Pseudocode): List<In
|
|||||||
|
|
||||||
fun ExtractionData.isVisibilityApplicable(): Boolean {
|
fun ExtractionData.isVisibilityApplicable(): Boolean {
|
||||||
val parent = targetSibling.parent
|
val parent = targetSibling.parent
|
||||||
return parent is KtClassBody || (parent is KtFile && !parent.isScript())
|
if (parent !is KtClassBody && (parent !is KtFile || parent.isScript())) return false
|
||||||
|
if (commonParent.parentsWithSelf.any { it is KtNamedFunction && it.hasModifier(KtTokens.INLINE_KEYWORD) && it.isPublic }) return false
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ExtractionData.getDefaultVisibility(): String {
|
fun ExtractionData.getDefaultVisibility(): String {
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in foo, value-parameter b: kotlin.Int defined in foo
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
|
||||||
|
private inline fun foo(a: Int, b: Int, f: (Int) -> Int) = f(<selection>a + b</selection>)
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in foo, value-parameter b: kotlin.Int defined in foo
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
|
||||||
|
private inline fun foo(a: Int, b: Int, f: (Int) -> Int) = f(i(a, b))
|
||||||
|
|
||||||
|
private fun i(a: Int, b: Int) = a + b
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in foo, value-parameter b: kotlin.Int defined in foo
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
|
||||||
|
inline fun foo(a: Int, b: Int, f: (Int) -> Int) = f(<selection>a + b</selection>)
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// PARAM_DESCRIPTOR: value-parameter a: kotlin.Int defined in foo, value-parameter b: kotlin.Int defined in foo
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
// PARAM_TYPES: kotlin.Int
|
||||||
|
|
||||||
|
inline fun foo(a: Int, b: Int, f: (Int) -> Int) = f(i(a, b))
|
||||||
|
|
||||||
|
fun i(a: Int, b: Int) = a + b
|
||||||
+12
@@ -923,6 +923,18 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
|||||||
doExtractFunctionTest(fileName);
|
doExtractFunctionTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extractFromPrivateInlineFun.kt")
|
||||||
|
public void testExtractFromPrivateInlineFun() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/extractFromPrivateInlineFun.kt");
|
||||||
|
doExtractFunctionTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extractFromPublicInlineFun.kt")
|
||||||
|
public void testExtractFromPublicInlineFun() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/extractFromPublicInlineFun.kt");
|
||||||
|
doExtractFunctionTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("extractToEnumClassBody.kt")
|
@TestMetadata("extractToEnumClassBody.kt")
|
||||||
public void testExtractToEnumClassBody() throws Exception {
|
public void testExtractToEnumClassBody() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/extractToEnumClassBody.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/extractToEnumClassBody.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user