Extract Function: Check for INVISIBLE_* errors during validation phase
#KT-4995 Fixed
This commit is contained in:
@@ -605,6 +605,8 @@ public interface Errors {
|
||||
// Error sets
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> UNRESOLVED_REFERENCE_DIAGNOSTICS = ImmutableSet.of(
|
||||
UNRESOLVED_REFERENCE, NAMED_PARAMETER_NOT_FOUND, UNRESOLVED_REFERENCE_WRONG_RECEIVER);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> INVISIBLE_REFERENCE_DIAGNOSTICS = ImmutableSet.of(
|
||||
INVISIBLE_MEMBER, INVISIBLE_MEMBER_FROM_INLINE, INVISIBLE_REFERENCE, INVISIBLE_SETTER);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of(
|
||||
UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> TYPE_INFERENCE_ERRORS = ImmutableSet.of(
|
||||
|
||||
@@ -38,5 +38,6 @@ package.private.0.will.no.longer.be.accessible.from.1=Package-private {0} will n
|
||||
0.uses.package.private.1={0} uses package-private {1}
|
||||
0.will.no.longer.be.accessible.after.extraction={0} will no longer be accessible after extraction
|
||||
0.will.become.invisible.after.extraction={0} will become invisible after extraction
|
||||
setter.of.0.will.become.invisible.after.extraction = Setter of {0} will become invisible after extraction
|
||||
|
||||
naming.convention.will.be.violated.after.rename=Naming conventions will be violated after rename
|
||||
+12
-4
@@ -721,14 +721,22 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
|
||||
continue
|
||||
}
|
||||
|
||||
diagnostics.firstOrNull { it.getFactory() == Errors.INVISIBLE_MEMBER }?.let {
|
||||
conflicts.putValue(
|
||||
resolveResult.originalRefExpr,
|
||||
diagnostics.firstOrNull { it.getFactory() in Errors.INVISIBLE_REFERENCE_DIAGNOSTICS }?.let {
|
||||
val message = when (it.getFactory()) {
|
||||
Errors.INVISIBLE_SETTER ->
|
||||
JetRefactoringBundle.message(
|
||||
"setter.of.0.will.become.invisible.after.extraction",
|
||||
RefactoringUIUtil.getDescription(resolveResult.declaration, true)
|
||||
)
|
||||
|
||||
else ->
|
||||
JetRefactoringBundle.message(
|
||||
"0.will.become.invisible.after.extraction",
|
||||
RefactoringUIUtil.getDescription(resolveResult.declaration, true).capitalize()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
conflicts.putValue(resolveResult.originalRefExpr, message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// SIBLING:
|
||||
public class A {
|
||||
class object {
|
||||
private val t: Int = 1
|
||||
}
|
||||
fun f() {
|
||||
<selection>t</selection>
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Property A.t will become invisible after extraction
|
||||
@@ -0,0 +1,7 @@
|
||||
// SIBLING:
|
||||
public class A {
|
||||
private class B
|
||||
fun f() {
|
||||
<selection>val b: A.B</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Class A.B will become invisible after extraction
|
||||
@@ -0,0 +1,9 @@
|
||||
// SIBLING:
|
||||
class A {
|
||||
var t = 1
|
||||
private set
|
||||
|
||||
fun test() {
|
||||
<selection>t = 5</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Setter of property A.t will become invisible after extraction
|
||||
+15
@@ -288,11 +288,26 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/noConflictWithInnerFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privateMemberInClassObject.kt")
|
||||
public void testPrivateMemberInClassObject() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/privateMemberInClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privateMemberRef.kt")
|
||||
public void testPrivateMemberRef() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/privateMemberRef.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privateNestedClass.kt")
|
||||
public void testPrivateNestedClass() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/privateNestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privateSetter.kt")
|
||||
public void testPrivateSetter() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/privateSetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refInReturn.kt")
|
||||
public void testRefInReturn() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/basic/refInReturn.kt");
|
||||
|
||||
Reference in New Issue
Block a user