Introduce Variable: Forbid inside of type references and 'super' references
#KT-8324 Fixed
This commit is contained in:
+7
@@ -130,6 +130,13 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
if (PsiTreeUtil.getNonStrictParentOfType(expression,
|
||||||
|
JetTypeReference.class, JetConstructorCalleeExpression.class, JetSuperExpression.class) != null) {
|
||||||
|
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.no.container"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(expression);
|
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(expression);
|
||||||
final BindingContext bindingContext = analysisResult.getBindingContext();
|
final BindingContext bindingContext = analysisResult.getBindingContext();
|
||||||
final JetType expressionType = bindingContext.getType(expression); //can be null or error type
|
final JetType expressionType = bindingContext.getType(expression); //can be null or error type
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
open class A(n: Int)
|
||||||
|
|
||||||
|
class B {
|
||||||
|
constructor(x: Int) : <selection>A</selection>(x + 1)
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Cannot refactor in this place
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
interface T
|
||||||
|
|
||||||
|
object O : T
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val x = object : T by <selection>O</selection> {}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
interface T
|
||||||
|
|
||||||
|
object O : T
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val o = O
|
||||||
|
val x = object : T by o {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
interface T
|
||||||
|
|
||||||
|
object O : T
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val x = object : <selection>T</selection> by O {}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Cannot refactor in this place
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
open class A(n: Int)
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val x = object : A(<selection>1</selection>) {}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
open class A(n: Int)
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val i = 1
|
||||||
|
val x = object : A(i) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
val x = object : <selection>Any</selection>() {}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Cannot refactor in this place
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
interface T
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val x = object : <selection>T</selection> {}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Cannot refactor in this place
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
open class A {
|
||||||
|
open fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
override fun foo() {
|
||||||
|
<selection>super</selection>.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Cannot refactor in this place
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class A {
|
||||||
|
fun bar() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
<selection>this</selection>.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class A {
|
||||||
|
fun bar() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val a = this
|
||||||
|
a.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -61,6 +61,42 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
|||||||
doIntroduceVariableTest(fileName);
|
doIntroduceVariableTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ConstructorDelegationCall.kt")
|
||||||
|
public void testConstructorDelegationCall() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ConstructorDelegationCall.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatorByExpressionInDelegate.kt")
|
||||||
|
public void testDelegatorByExpressionInDelegate() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DelegatorByExpressionInDelegate.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatorByExpressionInType.kt")
|
||||||
|
public void testDelegatorByExpressionInType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DelegatorByExpressionInType.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatorToSuperCallInArgument.kt")
|
||||||
|
public void testDelegatorToSuperCallInArgument() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DelegatorToSuperCallInArgument.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatorToSuperCallInType.kt")
|
||||||
|
public void testDelegatorToSuperCallInType() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DelegatorToSuperCallInType.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatorToSuperClass.kt")
|
||||||
|
public void testDelegatorToSuperClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DelegatorToSuperClass.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("DoWhileAddBlock.kt")
|
@TestMetadata("DoWhileAddBlock.kt")
|
||||||
public void testDoWhileAddBlock() throws Exception {
|
public void testDoWhileAddBlock() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DoWhileAddBlock.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DoWhileAddBlock.kt");
|
||||||
@@ -295,6 +331,18 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
|||||||
doIntroduceVariableTest(fileName);
|
doIntroduceVariableTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("SuperReference.kt")
|
||||||
|
public void testSuperReference() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/SuperReference.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ThisReference.kt")
|
||||||
|
public void testThisReference() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ThisReference.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("TwoExplicitReceivers.kt")
|
@TestMetadata("TwoExplicitReceivers.kt")
|
||||||
public void testTwoExplicitReceivers() throws Exception {
|
public void testTwoExplicitReceivers() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/TwoExplicitReceivers.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/TwoExplicitReceivers.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user