mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Improve PsiMethod.hasSignature; fix #294
This commit is contained in:
parent
06564e9142
commit
5bf1a9755f
@ -11,7 +11,19 @@ import java.io.IOException;
|
|||||||
import static org.example.myplugin.ResourceNotClosedInspectionTestKt.magic;
|
import static org.example.myplugin.ResourceNotClosedInspectionTestKt.magic;
|
||||||
|
|
||||||
public class ResourceNotClosedInspectionTestJava {
|
public class ResourceNotClosedInspectionTestJava {
|
||||||
|
|
||||||
|
public static Object funA() {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void funB(Object obj) {
|
||||||
|
System.out.println(obj);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// https://github.com/mamoe/mirai-console/issues/294
|
||||||
|
funB(funA());
|
||||||
|
|
||||||
File file = magic();
|
File file = magic();
|
||||||
Contact contact = magic();
|
Contact contact = magic();
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package test;
|
|||||||
import net.mamoe.mirai.console.command.Command;
|
import net.mamoe.mirai.console.command.Command;
|
||||||
import net.mamoe.mirai.console.command.CommandOwner;
|
import net.mamoe.mirai.console.command.CommandOwner;
|
||||||
import net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunction;
|
import net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunction;
|
||||||
|
import net.mamoe.mirai.console.command.java.JCompositeCommand;
|
||||||
import net.mamoe.mirai.console.command.java.JSimpleCommand;
|
import net.mamoe.mirai.console.command.java.JSimpleCommand;
|
||||||
import net.mamoe.mirai.console.permission.Permission;
|
import net.mamoe.mirai.console.permission.Permission;
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
|
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
|
||||||
@ -28,3 +29,16 @@ class TestCommand extends JSimpleCommand {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestCommand2 extends JCompositeCommand {
|
||||||
|
public TestCommand2(@NotNull CommandOwner owner, @NotNull String primaryName, @NotNull String[] secondaryNames, @NotNull Permission parentPermission) {
|
||||||
|
super(owner, primaryName, secondaryNames, parentPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubCommand("test")
|
||||||
|
public void test() {}
|
||||||
|
|
||||||
|
@SubCommand({})
|
||||||
|
public void subCmd() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -96,16 +96,21 @@ fun KtFunction.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtLightMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|
||||||
|
fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
||||||
if (functionSignature.name != null) {
|
if (functionSignature.name != null) {
|
||||||
if (this.name != functionSignature.name) return false
|
if (this.name != functionSignature.name) return false
|
||||||
}
|
}
|
||||||
val parameters = parameterList.parameters.toMutableList()
|
val parameters = parameterList.parameters.toMutableList()
|
||||||
if (functionSignature.dispatchReceiver != null) {
|
if (functionSignature.dispatchReceiver != null) {
|
||||||
val kotlinContainingClassFqn =
|
val containingClass = this.containingClass ?: return false
|
||||||
|
|
||||||
|
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 this.containingClass.getKotlinFqName()
|
} else containingClass.getKotlinFqName()
|
||||||
|
} else containingClass.getKotlinFqName()
|
||||||
|
|
||||||
if (kotlinContainingClassFqn != functionSignature.dispatchReceiver) return false
|
if (kotlinContainingClassFqn != functionSignature.dispatchReceiver) return false
|
||||||
}
|
}
|
||||||
if (functionSignature.extensionReceiver != null) {
|
if (functionSignature.extensionReceiver != null) {
|
||||||
@ -121,12 +126,6 @@ fun KtLightMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiMethod.hasSignature(functionSignature: FunctionSignature): Boolean {
|
|
||||||
if (this is KtLightMethod) {
|
|
||||||
return this.hasSignature(functionSignature)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KtExpression.isCalling(functionSignature: FunctionSignature): Boolean {
|
fun KtExpression.isCalling(functionSignature: FunctionSignature): Boolean {
|
||||||
val descriptor = resolveToCall(BodyResolveMode.PARTIAL)?.resultingDescriptor ?: return false
|
val descriptor = resolveToCall(BodyResolveMode.PARTIAL)?.resultingDescriptor ?: return false
|
||||||
|
Loading…
Reference in New Issue
Block a user