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