mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[unused declaration] special treatment for kotlin callable parameters (IDEA-295201)
GitOrigin-RevId: a0e943f2874b8149dd7aadbba1b1dc6ceb808286
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc8f83c8c7
commit
6e59e68a61
@@ -13,7 +13,6 @@ import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -207,7 +206,7 @@ public class RefJavaUtilImpl extends RefJavaUtil {
|
||||
psiResolved = ((UUnaryExpression)node).resolveOperator();
|
||||
}
|
||||
if (psiResolved == null) {
|
||||
psiResolved = tryFindKotlinParameter(node, decl);
|
||||
psiResolved = tryFindKotlinParameter(node);
|
||||
}
|
||||
|
||||
RefElement refResolved;
|
||||
@@ -410,18 +409,11 @@ public class RefJavaUtilImpl extends RefJavaUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiElement tryFindKotlinParameter(@NotNull UExpression node, @NotNull UElement decl) {
|
||||
//TODO see KT-25524
|
||||
private static PsiElement tryFindKotlinParameter(@NotNull UExpression node) {
|
||||
if (node instanceof UCallExpression && "invoke".equals(((UCallExpression)node).getMethodName())) {
|
||||
UIdentifier identifier = ((UCallExpression)node).getMethodIdentifier();
|
||||
if (identifier != null) {
|
||||
String name = identifier.getName();
|
||||
if (decl instanceof UMethod) {
|
||||
UParameter parameter = ContainerUtil.find(((UMethod)decl).getUastParameters(), p -> name.equals(p.getName()));
|
||||
if (parameter != null) {
|
||||
return parameter.getSourcePsi();
|
||||
}
|
||||
}
|
||||
UExpression receiver = ((UCallExpression)node).getReceiver();
|
||||
if (receiver instanceof UResolvable) {
|
||||
return ((UResolvable)receiver).resolve();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
|
||||
<problem>
|
||||
<file>TC.kt</file>
|
||||
<line>1</line>
|
||||
<entry_point TYPE="class" FQNAME="TC"/>
|
||||
<description>Class is not instantiated.</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>TC.kt</file>
|
||||
<line>3</line>
|
||||
<entry_point TYPE="method" FQNAME="TC void fooBar(kotlin.jvm.functions.Function1<? super java.lang.String,kotlin.Unit> edit)"/>
|
||||
<description><ul><li>Method owner class is never instantiated OR</li><li>An instantiation is not reachable from entry points.</li></ul>
|
||||
</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>TC.kt</file>
|
||||
<line>7</line>
|
||||
<entry_point TYPE="method" FQNAME="TC void runWriteActionAndWait(kotlin.jvm.functions.Function0<? extends T> action)"/>
|
||||
<description>Parameter <code>action</code> is not used</description>
|
||||
</problem>
|
||||
|
||||
|
||||
</problems>
|
||||
@@ -0,0 +1,8 @@
|
||||
class TC {
|
||||
|
||||
fun fooBar(edit: (String) -> Unit) {
|
||||
runWriteActionAndWait { edit("") }
|
||||
}
|
||||
|
||||
inline fun <T> runWriteActionAndWait(crossinline action: () -> T) {}
|
||||
}
|
||||
@@ -59,6 +59,12 @@ public class UnusedDeclarationKtTest20 extends AbstractUnusedDeclarationTest {
|
||||
doTest("deadCode/" + getTestName(true), myToolWrapper);
|
||||
}
|
||||
|
||||
public void testCallableParameter() {
|
||||
myTool.getSharedLocalInspectionTool().PARAMETER = true;
|
||||
myTool.getSharedLocalInspectionTool().LOCAL_VARIABLE = false;
|
||||
doTest("deadCode/" + getTestName(true), myToolWrapper);
|
||||
}
|
||||
|
||||
public void testStaticMethods() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user