mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-29 10:00:13 +08:00
[idea] Support IDEA 2022.3
This commit is contained in:
parent
4545489eef
commit
eb0891fe24
@ -36,7 +36,7 @@ fun Project.useIr() {
|
|||||||
|
|
||||||
private fun Project.jvmVersion(): JavaVersion {
|
private fun Project.jvmVersion(): JavaVersion {
|
||||||
return if (project.path.endsWith("mirai-console-intellij")) {
|
return if (project.path.endsWith("mirai-console-intellij")) {
|
||||||
JavaVersion.VERSION_11
|
JavaVersion.VERSION_17
|
||||||
} else {
|
} else {
|
||||||
JavaVersion.VERSION_1_8
|
JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ object Versions {
|
|||||||
const val junit = "5.7.2"
|
const val junit = "5.7.2"
|
||||||
|
|
||||||
const val yamlkt = "0.12.0"
|
const val yamlkt = "0.12.0"
|
||||||
const val intellijGradlePlugin = "1.7.0"
|
const val intellijGradlePlugin = "1.11.0"
|
||||||
|
|
||||||
// https://github.com/google/jimfs
|
// https://github.com/google/jimfs
|
||||||
// Java In Memory File System
|
// Java In Memory File System
|
||||||
|
@ -44,8 +44,8 @@ intellij {
|
|||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.getByName("publishPlugin", org.jetbrains.intellij.tasks.PublishPluginTask::class) {
|
tasks.getByName("publishPlugin", org.jetbrains.intellij.tasks.PublishPluginTask::class) {
|
||||||
@ -64,15 +64,15 @@ fun File.resolveMkdir(relative: String): File {
|
|||||||
|
|
||||||
kotlin.target.compilations.all {
|
kotlin.target.compilations.all {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "11"
|
jvmTarget = "17"
|
||||||
apiVersion = "1.5" // bundled Kotlin is 1.5.10
|
apiVersion = "1.7" // bundled Kotlin is 1.7.20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
|
// https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
|
||||||
tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
|
tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
|
||||||
sinceBuild.set("221")
|
sinceBuild.set("223")
|
||||||
untilBuild.set("222.*")
|
untilBuild.set("223.*")
|
||||||
pluginDescription.set(
|
pluginDescription.set(
|
||||||
"""
|
"""
|
||||||
Plugin development support for <a href='https://github.com/mamoe/mirai'>Mirai Console</a>
|
Plugin development support for <a href='https://github.com/mamoe/mirai'>Mirai Console</a>
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
|
*
|
||||||
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
|
*
|
||||||
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.6.0"
|
kotlin("jvm") version "1.7.20"
|
||||||
kotlin("plugin.serialization") version "1.6.0"
|
kotlin("plugin.serialization") version "1.7.20"
|
||||||
id("net.mamoe.mirai-console") version "2.99.0-local"
|
id("net.mamoe.mirai-console") version "2.99.0-local"
|
||||||
java
|
java
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
*
|
*
|
||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.intellij
|
package net.mamoe.mirai.console.intellij
|
||||||
@ -23,7 +23,7 @@ import org.jetbrains.kotlin.container.useInstance
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||||
import org.jetbrains.kotlin.idea.core.unwrapModuleSourceInfo
|
import org.jetbrains.kotlin.idea.base.projectStructure.unwrapModuleSourceInfo
|
||||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||||
|
@ -11,7 +11,9 @@ package net.mamoe.mirai.console.intellij.diagnostics
|
|||||||
|
|
||||||
import com.intellij.codeInspection.ProblemHighlightType
|
import com.intellij.codeInspection.ProblemHighlightType
|
||||||
import com.intellij.codeInspection.ProblemsHolder
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
|
import com.intellij.openapi.application.runReadAction
|
||||||
import com.intellij.openapi.progress.impl.CancellationCheck.Companion.runWithCancellationCheck
|
import com.intellij.openapi.progress.impl.CancellationCheck.Companion.runWithCancellationCheck
|
||||||
|
import com.intellij.openapi.project.rootManager
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
@ -21,10 +23,8 @@ import net.mamoe.mirai.console.compiler.common.resolve.PLUGIN_FQ_NAME
|
|||||||
import net.mamoe.mirai.console.intellij.diagnostics.fix.ConfigurePluginMainServiceFix
|
import net.mamoe.mirai.console.intellij.diagnostics.fix.ConfigurePluginMainServiceFix
|
||||||
import net.mamoe.mirai.console.intellij.resolve.allSuperNames
|
import net.mamoe.mirai.console.intellij.resolve.allSuperNames
|
||||||
import net.mamoe.mirai.console.intellij.resolve.hasAnnotation
|
import net.mamoe.mirai.console.intellij.resolve.hasAnnotation
|
||||||
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
import org.jetbrains.kotlin.idea.base.util.module
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||||
import org.jetbrains.kotlin.idea.util.module
|
|
||||||
import org.jetbrains.kotlin.idea.util.rootManager
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||||
import org.jetbrains.kotlin.psi.classOrObjectVisitor
|
import org.jetbrains.kotlin.psi.classOrObjectVisitor
|
||||||
|
@ -16,15 +16,15 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import net.mamoe.mirai.console.intellij.resolve.*
|
import net.mamoe.mirai.console.intellij.resolve.*
|
||||||
import org.jetbrains.kotlin.idea.base.utils.fqname.getKotlinFqName
|
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||||
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||||
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
||||||
@ -65,7 +65,7 @@ val CONTACT_FQ_NAME = FqName("net.mamoe.mirai.contact.Contact")
|
|||||||
val CONTACT_COMPANION_FQ_NAME = FqName("net.mamoe.mirai.contact.Contact.Companion")
|
val CONTACT_COMPANION_FQ_NAME = FqName("net.mamoe.mirai.contact.Contact.Companion")
|
||||||
|
|
||||||
fun KtReferenceExpression.resolveCalleeFunction(): KtNamedFunction? {
|
fun KtReferenceExpression.resolveCalleeFunction(): KtNamedFunction? {
|
||||||
val originalCallee = getCalleeExpressionIfAny()?.referenceExpression()?.resolve() ?: return null
|
val originalCallee = getCalleeExpressionIfAny()?.referenceExpression()?.mainReference?.resolve() ?: return null
|
||||||
if (originalCallee !is KtNamedFunction) return null
|
if (originalCallee !is KtNamedFunction) return null
|
||||||
|
|
||||||
return originalCallee
|
return originalCallee
|
||||||
@ -77,12 +77,12 @@ fun KtNamedFunction.isNamedMemberFunctionOf(
|
|||||||
extensionReceiver: String? = null
|
extensionReceiver: String? = null
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (extensionReceiver != null) {
|
if (extensionReceiver != null) {
|
||||||
if (this.receiverTypeReference?.resolveReferencedType()?.getKotlinFqName()
|
if (this.receiverTypeReference?.resolveReferencedType()?.kotlinFqName
|
||||||
?.toString() != extensionReceiver
|
?.toString() != extensionReceiver
|
||||||
) return false
|
) return false
|
||||||
}
|
}
|
||||||
return this.name == functionName && this.containingClassOrObject?.allSuperTypes?.any {
|
return this.name == functionName && this.containingClassOrObject?.allSuperTypes?.any {
|
||||||
it.getKotlinFqName()?.toString() == className
|
it.kotlinFqName?.toString() == className
|
||||||
} == true
|
} == true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +142,7 @@ object ResourceNotClosedInspectionProcessors {
|
|||||||
Fix("sendAsImageTo"),
|
Fix("sendAsImageTo"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
callee.hasSignature(UPLOAD_AS_IMAGE) -> {
|
callee.hasSignature(UPLOAD_AS_IMAGE) -> {
|
||||||
holder.registerResourceNotClosedProblem(
|
holder.registerResourceNotClosedProblem(
|
||||||
parent.receiverExpression,
|
parent.receiverExpression,
|
||||||
@ -232,6 +233,7 @@ object ResourceNotClosedInspectionProcessors {
|
|||||||
fileTypeArgument = arguments.getOrNull(1)
|
fileTypeArgument = arguments.getOrNull(1)
|
||||||
) { it.methodExpression.qualifierExpression?.text ?: "this" }
|
) { it.methodExpression.qualifierExpression?.text ?: "this" }
|
||||||
}
|
}
|
||||||
|
|
||||||
callee.hasSignature(CONTACT_UPLOAD_IMAGE_STATIC) -> {
|
callee.hasSignature(CONTACT_UPLOAD_IMAGE_STATIC) -> {
|
||||||
createFixImpl(
|
createFixImpl(
|
||||||
expr = expr,
|
expr = expr,
|
||||||
|
@ -17,12 +17,12 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import net.mamoe.mirai.console.intellij.resolve.*
|
import net.mamoe.mirai.console.intellij.resolve.*
|
||||||
|
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
|
||||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||||
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForReceiver
|
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForReceiver
|
||||||
@ -42,7 +42,7 @@ class UsingStringPlusMessageInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
|
|
||||||
fun KtReferenceExpression.isCallingStringPlus(): Boolean {
|
fun KtReferenceExpression.isCallingStringPlus(): Boolean {
|
||||||
val callee = this.referenceExpression()?.resolve() ?: return false
|
val callee = this.referenceExpression()?.mainReference?.resolve() ?: return false
|
||||||
if (callee !is KtNamedFunction) return false
|
if (callee !is KtNamedFunction) return false
|
||||||
|
|
||||||
val className = callee.containingClassOrObject?.fqName?.asString()
|
val className = callee.containingClassOrObject?.fqName?.asString()
|
||||||
|
@ -15,7 +15,7 @@ import net.mamoe.mirai.console.compiler.common.resolve.READ_ONLY_PLUGIN_DATA_FQ_
|
|||||||
import net.mamoe.mirai.console.intellij.resolve.getResolvedCall
|
import net.mamoe.mirai.console.intellij.resolve.getResolvedCall
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.kotlin.idea.base.utils.fqname.getKotlinFqName
|
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
@ -47,7 +47,7 @@ fun KtElement.getResolvedCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KtTypeReference.isReferencing(fqName: FqName): Boolean {
|
fun KtTypeReference.isReferencing(fqName: FqName): Boolean {
|
||||||
return resolveReferencedType()?.getKotlinFqName() == fqName
|
return resolveReferencedType()?.kotlinFqName == fqName
|
||||||
}
|
}
|
||||||
|
|
||||||
val KtTypeReference.referencedUserType: KtUserType? get() = this.typeElement.castOrNull()
|
val KtTypeReference.referencedUserType: KtUserType? get() = this.typeElement.castOrNull()
|
||||||
|
@ -18,11 +18,11 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import net.mamoe.mirai.console.intellij.diagnostics.readChildText
|
import net.mamoe.mirai.console.intellij.diagnostics.readChildText
|
||||||
import net.mamoe.mirai.console.intellij.diagnostics.writeChild
|
import net.mamoe.mirai.console.intellij.diagnostics.writeChild
|
||||||
import org.jetbrains.kotlin.idea.core.isAndroidModule
|
import org.jetbrains.kotlin.idea.base.util.isAndroidModule
|
||||||
|
import org.jetbrains.kotlin.idea.base.util.module
|
||||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.idea.util.module
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigurePluginMainServiceFix(
|
class ConfigurePluginMainServiceFix(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||||
*
|
*
|
||||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||||
@ -14,12 +14,11 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.idea.base.psi.replaced
|
||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
|
||||||
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
|
||||||
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
|
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.KtTypeProjection
|
import org.jetbrains.kotlin.psi.KtTypeProjection
|
||||||
|
|
||||||
@ -32,18 +31,15 @@ abstract class AbstractTypeProjectionFix(
|
|||||||
|
|
||||||
override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) {
|
override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) {
|
||||||
val element = element ?: return
|
val element = element ?: return
|
||||||
project.executeWriteCommand(name) {
|
val arguments = element.text.substringAfter('<', "")
|
||||||
val arguments = element.text.substringAfter('<', "")
|
val newTypeElement = KtPsiFactory(project).createTypeArgument(
|
||||||
|
if (arguments.isBlank()) {
|
||||||
val e = element.replaced(
|
newTypeFqn
|
||||||
KtPsiFactory(project).createTypeArgument(
|
} else "$newTypeFqn<$arguments"
|
||||||
if (arguments.isBlank()) {
|
)
|
||||||
newTypeFqn
|
val e = element.replaced(newTypeElement)
|
||||||
} else "$newTypeFqn<$arguments"
|
// ABI change
|
||||||
)
|
ShortenReferences.DEFAULT.process(e)
|
||||||
)
|
|
||||||
ShortenReferences.DEFAULT.process(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import net.mamoe.mirai.console.intellij.diagnostics.ResourceNotClosedInspectionP
|
|||||||
import net.mamoe.mirai.console.intellij.diagnostics.replaceExpressionAndShortenReferences
|
import net.mamoe.mirai.console.intellij.diagnostics.replaceExpressionAndShortenReferences
|
||||||
import net.mamoe.mirai.console.intellij.diagnostics.resolveCalleeFunction
|
import net.mamoe.mirai.console.intellij.diagnostics.resolveCalleeFunction
|
||||||
import net.mamoe.mirai.console.intellij.resolve.hasSignature
|
import net.mamoe.mirai.console.intellij.resolve.hasSignature
|
||||||
import org.jetbrains.kotlin.idea.intentions.SelfTargetingIntention
|
import org.jetbrains.kotlin.idea.base.util.module
|
||||||
import org.jetbrains.kotlin.idea.util.module
|
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingIntention
|
||||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
||||||
|
@ -14,12 +14,13 @@ import com.intellij.psi.PsiModifier
|
|||||||
import net.mamoe.mirai.console.intellij.diagnostics.resolveReferencedType
|
import net.mamoe.mirai.console.intellij.diagnostics.resolveReferencedType
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.base.utils.fqname.getKotlinFqName
|
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getReturnTypeReference
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getReturnTypeReference
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.nj2k.postProcessing.type
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFunction
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
@ -87,7 +88,7 @@ fun KtFunction.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|||||||
}
|
}
|
||||||
if (functionSignature.extensionReceiver != null) {
|
if (functionSignature.extensionReceiver != null) {
|
||||||
if (this.receiverTypeReference?.resolveReferencedType()
|
if (this.receiverTypeReference?.resolveReferencedType()
|
||||||
?.getKotlinFqName() != functionSignature.extensionReceiver
|
?.kotlinFqName != functionSignature.extensionReceiver
|
||||||
) return false
|
) return false
|
||||||
}
|
}
|
||||||
if (functionSignature.parameters != null) {
|
if (functionSignature.parameters != null) {
|
||||||
@ -97,12 +98,14 @@ fun KtFunction.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|||||||
}
|
}
|
||||||
if (functionSignature.returnType != null) {
|
if (functionSignature.returnType != null) {
|
||||||
if (this.getReturnTypeReference()?.resolveReferencedType()
|
if (this.getReturnTypeReference()?.resolveReferencedType()
|
||||||
?.getKotlinFqName() != functionSignature.returnType
|
?.kotlinFqName != functionSignature.returnType
|
||||||
) return false
|
) return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KtDeclaration.type() =
|
||||||
|
(resolveToDescriptorIfAny() as? CallableDescriptor)?.returnType
|
||||||
|
|
||||||
fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
||||||
if (functionSignature.name != null) {
|
if (functionSignature.name != null) {
|
||||||
@ -115,8 +118,8 @@ fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|||||||
val kotlinContainingClassFqn = if (this is KtLightMethod) {
|
val kotlinContainingClassFqn = if (this is KtLightMethod) {
|
||||||
if (this.modifierList.hasExplicitModifier(PsiModifier.STATIC)) {
|
if (this.modifierList.hasExplicitModifier(PsiModifier.STATIC)) {
|
||||||
this.containingClass.kotlinOrigin?.companionObjects?.firstOrNull()?.fqName
|
this.containingClass.kotlinOrigin?.companionObjects?.firstOrNull()?.fqName
|
||||||
} else containingClass.getKotlinFqName()
|
} else containingClass.kotlinFqName
|
||||||
} else containingClass.getKotlinFqName()
|
} else containingClass.kotlinFqName
|
||||||
|
|
||||||
if (kotlinContainingClassFqn != functionSignature.dispatchReceiver) return false
|
if (kotlinContainingClassFqn != functionSignature.dispatchReceiver) return false
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,15 @@ import net.mamoe.mirai.console.compiler.common.resolve.COMPOSITE_COMMAND_SUB_COM
|
|||||||
import net.mamoe.mirai.console.compiler.common.resolve.SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME
|
import net.mamoe.mirai.console.compiler.common.resolve.SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME
|
||||||
import net.mamoe.mirai.console.compiler.common.resolve.findParent
|
import net.mamoe.mirai.console.compiler.common.resolve.findParent
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.base.utils.fqname.getKotlinFqName
|
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
||||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||||
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.idea.references.resolveToDescriptors
|
import org.jetbrains.kotlin.idea.references.resolveToDescriptors
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
@ -67,7 +67,8 @@ val KtPureClassOrObject.allSuperTypes: Sequence<KtSuperTypeListEntry>
|
|||||||
yieldAll(superTypeListEntries)
|
yieldAll(superTypeListEntries)
|
||||||
for (list in superTypeListEntries.asSequence()) {
|
for (list in superTypeListEntries.asSequence()) {
|
||||||
yieldAll(
|
yieldAll(
|
||||||
(list.typeAsUserType?.referenceExpression?.resolve()?.parents(true)?.filterIsInstance<KtClass>()
|
(list.typeAsUserType?.referenceExpression?.mainReference?.resolve()?.parents(true)
|
||||||
|
?.filterIsInstance<KtClass>()
|
||||||
?.firstOrNull())?.allSuperTypes.orEmpty()
|
?.firstOrNull())?.allSuperTypes.orEmpty()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ fun KtClass.hasSuperType(fqName: FqName): Boolean = allSuperNames.contains(fqNam
|
|||||||
@kotlin.internal.LowPriorityInOverloadResolution
|
@kotlin.internal.LowPriorityInOverloadResolution
|
||||||
fun PsiElement.hasSuperType(fqName: FqName): Boolean = allSuperNames.contains(fqName)
|
fun PsiElement.hasSuperType(fqName: FqName): Boolean = allSuperNames.contains(fqName)
|
||||||
|
|
||||||
val KtClassOrObject.allSuperNames: Sequence<FqName> get() = allSuperTypes.mapNotNull { it.getKotlinFqName() }
|
val KtClassOrObject.allSuperNames: Sequence<FqName> get() = allSuperTypes.mapNotNull { it.kotlinFqName }
|
||||||
val PsiClass.allSuperNames: Sequence<FqName>
|
val PsiClass.allSuperNames: Sequence<FqName>
|
||||||
get() = allSuperTypes.mapNotNull { clazz ->
|
get() = allSuperTypes.mapNotNull { clazz ->
|
||||||
clazz.qualifiedName?.let {
|
clazz.qualifiedName?.let {
|
||||||
@ -151,14 +152,14 @@ fun getElementForLineMark(callElement: PsiElement): PsiElement =
|
|||||||
val KtAnnotationEntry.annotationClass: KtClass?
|
val KtAnnotationEntry.annotationClass: KtClass?
|
||||||
get() = calleeExpression?.constructorReferenceExpression?.run {
|
get() = calleeExpression?.constructorReferenceExpression?.run {
|
||||||
try {
|
try {
|
||||||
resolve()
|
mainReference.resolve()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null // type inference with `by lazy {}` is unstable for now. I just ignore exceptions encountering with such issue.
|
null // type inference with `by lazy {}` is unstable for now. I just ignore exceptions encountering with such issue.
|
||||||
}
|
}
|
||||||
}?.findParent<KtClass>()
|
}?.findParent<KtClass>()
|
||||||
|
|
||||||
fun KtAnnotated.hasAnnotation(fqName: FqName): Boolean =
|
fun KtAnnotated.hasAnnotation(fqName: FqName): Boolean =
|
||||||
this.annotationEntries.any { it.annotationClass?.getKotlinFqName() == fqName }
|
this.annotationEntries.any { it.annotationClass?.kotlinFqName == fqName }
|
||||||
|
|
||||||
fun ValueArgument.resolveStringConstantValues(bindingContext: BindingContext): Sequence<String>? {
|
fun ValueArgument.resolveStringConstantValues(bindingContext: BindingContext): Sequence<String>? {
|
||||||
return this.getArgumentExpression()?.resolveStringConstantValues(bindingContext)
|
return this.getArgumentExpression()?.resolveStringConstantValues(bindingContext)
|
||||||
@ -199,6 +200,7 @@ fun ConstantValue<*>.selfOrChildrenConstantStrings(): Sequence<String> {
|
|||||||
is ArrayValue -> sequence {
|
is ArrayValue -> sequence {
|
||||||
yieldAll(this@selfOrChildrenConstantStrings.selfOrChildrenConstantStrings())
|
yieldAll(this@selfOrChildrenConstantStrings.selfOrChildrenConstantStrings())
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> emptySequence()
|
else -> emptySequence()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,6 +232,7 @@ fun KtExpression.resolveStringConstantValues(bindingContext: BindingContext): Se
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is KtStringTemplateExpression -> {
|
is KtStringTemplateExpression -> {
|
||||||
if (hasInterpolation()) return emptySequence()
|
if (hasInterpolation()) return emptySequence()
|
||||||
return sequenceOf(entries.joinToString("") { it.text })
|
return sequenceOf(entries.joinToString("") { it.text })
|
||||||
|
Loading…
Reference in New Issue
Block a user