Partial body resolve: more efficient handling of while
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.jet.utils.addIfNotNull
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
|
||||
class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: JetExpression) : (JetElement) -> Boolean {
|
||||
|
||||
@@ -167,6 +168,18 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J
|
||||
expression.getLoopRange()?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(expression: JetWhileExpression) {
|
||||
val condition = expression.getCondition()
|
||||
// we need to enter the body only for "while(true)"
|
||||
//TODO: what about e.g. "1 == 1"
|
||||
if (condition.isTrueConstant()) {
|
||||
expression.acceptChildren(this)
|
||||
}
|
||||
else {
|
||||
condition?.accept(this)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: when
|
||||
})
|
||||
|
||||
@@ -260,6 +273,9 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J
|
||||
|
||||
// private fun JetExpression?.isNullLiteral() = this?.getNode()?.getElementType() == JetNodeTypes.NULL
|
||||
|
||||
private fun JetExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == JetNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
|
||||
//TODO: review logic
|
||||
private fun isValueNeeded(expression: JetExpression): Boolean {
|
||||
val parent = expression.getParent()
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.Any
|
||||
Skipped statements:
|
||||
print(p1!!)
|
||||
@@ -0,0 +1,9 @@
|
||||
fun x(s: Any): Boolean{}
|
||||
|
||||
fun foo(p: Any?, p1: Any?) {
|
||||
while(x(p!!)) {
|
||||
print(p1!!)
|
||||
}
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Resolve target: value-parameter val p: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x()) break
|
||||
@@ -0,0 +1,10 @@
|
||||
fun x(): Boolean{}
|
||||
|
||||
fun foo(p: Any?) {
|
||||
while(true) {
|
||||
print(p!!)
|
||||
if (x()) break
|
||||
}
|
||||
|
||||
<caret>p.hashCode()
|
||||
}
|
||||
@@ -167,4 +167,16 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/Simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("While.kt")
|
||||
public void testWhile() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/While.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WhileTrue.kt")
|
||||
public void testWhileTrue() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/WhileTrue.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user