Minor refactoring in DeprecatedCallChecker
This commit is contained in:
+9
-10
@@ -50,38 +50,37 @@ object DeprecatedCallChecker : CallChecker {
|
||||
if (deprecation != null) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation))
|
||||
}
|
||||
else if (targetDescriptor is PropertyDescriptor) {
|
||||
propertyGetterWorkaround(targetDescriptor, trace, element)
|
||||
else if (targetDescriptor is PropertyDescriptor && shouldCheckPropertyGetter(element)) {
|
||||
targetDescriptor.getter?.let { check(it, trace, element) }
|
||||
}
|
||||
}
|
||||
|
||||
private val PROPERTY_SET_OPERATIONS = TokenSet.create(KtTokens.EQ, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ,
|
||||
KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS)
|
||||
private val PROPERTY_SET_OPERATIONS = TokenSet.create(*KtTokens.ALL_ASSIGNMENTS.types, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS)
|
||||
|
||||
private fun propertyGetterWorkaround(propertyDescriptor: PropertyDescriptor, trace: BindingTrace, expression: PsiElement) {
|
||||
private fun shouldCheckPropertyGetter(expression: PsiElement): Boolean {
|
||||
// property getters do not come as callable yet, so we analyse surroundings to check for deprecation annotation on getter
|
||||
val binaryExpression = PsiTreeUtil.getParentOfType<KtBinaryExpression>(expression, KtBinaryExpression::class.java)
|
||||
if (binaryExpression != null) {
|
||||
val left = binaryExpression.left
|
||||
if (left == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
|
||||
if (left == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return false
|
||||
|
||||
val referenceExpressions = PsiTreeUtil.getChildrenOfType<KtReferenceExpression>(left, KtReferenceExpression::class.java)
|
||||
if (referenceExpressions != null) {
|
||||
for (expr in referenceExpressions) {
|
||||
// skip binary set operations
|
||||
if (expr == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
|
||||
if (expr == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val unaryExpression = PsiTreeUtil.getParentOfType(expression, KtUnaryExpression::class.java)
|
||||
// skip unary set operations
|
||||
if (unaryExpression?.operationReference?.getReferencedNameElementType() in PROPERTY_SET_OPERATIONS) return
|
||||
if (unaryExpression?.operationReference?.getReferencedNameElementType() in PROPERTY_SET_OPERATIONS) return false
|
||||
|
||||
val callableExpression = PsiTreeUtil.getParentOfType(expression, KtCallableReferenceExpression::class.java)
|
||||
// skip Type::property
|
||||
if (callableExpression != null && callableExpression.callableReference == expression) return
|
||||
if (callableExpression != null && callableExpression.callableReference == expression) return false
|
||||
|
||||
propertyDescriptor.getter?.let { check(it, trace, expression) }
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user