PSI Pattern Matching: Fix matching of !!

#KT-6021 Fixed
This commit is contained in:
Alexey Sedunov
2014-10-15 14:08:45 +04:00
parent 6f5a2172ac
commit b18b888161
6 changed files with 59 additions and 0 deletions
@@ -89,6 +89,7 @@ import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier
import org.jetbrains.jet.plugin.refactoring.getContextForContainingDeclarationBody
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
import org.jetbrains.jet.lang.psi.JetOperationReferenceExpression
public trait UnificationResult {
public enum class Status {
@@ -366,6 +367,7 @@ public class JetPsiUnifier(
private fun JetElement.shouldIgnoreResolvedCall(): Boolean {
return when {
this is JetConstantExpression -> true
this is JetOperationReferenceExpression -> getReferencedNameElementType() == JetTokens.EXCLEXCL
this is JetIfExpression -> true
this is JetUnaryExpression -> when (getOperationReference().getReferencedNameElementType()) {
JetTokens.EXCLEXCL, JetTokens.PLUSPLUS, JetTokens.MINUSMINUS -> true
@@ -0,0 +1,12 @@
// PARAM_TYPES: kotlin.String?, kotlin.Comparable<String>?, kotlin.CharSequence?, kotlin.Any?
// PARAM_DESCRIPTOR: val s: kotlin.String? defined in foo
// SIBLING:
fun foo(): Int {
val s: String? = ""
return if (true) {
<selection>s!!.length</selection>
} else {
s!!.length
}
}
@@ -0,0 +1,16 @@
// PARAM_TYPES: kotlin.String?, kotlin.Comparable<String>?, kotlin.CharSequence?, kotlin.Any?
// PARAM_DESCRIPTOR: val s: kotlin.String? defined in foo
// SIBLING:
fun foo(): Int {
val s: String? = ""
return if (true) {
i(s)
} else {
i(s)
}
}
private fun i(s: String?): Int {
return s!!.length
}
@@ -0,0 +1,8 @@
fun foo(): Int {
val s: String? = ""
return if (true) {
<selection>s!!.length</selection>
} else {
s!!.length
}
}
@@ -0,0 +1,9 @@
fun foo(): Int {
val s: String? = ""
val i = s!!.length
return if (true) {
i
} else {
i
}
}
@@ -173,6 +173,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
doIntroduceVariableTest(fileName);
}
@TestMetadata("notNullAssertion.kt")
public void testNotNullAssertion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/notNullAssertion.kt");
doIntroduceVariableTest(fileName);
}
@TestMetadata("OccurrencesInStringTemplate.kt")
public void testOccurrencesInStringTemplate() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/OccurrencesInStringTemplate.kt");
@@ -1091,6 +1097,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
doExtractFunctionTest(fileName);
}
@TestMetadata("notNullAssertion.kt")
public void testNotNullAssertion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/duplicates/notNullAssertion.kt");
doExtractFunctionTest(fileName);
}
@TestMetadata("outputValueAndUnitMatching.kt")
public void testOutputValueAndUnitMatching() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/duplicates/outputValueAndUnitMatching.kt");