[java] Properly get matching method arguments local classes in static methods

#IDEA-373584

GitOrigin-RevId: 04c8ee6bb7c8427afed171dfdd78b00ab5220a8d
This commit is contained in:
Bart van Helvert
2025-06-18 15:10:58 +00:00
committed by intellij-monorepo-bot
parent cd7be3977a
commit ae47e433b0
3 changed files with 17 additions and 1 deletions
@@ -186,7 +186,7 @@ public class JavaLangClassMemberReference extends PsiReferenceBase<PsiLiteralExp
private static int matchMethodArguments(PsiMethod method, List<ReflectiveType> argumentTypes) {
// Get nested classes because they need to be passed if not static
List<PsiClass> enclosingClasses = PsiTreeUtil.collectParents(method, PsiClass.class, false, parent -> {
return parent instanceof PsiFile || parent instanceof PsiClass cls && cls.hasModifier(JvmModifier.STATIC);
return parent instanceof PsiFile || (parent instanceof PsiModifierListOwner cls && cls.hasModifier(JvmModifier.STATIC));
});
if (!enclosingClasses.isEmpty()) {
// the containing class of the method doesn't need to be passed
@@ -0,0 +1,15 @@
class Constructors {
public static void testConstructorInStatic() throws Exception {
class X {
X(int i) {}
class Y {
Y() {}
Y(String a) {}
}
}
X.class.getDeclaredConstructor(int.class);
X.Y.class.getDeclaredConstructor(X.class);
X.Y.class.getDeclaredConstructor(X.class, String.class);
}
}
@@ -28,6 +28,7 @@ class JavaReflectionMemberAccessTest : LightJavaCodeInsightFixtureTestCase() {
fun testConstructorExists() = doTest(true)
fun testConstructorInnerClass() = doTest(true)
fun testConstructorLocalClass() = doTest(true)
fun testConstructorLocalClassInStaticMethod() = doTest(true)
fun testNewInstance() = doTest(true)
fun testBugs() = doTest(true)