Analyze Data Flow to Here: Java super-methods supported

This commit is contained in:
Valentin Kipyatkov
2020-02-09 23:21:01 +02:00
parent cfa1d91aa4
commit b406d85ca3
5 changed files with 36 additions and 20 deletions
@@ -80,25 +80,6 @@ private fun KtDeclaration.processHierarchyUpward(scope: AnalysisScope, processor
.forEach(processor)
}
private fun KtFunction.processCalls(scope: SearchScope, exactFunctionOnly: Boolean, processor: (UsageInfo) -> Unit) {
val options = KotlinFunctionFindUsagesOptions(project).apply {
isSearchForTextOccurrences = false
isSkipImportStatements = true
searchScope = scope.intersectWith(useScope)
}
if (exactFunctionOnly) {
processAllExactUsages(options, processor)
} else {
val descriptor = unsafeResolveToDescriptor() as? CallableMemberDescriptor ?: return
for (superDescriptor in descriptor.getDeepestSuperDeclarations()) {
when (val declaration = superDescriptor.originalSource.getPsi()) {
is KtDeclaration -> declaration.processAllUsages(options, processor)
else -> {} //TODO
}
}
}
}
private enum class AccessKind {
READ_ONLY, WRITE_ONLY, WRITE_WITH_OPTIONAL_READ, READ_OR_WRITE
}
@@ -150,6 +131,28 @@ abstract class Slicer(
}
abstract fun processChildren()
protected fun KtFunction.processCalls(scope: SearchScope, exactFunctionOnly: Boolean, usageProcessor: (UsageInfo) -> Unit) {
val options = KotlinFunctionFindUsagesOptions(project).apply {
isSearchForTextOccurrences = false
isSkipImportStatements = true
searchScope = scope.intersectWith(useScope)
}
if (exactFunctionOnly) {
processAllExactUsages(options, usageProcessor)
} else {
val descriptor = unsafeResolveToDescriptor() as? CallableMemberDescriptor ?: return
for (superDescriptor in descriptor.getDeepestSuperDeclarations()) {
val declaration = superDescriptor.originalSource.getPsi() ?: continue
when (declaration) {
is KtDeclaration -> declaration.processAllUsages(options, usageProcessor)
// todo: work around the bug in JavaSliceProvider.transform()
is PsiMethod -> processor.process(JavaSliceUsage.createRootUsage(declaration, parentUsage.params))
else -> declaration.passToProcessor()
}
}
}
}
}
class InflowSlicer(
+3
View File
@@ -0,0 +1,3 @@
interface JavaInterface {
void foo(int p);
}
+5 -1
View File
@@ -4,7 +4,7 @@ interface I {
fun foo(p: Int)
}
class C : I {
class C : I, JavaInterface {
override fun foo(p: Int) {
println(<caret>p)
}
@@ -17,3 +17,7 @@ class C : I {
fun f(i: I) {
i.foo(2)
}
fun g(i: JavaInterface) {
i.foo(3)
}
@@ -1,3 +1,8 @@
2 void <bold>foo(int p);</bold>
9 println(<bold>p</bold>)
8 override fun foo(<bold>p: Int</bold>) {
2 void <bold>foo(int p);</bold>
13 foo(<bold>1</bold>)
9 println(<bold>p</bold>)
8 override fun foo(<bold>p: Int</bold>) {
+1
View File
@@ -1,4 +1,5 @@
9 println(<bold>p</bold>)
8 override fun foo(<bold>p: Int</bold>) {
2 void <bold>foo(int p);</bold>
13 foo(<bold>1</bold>)
18 i.foo(<bold>2</bold>)