mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Support complex expressions
This commit is contained in:
parent
280a85ad8f
commit
f8b6e8a1fa
@ -56,16 +56,18 @@ class ConvertToPlainTextFix(
|
||||
|
||||
val psiFactory = KtPsiFactory(project)
|
||||
|
||||
if (element.parent is KtBinaryExpression) {
|
||||
// 'str + msg'
|
||||
|
||||
val referenceExpr = element.referenceExpression()
|
||||
if (referenceExpr == null || element.parent is KtBinaryExpression) {
|
||||
// + operator, e.g. 'str + msg'
|
||||
// or
|
||||
// complex expressions, e.g. 'str.toString().plus(msg)', '"".also { }.plus(msg)'
|
||||
val replaced = element.replace(psiFactory.createExpression("net.mamoe.mirai.message.data.PlainText(${element.text})"))
|
||||
as? KtElement ?: return
|
||||
ShortenReferences.DEFAULT.process(replaced)
|
||||
return
|
||||
}
|
||||
|
||||
val resolved = element.referenceExpression()?.resolve() ?: return
|
||||
val resolved = referenceExpr.resolve()
|
||||
if (resolved !is KtDeclaration) return
|
||||
// 'plus' function
|
||||
// perform fix on receiver
|
||||
|
Loading…
Reference in New Issue
Block a user