Skip to content

Commit

Permalink
[idea] Support IDEA 2022.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Dec 22, 2022
1 parent 4545489 commit eb0891f
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 61 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ProjectConfigure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions mirai-console/tools/intellij-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -142,6 +142,7 @@ object ResourceNotClosedInspectionProcessors {
Fix("sendAsImageTo"),
)
}

callee.hasSignature(UPLOAD_AS_IMAGE) -> {
holder.registerResourceNotClosedProblem(
parent.receiverExpression,
Expand Down Expand Up @@ -232,6 +233,7 @@ object ResourceNotClosedInspectionProcessors {
fileTypeArgument = arguments.getOrNull(1)
) { it.methodExpression.qualifierExpression?.text ?: "this" }
}

callee.hasSignature(CONTACT_UPLOAD_IMAGE_STATIC) -> {
createFixImpl(
expr = expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit eb0891f

Please sign in to comment.