From 280a85ad8ffef62a53da8396b031803ee5f94de1 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 30 Dec 2020 16:44:58 +0800 Subject: [PATCH] Code cleanup --- .../UsingStringPlusMessageInspection.kt | 6 +----- .../src/diagnostics/fix/ConvertToPlainTextFix.kt | 16 ---------------- tools/intellij-plugin/src/resolve/resolveIdea.kt | 4 ++-- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/tools/intellij-plugin/src/diagnostics/UsingStringPlusMessageInspection.kt b/tools/intellij-plugin/src/diagnostics/UsingStringPlusMessageInspection.kt index bf686bbd7..1d6416233 100644 --- a/tools/intellij-plugin/src/diagnostics/UsingStringPlusMessageInspection.kt +++ b/tools/intellij-plugin/src/diagnostics/UsingStringPlusMessageInspection.kt @@ -42,9 +42,7 @@ class UsingStringPlusMessageInspection : AbstractKotlinInspection() { if (className != "kotlin.String") return@visitor if (callee.name != "plus") return@visitor - val parent = expression.parent - - val inspectionTarget = when (parent) { + val inspectionTarget = when (val parent = expression.parent) { is KtBinaryExpression -> { val right = parent.right?.referenceExpression()?.resolve() as? KtDeclaration ?: return@visitor val rightType = right.type() ?: return@visitor @@ -65,8 +63,6 @@ class UsingStringPlusMessageInspection : AbstractKotlinInspection() { else -> null } ?: return@visitor - println(expression::class.qualifiedName + " " + callee::class.qualifiedName + " " + callee.text) - holder.registerProblem( inspectionTarget, "使用 String + Message 会导致 Message 被转换为 String 再相加", diff --git a/tools/intellij-plugin/src/diagnostics/fix/ConvertToPlainTextFix.kt b/tools/intellij-plugin/src/diagnostics/fix/ConvertToPlainTextFix.kt index bd88076c1..9e56c083c 100644 --- a/tools/intellij-plugin/src/diagnostics/fix/ConvertToPlainTextFix.kt +++ b/tools/intellij-plugin/src/diagnostics/fix/ConvertToPlainTextFix.kt @@ -11,9 +11,7 @@ package net.mamoe.mirai.console.intellij.diagnostics.fix import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile -import org.jetbrains.annotations.NonNls import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall @@ -37,7 +35,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression import org.jetbrains.kotlin.psi.psiUtil.referenceExpression import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -import org.jetbrains.kotlin.utils.checkWithAttachment class ConvertToPlainTextFix( /** @@ -52,19 +49,6 @@ class ConvertToPlainTextFix( override fun getFamilyName(): String = "Mirai Console" override fun getText(): String = "将 String 转换为 PlainText" - fun KtPsiFactory.createAnalyzableDeclaration(@NonNls text: String, context: PsiElement): TDeclaration { - val file = createAnalyzableFile("Dummy.kt", text, context) - val declarations = file.declarations - checkWithAttachment(declarations.size == 1, { "unexpected ${declarations.size} declarations" }) { - it.withAttachment("text.kt", text) - for (d in declarations.withIndex()) { - it.withAttachment("declaration${d.index}.kt", d.value.text) - } - } - @Suppress("UNCHECKED_CAST") - return declarations.first() as TDeclaration - } - override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) { if (editor == null) return if (file !is KtFile) return diff --git a/tools/intellij-plugin/src/resolve/resolveIdea.kt b/tools/intellij-plugin/src/resolve/resolveIdea.kt index af3a6684f..fb8263eba 100644 --- a/tools/intellij-plugin/src/resolve/resolveIdea.kt +++ b/tools/intellij-plugin/src/resolve/resolveIdea.kt @@ -89,8 +89,8 @@ fun KtConstructorCalleeExpression.getTypeAsUserType(): KtUserType? { } fun KotlinType.hasSuperType(fqName: String, includeSelf: Boolean = true): Boolean { - if (this.fqName?.asString() == fqName) return true - return this.supertypes().any { it.hasSuperType("net.mamoe.mirai.message.data.Message", false) } + if (includeSelf && this.fqName?.asString() == fqName) return true + return this.supertypes().any { it.hasSuperType("net.mamoe.mirai.message.data.Message", true) } } fun KtClassOrObject.hasSuperType(fqName: FqName): Boolean = allSuperNames.contains(fqName)