Extraction Engine: Assume internal visibility for trait members
This commit is contained in:
+10
-1
@@ -736,6 +736,15 @@ fun ExtractionData.isVisibilityApplicable(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
fun ExtractionData.getDefaultVisibility(): String {
|
||||
if (!isVisibilityApplicable()) return ""
|
||||
|
||||
val parent = targetSibling.getStrictParentOfType<JetDeclaration>()
|
||||
if (parent is JetClass && parent.isTrait()) return ""
|
||||
|
||||
return "private"
|
||||
}
|
||||
|
||||
fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
if (originalElements.isEmpty()) {
|
||||
return AnalysisResult(null, Status.CRITICAL_ERROR, listOf(ErrorMessage.NO_EXPRESSION))
|
||||
@@ -824,7 +833,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
this,
|
||||
bindingContext,
|
||||
functionNames,
|
||||
if (isVisibilityApplicable()) "private" else "",
|
||||
getDefaultVisibility(),
|
||||
adjustedParameters.sortBy { it.name },
|
||||
receiverParameter,
|
||||
paramsInfo.typeParameters.sortBy { it.originalDeclaration.getName()!! },
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
trait T{
|
||||
fun foo(): Int {
|
||||
return <selection>1</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
trait T{
|
||||
fun foo(): Int {
|
||||
return i()
|
||||
}
|
||||
|
||||
fun i(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// EXTRACTION_TARGET: property with getter
|
||||
trait T {
|
||||
private val i: Int
|
||||
val i: Int
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
|
||||
+6
@@ -483,6 +483,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/refInReturn.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("traitFunction.kt")
|
||||
public void testTraitFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/traitFunction.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/refactoring/extractFunction/controlFlow")
|
||||
|
||||
Reference in New Issue
Block a user