CFG: mark annotation arguments as "used as expressions" #KT-24596 Fixed

NB: only classes / function / properties annotations are considered here,
not including local declarations and other annotations
This commit is contained in:
Mikhail Glukhikh
2019-07-09 13:12:48 +03:00
parent b24b8bfb28
commit eb00af6b96
4 changed files with 70 additions and 0 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.BindingContext.*
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
@@ -97,6 +98,7 @@ class ControlFlowInformationProvider private constructor(
}
markStatements()
markAnnotationArguments()
markUnusedExpressions()
@@ -799,6 +801,21 @@ class ControlFlowInformationProvider private constructor(
}
}
private fun markAnnotationArguments() {
when (subroutine) {
is KtAnnotationEntry -> markAnnotationArguments(subroutine)
is KtAnnotated -> subroutine.annotationEntries.forEach { markAnnotationArguments(it) }
}
}
private fun markAnnotationArguments(entry: KtAnnotationEntry) {
for (argument in entry.valueArguments) {
argument.getArgumentExpression()?.forEachDescendantOfType<KtExpression> {
trace.record(USED_AS_EXPRESSION, it, true)
}
}
}
private fun checkIfExpressions() = pseudocode.traverse(TraversalOrder.FORWARD) { instruction ->
val value = (instruction as? InstructionWithValue)?.outputValue
for (element in instruction.owner.getValueElements(value)) {