mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 23:50:15 +08:00
Support CommandDeclarationLineMarkerProvider for Java methods
This commit is contained in:
parent
6d02aa72d9
commit
73f457b628
@ -1,10 +1,30 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
|
import net.mamoe.mirai.console.command.Command;
|
||||||
|
import net.mamoe.mirai.console.command.CommandOwner;
|
||||||
|
import net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunction;
|
||||||
|
import net.mamoe.mirai.console.command.java.JSimpleCommand;
|
||||||
|
import net.mamoe.mirai.console.permission.Permission;
|
||||||
|
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription;
|
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TestJavaPlugin extends net.mamoe.mirai.console.plugin.jvm.JavaPlugin {
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestJavaPlugin extends JavaPlugin {
|
||||||
public TestJavaPlugin(@NotNull JvmPluginDescription description) {
|
public TestJavaPlugin(@NotNull JvmPluginDescription description) {
|
||||||
super(description);
|
super(description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestCommand extends JSimpleCommand {
|
||||||
|
|
||||||
|
public TestCommand(@NotNull CommandOwner owner, @NotNull String primaryName, @NotNull String[] secondaryNames, @NotNull Permission basePermission) {
|
||||||
|
super(owner, primaryName, secondaryNames, basePermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Handler
|
||||||
|
public void test(String s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo
|
|||||||
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
import com.intellij.codeInsight.daemon.LineMarkerProvider
|
||||||
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 com.intellij.psi.PsiMethod
|
||||||
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
|
||||||
@ -21,12 +22,25 @@ 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
|
when (element) {
|
||||||
|
is KtNamedFunction -> {
|
||||||
if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null
|
if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null
|
||||||
|
|
||||||
runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection
|
runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection
|
||||||
return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element))
|
return Info(getElementForLineMark(element.funKeyword ?: element.identifyingElement ?: element))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is PsiMethod -> {
|
||||||
|
if (!element.isSimpleCommandHandlerOrCompositeCommandSubCommand()) return null
|
||||||
|
|
||||||
|
runIgnoringErrors { // not showing icons is better than throwing exception every time doing inspection
|
||||||
|
return Info(getElementForLineMark(element.identifyingElement ?: element))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
class Info(callElement: PsiElement) : LineMarkerInfo<PsiElement>(
|
class Info(callElement: PsiElement) : LineMarkerInfo<PsiElement>(
|
||||||
|
@ -12,6 +12,7 @@ package net.mamoe.mirai.console.intellij.resolve
|
|||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiDeclarationStatement
|
import com.intellij.psi.PsiDeclarationStatement
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiModifierListOwner
|
||||||
import com.intellij.psi.util.parentsWithSelf
|
import com.intellij.psi.util.parentsWithSelf
|
||||||
import net.mamoe.mirai.console.compiler.common.castOrNull
|
import net.mamoe.mirai.console.compiler.common.castOrNull
|
||||||
import net.mamoe.mirai.console.compiler.common.resolve.*
|
import net.mamoe.mirai.console.compiler.common.resolve.*
|
||||||
@ -43,15 +44,22 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
|||||||
* For CompositeCommand.SubCommand
|
* For CompositeCommand.SubCommand
|
||||||
*/
|
*/
|
||||||
fun KtNamedFunction.isCompositeCommandSubCommand(): Boolean = this.hasAnnotation(COMPOSITE_COMMAND_SUB_COMMAND_FQ_NAME)
|
fun KtNamedFunction.isCompositeCommandSubCommand(): Boolean = this.hasAnnotation(COMPOSITE_COMMAND_SUB_COMMAND_FQ_NAME)
|
||||||
|
fun PsiModifierListOwner.isCompositeCommandSubCommand(): Boolean = this.hasAnnotation(COMPOSITE_COMMAND_SUB_COMMAND_FQ_NAME)
|
||||||
|
|
||||||
|
internal fun PsiModifierListOwner.hasAnnotation(fqName: FqName): Boolean = this.hasAnnotation(fqName.asString())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleCommand.Handler
|
* SimpleCommand.Handler
|
||||||
*/
|
*/
|
||||||
fun KtNamedFunction.isSimpleCommandHandler(): Boolean = this.hasAnnotation(SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME)
|
fun KtNamedFunction.isSimpleCommandHandler(): Boolean = this.hasAnnotation(SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME)
|
||||||
|
fun PsiModifierListOwner.isSimpleCommandHandler(): Boolean = this.hasAnnotation(SIMPLE_COMMAND_HANDLER_COMMAND_FQ_NAME)
|
||||||
|
|
||||||
fun KtNamedFunction.isSimpleCommandHandlerOrCompositeCommandSubCommand(): Boolean =
|
fun KtNamedFunction.isSimpleCommandHandlerOrCompositeCommandSubCommand(): Boolean =
|
||||||
this.isSimpleCommandHandler() || this.isCompositeCommandSubCommand()
|
this.isSimpleCommandHandler() || this.isCompositeCommandSubCommand()
|
||||||
|
|
||||||
|
fun PsiModifierListOwner.isSimpleCommandHandlerOrCompositeCommandSubCommand(): Boolean =
|
||||||
|
this.isSimpleCommandHandler() || this.isCompositeCommandSubCommand()
|
||||||
|
|
||||||
|
|
||||||
val KtPureClassOrObject.allSuperTypes: Sequence<KtSuperTypeListEntry>
|
val KtPureClassOrObject.allSuperTypes: Sequence<KtSuperTypeListEntry>
|
||||||
get() = sequence {
|
get() = sequence {
|
||||||
|
Loading…
Reference in New Issue
Block a user