Introduce Variable: Forbid inside of type references and 'super' references

#KT-8324 Fixed
This commit is contained in:
Alexey Sedunov
2015-09-02 17:59:40 +03:00
parent fa8fcb53c5
commit d7e79e7f28
18 changed files with 136 additions and 0 deletions
@@ -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);
final BindingContext bindingContext = analysisResult.getBindingContext();
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)
}
@@ -0,0 +1 @@
Cannot refactor in this place
@@ -0,0 +1,7 @@
interface T
object O : T
fun foo() {
val x = object : T by <selection>O</selection> {}
}
@@ -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 {}
}
@@ -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>) {}
}
@@ -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>() {}
}
@@ -0,0 +1 @@
Cannot refactor in this place
@@ -0,0 +1,5 @@
interface T
fun foo() {
val x = object : <selection>T</selection> {}
}
@@ -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()
}
}
@@ -61,6 +61,42 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
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")
public void testDoWhileAddBlock() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/DoWhileAddBlock.kt");
@@ -295,6 +331,18 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
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")
public void testTwoExplicitReceivers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/TwoExplicitReceivers.kt");