mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Partial body resolve works for local Nothing functions + does not go inside local functions and classes
GitOrigin-RevId: 67eb537056424ca0358fda618f037d943ac7e4f5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
21b4cfeb01
commit
55e48c09f1
@@ -99,7 +99,6 @@ public class ResolveElementCache extends ElementResolver {
|
||||
set.addAll(hardcodedNames);
|
||||
set.addAll(indexedNames);
|
||||
return set;
|
||||
//TODO: what about local declarations?
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+24
-6
@@ -26,6 +26,9 @@ import java.util.HashMap
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isProbablyNothing
|
||||
|
||||
//TODO: do resolve anonymous object's body
|
||||
|
||||
class PartialBodyResolveFilter(
|
||||
elementToResolve: JetElement,
|
||||
@@ -35,12 +38,27 @@ class PartialBodyResolveFilter(
|
||||
|
||||
private val statementsToResolve = HashSet<JetExpression>()
|
||||
private val processedBlocks = HashSet<JetBlockExpression>()
|
||||
private val nothingFunctionNames = probablyNothingCallableNamesService.functionNames()
|
||||
|
||||
private val nothingFunctionNames = HashSet(probablyNothingCallableNamesService.functionNames())
|
||||
private val nothingPropertyNames = probablyNothingCallableNamesService.propertyNames()
|
||||
|
||||
;{
|
||||
assert(body.isAncestor(elementToResolve, strict = false))
|
||||
|
||||
body.accept(object : JetVisitorVoid(){
|
||||
override fun visitNamedFunction(function: JetNamedFunction) {
|
||||
super.visitNamedFunction(function)
|
||||
|
||||
if (function.getTypeReference().isProbablyNothing()) {
|
||||
nothingFunctionNames.add(function.getName())
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitElement(element: PsiElement) {
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
})
|
||||
|
||||
addStatementsToResolve(elementToResolve)
|
||||
}
|
||||
|
||||
@@ -54,8 +72,7 @@ class PartialBodyResolveFilter(
|
||||
|
||||
private fun addStatementsToResolve(element: JetElement) {
|
||||
if (element == body) return
|
||||
val parent = element.getParent() as? JetElement
|
||||
?: return
|
||||
val parent = element.getParent() as? JetElement ?: return
|
||||
|
||||
if (parent is JetBlockExpression) {
|
||||
processBlock(parent)
|
||||
@@ -67,6 +84,7 @@ class PartialBodyResolveFilter(
|
||||
|
||||
for (statement in element.siblings(forward = false, withItself = false)) {
|
||||
if (statement !is JetExpression) continue
|
||||
if (statement is JetClassBody) continue
|
||||
|
||||
val smartCastPlaces = potentialSmartCastPlaces(statement)
|
||||
if (!smartCastPlaces.isEmpty()) {
|
||||
@@ -312,15 +330,15 @@ class PartialBodyResolveFilter(
|
||||
return result
|
||||
}
|
||||
|
||||
private abstract class ControlFlowVisitor : JetVisitorVoid() {
|
||||
private inner abstract class ControlFlowVisitor : JetVisitorVoid() {
|
||||
override fun visitJetElement(element: JetElement) {
|
||||
if (element.noControlFlowInside()) return
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
private fun JetElement.noControlFlowInside() = this is JetFunction || this is JetClass || this is JetClassBody
|
||||
}
|
||||
|
||||
private fun JetElement.noControlFlowInside() = this is JetFunction || this is JetClass || this is JetClassBody
|
||||
|
||||
private fun MutableSet<JetExpression>.addStatementsForPlaces(thisStatement: JetExpression, places: Collection<JetExpression>) {
|
||||
@PlacesLoop
|
||||
for (place in places) {
|
||||
|
||||
+24
-1
@@ -19,7 +19,6 @@ package org.jetbrains.jet.resolve;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -36,6 +35,12 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/resolve/partialBodyResolve"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousObjects.kt")
|
||||
public void testAnonymousObjects() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/AnonymousObjects.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("As.kt")
|
||||
public void testAs() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/As.kt");
|
||||
@@ -234,6 +239,24 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalClass.kt")
|
||||
public void testLocalClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/LocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalFun.kt")
|
||||
public void testLocalFun() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/LocalFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalNothingFun.kt")
|
||||
public void testLocalNothingFun() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/LocalNothingFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/Simple.kt");
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
@@ -0,0 +1,22 @@
|
||||
open class C(p: Int) {
|
||||
open fun f(){}
|
||||
}
|
||||
|
||||
fun foo(p: String?) {
|
||||
val o = object : Runnable {
|
||||
override fun run() {
|
||||
if (p == null) return
|
||||
print(p.size)
|
||||
}
|
||||
}
|
||||
|
||||
val c = object : C(p!!.size) {
|
||||
override fun f() {
|
||||
super.f()
|
||||
if (p == null) return
|
||||
print(p.size)
|
||||
}
|
||||
}
|
||||
|
||||
<caret>p?.size
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(p: String?) {
|
||||
class LocalClass {
|
||||
fun f(): String? {
|
||||
if (p == null) return null
|
||||
print(p.size)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
<caret>p?.size
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
Resolve target: value-parameter val p: kotlin.String?
|
||||
Skipped statements:
|
||||
if (p == null) return null
|
||||
print(p.size)
|
||||
return ""
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(p: String?) {
|
||||
fun local(): String? {
|
||||
if (p == null) return null
|
||||
print(p.size)
|
||||
return ""
|
||||
}
|
||||
|
||||
<caret>p?.size
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Resolve target: value-parameter val p: kotlin.String? smart-casted to kotlin.String
|
||||
Skipped statements:
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(p: String?, p1: Any?) {
|
||||
if (p1 == null) return
|
||||
|
||||
fun localError(): Nothing = throw Exception()
|
||||
|
||||
if (p == null) {
|
||||
localError()
|
||||
}
|
||||
<caret>p.size
|
||||
}
|
||||
Reference in New Issue
Block a user