mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Migrate deprecated usages of LineMarkerInfo
This commit is contained in:
parent
b254018a74
commit
445cfd07c3
@ -1,49 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
* Copyright 2019-2021 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 AFFERO GENERAL PUBLIC LICENSE version 3 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/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.intellij.line.marker
|
package net.mamoe.mirai.console.intellij.line.marker
|
||||||
|
|
||||||
import com.intellij.codeHighlighting.Pass
|
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
||||||
import com.intellij.openapi.actionSystem.AnAction
|
|
||||||
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import net.mamoe.mirai.console.intellij.Icons
|
import net.mamoe.mirai.console.intellij.Icons
|
||||||
import net.mamoe.mirai.console.intellij.resolve.getElementForLineMark
|
import net.mamoe.mirai.console.intellij.resolve.getElementForLineMark
|
||||||
import net.mamoe.mirai.console.intellij.resolve.isSimpleCommandHandlerOrCompositeCommandSubCommand
|
import net.mamoe.mirai.console.intellij.resolve.isSimpleCommandHandlerOrCompositeCommandSubCommand
|
||||||
|
import net.mamoe.mirai.console.intellij.util.runIgnoringErrors
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
|
|
||||||
class CommandDeclarationLineMarkerProvider : LineMarkerProvider {
|
class CommandDeclarationLineMarkerProvider : LineMarkerProvider {
|
||||||
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
|
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
|
||||||
if (element !is KtNamedFunction) return null
|
if (element !is KtNamedFunction) return null
|
||||||
if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null
|
if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null
|
||||||
return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element))
|
runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection
|
||||||
|
return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
class Info(
|
class Info(callElement: PsiElement) : LineMarkerInfo<PsiElement>(
|
||||||
callElement: PsiElement,
|
|
||||||
) : LineMarkerInfo<PsiElement>(
|
|
||||||
callElement,
|
callElement,
|
||||||
callElement.textRange,
|
callElement.textRange,
|
||||||
Icons.CommandDeclaration,
|
Icons.CommandDeclaration,
|
||||||
Pass.LINE_MARKERS,
|
tooltipProvider,
|
||||||
{
|
null, GutterIconRenderer.Alignment.RIGHT
|
||||||
"子指令定义"
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
GutterIconRenderer.Alignment.RIGHT
|
|
||||||
) {
|
) {
|
||||||
override fun createGutterRenderer(): GutterIconRenderer {
|
companion object {
|
||||||
return object : LineMarkerInfo.LineMarkerGutterIconRenderer<PsiElement>(this) {
|
val tooltipProvider = { _: PsiElement ->
|
||||||
override fun getClickAction(): AnAction? = null
|
"子指令定义"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
* Copyright 2019-2021 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 AFFERO GENERAL PUBLIC LICENSE version 3 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/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.mamoe.mirai.console.intellij.line.marker
|
package net.mamoe.mirai.console.intellij.line.marker
|
||||||
|
|
||||||
import com.intellij.codeHighlighting.Pass
|
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
import com.intellij.codeInsight.daemon.LineMarkerInfo
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
||||||
import com.intellij.openapi.actionSystem.AnAction
|
|
||||||
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import net.mamoe.mirai.console.compiler.common.resolve.PLUGIN_FQ_NAME
|
import net.mamoe.mirai.console.compiler.common.resolve.PLUGIN_FQ_NAME
|
||||||
import net.mamoe.mirai.console.intellij.Icons
|
import net.mamoe.mirai.console.intellij.Icons
|
||||||
import net.mamoe.mirai.console.intellij.resolve.allSuperNames
|
import net.mamoe.mirai.console.intellij.resolve.allSuperNames
|
||||||
import net.mamoe.mirai.console.intellij.resolve.getElementForLineMark
|
import net.mamoe.mirai.console.intellij.resolve.getElementForLineMark
|
||||||
|
import net.mamoe.mirai.console.intellij.util.runIgnoringErrors
|
||||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||||
|
|
||||||
class PluginMainLineMarkerProvider : LineMarkerProvider {
|
class PluginMainLineMarkerProvider : LineMarkerProvider {
|
||||||
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
|
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
|
||||||
if (element !is KtObjectDeclaration) return null
|
if (element !is KtObjectDeclaration) return null
|
||||||
if (element.allSuperNames.any { it == PLUGIN_FQ_NAME }) return Info(getElementForLineMark(element))
|
runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection
|
||||||
|
if (element.allSuperNames.any { it == PLUGIN_FQ_NAME }) return Info(getElementForLineMark(element))
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
class Info(
|
class Info(callElement: PsiElement) : LineMarkerInfo<PsiElement>(
|
||||||
callElement: PsiElement,
|
// this constructor is deprecated but is not going to be removed. The newer ones are since 203 which is too high.
|
||||||
) : LineMarkerInfo<PsiElement>(
|
|
||||||
callElement,
|
callElement,
|
||||||
callElement.textRange,
|
callElement.textRange,
|
||||||
Icons.PluginMainDeclaration,
|
Icons.CommandDeclaration,
|
||||||
Pass.LINE_MARKERS,
|
tooltipProvider,
|
||||||
{
|
null, GutterIconRenderer.Alignment.RIGHT
|
||||||
"Mirai Console Plugin"
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
GutterIconRenderer.Alignment.CENTER
|
|
||||||
) {
|
) {
|
||||||
override fun createGutterRenderer(): GutterIconRenderer {
|
companion object {
|
||||||
return object : LineMarkerInfo.LineMarkerGutterIconRenderer<PsiElement>(this) {
|
val tooltipProvider = { _: PsiElement ->
|
||||||
override fun getClickAction(): AnAction? = null
|
"Mirai Console Plugin"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user