[idea] Support IDEA 2022.3

This commit is contained in:
Him188 2022-12-22 13:26:58 +00:00
parent 4545489eef
commit eb0891fe24
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
14 changed files with 74 additions and 61 deletions

View File

@ -36,7 +36,7 @@ fun Project.useIr() {
private fun Project.jvmVersion(): JavaVersion {
return if (project.path.endsWith("mirai-console-intellij")) {
JavaVersion.VERSION_11
JavaVersion.VERSION_17
} else {
JavaVersion.VERSION_1_8
}

View File

@ -72,7 +72,7 @@ object Versions {
const val junit = "5.7.2"
const val yamlkt = "0.12.0"
const val intellijGradlePlugin = "1.7.0"
const val intellijGradlePlugin = "1.11.0"
// https://github.com/google/jimfs
// Java In Memory File System

View File

@ -44,8 +44,8 @@ intellij {
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.getByName("publishPlugin", org.jetbrains.intellij.tasks.PublishPluginTask::class) {
@ -64,15 +64,15 @@ fun File.resolveMkdir(relative: String): File {
kotlin.target.compilations.all {
kotlinOptions {
jvmTarget = "11"
apiVersion = "1.5" // bundled Kotlin is 1.5.10
jvmTarget = "17"
apiVersion = "1.7" // bundled Kotlin is 1.7.20
}
}
// https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
sinceBuild.set("221")
untilBuild.set("222.*")
sinceBuild.set("223")
untilBuild.set("223.*")
pluginDescription.set(
"""
Plugin development support for <a href='https://github.com/mamoe/mirai'>Mirai Console</a>

View File

@ -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 {
kotlin("jvm") version "1.6.0"
kotlin("plugin.serialization") version "1.6.0"
kotlin("jvm") version "1.7.20"
kotlin("plugin.serialization") version "1.7.20"
id("net.mamoe.mirai-console") version "2.99.0-local"
java
}

View File

@ -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 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* 此源代码的使用受 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/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
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.ModuleDescriptor
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.psi.KtDeclaration
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker

View File

@ -11,7 +11,9 @@ package net.mamoe.mirai.console.intellij.diagnostics
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.progress.impl.CancellationCheck.Companion.runWithCancellationCheck
import com.intellij.openapi.project.rootManager
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
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.resolve.allSuperNames
import net.mamoe.mirai.console.intellij.resolve.hasAnnotation
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.idea.util.rootManager
import org.jetbrains.kotlin.idea.base.util.module
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.classOrObjectVisitor

View File

@ -16,15 +16,15 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.*
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.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
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.util.ImportInsertHelper
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
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")
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
return originalCallee
@ -77,12 +77,12 @@ fun KtNamedFunction.isNamedMemberFunctionOf(
extensionReceiver: String? = null
): Boolean {
if (extensionReceiver != null) {
if (this.receiverTypeReference?.resolveReferencedType()?.getKotlinFqName()
if (this.receiverTypeReference?.resolveReferencedType()?.kotlinFqName
?.toString() != extensionReceiver
) return false
}
return this.name == functionName && this.containingClassOrObject?.allSuperTypes?.any {
it.getKotlinFqName()?.toString() == className
it.kotlinFqName?.toString() == className
} == true
}
@ -142,6 +142,7 @@ object ResourceNotClosedInspectionProcessors {
Fix("sendAsImageTo"),
)
}
callee.hasSignature(UPLOAD_AS_IMAGE) -> {
holder.registerResourceNotClosedProblem(
parent.receiverExpression,
@ -232,6 +233,7 @@ object ResourceNotClosedInspectionProcessors {
fileTypeArgument = arguments.getOrNull(1)
) { it.methodExpression.qualifierExpression?.text ?: "this" }
}
callee.hasSignature(CONTACT_UPLOAD_IMAGE_STATIC) -> {
createFixImpl(
expr = expr,

View File

@ -17,12 +17,12 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiFile
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.inspections.AbstractKotlinInspection
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForReceiver
@ -42,7 +42,7 @@ class UsingStringPlusMessageInspection : AbstractKotlinInspection() {
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
val className = callee.containingClassOrObject?.fqName?.asString()

View File

@ -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 org.jetbrains.kotlin.descriptors.CallableDescriptor
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.name.FqName
import org.jetbrains.kotlin.psi.KtElement
@ -47,7 +47,7 @@ fun KtElement.getResolvedCall(
}
fun KtTypeReference.isReferencing(fqName: FqName): Boolean {
return resolveReferencedType()?.getKotlinFqName() == fqName
return resolveReferencedType()?.kotlinFqName == fqName
}
val KtTypeReference.referencedUserType: KtUserType? get() = this.typeElement.castOrNull()

View File

@ -18,11 +18,11 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import net.mamoe.mirai.console.intellij.diagnostics.readChildText
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.quickfix.KotlinCrossLanguageQuickFixAction
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.module
class ConfigurePluginMainServiceFix(

View File

@ -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 许可证的约束, 可以在以下链接找到该许可证.
* 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.psi.PsiFile
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.replaced
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction
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.KtTypeProjection
@ -32,18 +31,15 @@ abstract class AbstractTypeProjectionFix(
override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) {
val element = element ?: return
project.executeWriteCommand(name) {
val arguments = element.text.substringAfter('<', "")
val e = element.replaced(
KtPsiFactory(project).createTypeArgument(
if (arguments.isBlank()) {
newTypeFqn
} else "$newTypeFqn<$arguments"
)
)
ShortenReferences.DEFAULT.process(e)
}
val arguments = element.text.substringAfter('<', "")
val newTypeElement = KtPsiFactory(project).createTypeArgument(
if (arguments.isBlank()) {
newTypeFqn
} else "$newTypeFqn<$arguments"
)
val e = element.replaced(newTypeElement)
// ABI change
ShortenReferences.DEFAULT.process(e)
}
}

View File

@ -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.resolveCalleeFunction
import net.mamoe.mirai.console.intellij.resolve.hasSignature
import org.jetbrains.kotlin.idea.intentions.SelfTargetingIntention
import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.idea.base.util.module
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingIntention
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression

View File

@ -14,12 +14,13 @@ import com.intellij.psi.PsiModifier
import net.mamoe.mirai.console.intellij.diagnostics.resolveReferencedType
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
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.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getReturnTypeReference
import org.jetbrains.kotlin.idea.refactoring.fqName.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.KtFunction
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
@ -87,7 +88,7 @@ fun KtFunction.hasSignature(functionSignature: FunctionSignature): Boolean {
}
if (functionSignature.extensionReceiver != null) {
if (this.receiverTypeReference?.resolveReferencedType()
?.getKotlinFqName() != functionSignature.extensionReceiver
?.kotlinFqName != functionSignature.extensionReceiver
) return false
}
if (functionSignature.parameters != null) {
@ -97,12 +98,14 @@ fun KtFunction.hasSignature(functionSignature: FunctionSignature): Boolean {
}
if (functionSignature.returnType != null) {
if (this.getReturnTypeReference()?.resolveReferencedType()
?.getKotlinFqName() != functionSignature.returnType
?.kotlinFqName != functionSignature.returnType
) return false
}
return true
}
fun KtDeclaration.type() =
(resolveToDescriptorIfAny() as? CallableDescriptor)?.returnType
fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
if (functionSignature.name != null) {
@ -115,8 +118,8 @@ fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
val kotlinContainingClassFqn = if (this is KtLightMethod) {
if (this.modifierList.hasExplicitModifier(PsiModifier.STATIC)) {
this.containingClass.kotlinOrigin?.companionObjects?.firstOrNull()?.fqName
} else containingClass.getKotlinFqName()
} else containingClass.getKotlinFqName()
} else containingClass.kotlinFqName
} else containingClass.kotlinFqName
if (kotlinContainingClassFqn != functionSignature.dispatchReceiver) return false
}

View File

@ -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.findParent
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.refactoring.fqName.fqName
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.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.referenceExpression
import org.jetbrains.kotlin.resolve.BindingContext
@ -67,7 +67,8 @@ val KtPureClassOrObject.allSuperTypes: Sequence<KtSuperTypeListEntry>
yieldAll(superTypeListEntries)
for (list in superTypeListEntries.asSequence()) {
yieldAll(
(list.typeAsUserType?.referenceExpression?.resolve()?.parents(true)?.filterIsInstance<KtClass>()
(list.typeAsUserType?.referenceExpression?.mainReference?.resolve()?.parents(true)
?.filterIsInstance<KtClass>()
?.firstOrNull())?.allSuperTypes.orEmpty()
)
}
@ -118,7 +119,7 @@ fun KtClass.hasSuperType(fqName: FqName): Boolean = allSuperNames.contains(fqNam
@kotlin.internal.LowPriorityInOverloadResolution
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>
get() = allSuperTypes.mapNotNull { clazz ->
clazz.qualifiedName?.let {
@ -151,14 +152,14 @@ fun getElementForLineMark(callElement: PsiElement): PsiElement =
val KtAnnotationEntry.annotationClass: KtClass?
get() = calleeExpression?.constructorReferenceExpression?.run {
try {
resolve()
mainReference.resolve()
} catch (e: Exception) {
null // type inference with `by lazy {}` is unstable for now. I just ignore exceptions encountering with such issue.
}
}?.findParent<KtClass>()
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>? {
return this.getArgumentExpression()?.resolveStringConstantValues(bindingContext)
@ -199,6 +200,7 @@ fun ConstantValue<*>.selfOrChildrenConstantStrings(): Sequence<String> {
is ArrayValue -> sequence {
yieldAll(this@selfOrChildrenConstantStrings.selfOrChildrenConstantStrings())
}
else -> emptySequence()
}
}
@ -230,6 +232,7 @@ fun KtExpression.resolveStringConstantValues(bindingContext: BindingContext): Se
//}
}
}
is KtStringTemplateExpression -> {
if (hasInterpolation()) return emptySequence()
return sequenceOf(entries.joinToString("") { it.text })