[java-highlighting] IDEA-378880 False compilation error in a compact source file

- disable correction by scope for classes inside compact source files


(cherry picked from commit 44831301a6c14f60d26ae4715df18c4cd24e1ee8)

IJ-CR-175022

GitOrigin-RevId: 7240e79a4db2222006d0c32fdab7e38d4b167dde
This commit is contained in:
Mikhail Pyltsin
2025-09-09 11:50:22 +02:00
committed by intellij-monorepo-bot
parent 19ad203e9b
commit 773f837fff
4 changed files with 40 additions and 6 deletions

View File

@@ -90,12 +90,12 @@ public final class PsiSuperMethodUtil {
* For the multi-module projects which use different jdks or libraries,
* it's important to map e.g. super class hierarchy to the current jdk.
* <p>Example:</p>
* Suppose there is an abstract reader in a module with jdk 1.6 which inherits {@link Closeable} (no super interfaces!).
* Suppose there is an abstract reader in a module with jdk 1.6 which inherits {@link Closeable} (no super interfaces!).
* In another module with jdk 1.7+ an inheritor of this reader should implement {@link AutoCloseable} though.
*
* @param psiClass a class to remap
* @param resolveScope scope where class should be found
* @return remapped class or same, if no other candidates were found
*
* @param psiClass a class to remap
* @param resolveScope scope where class should be found
* @return remapped class or same, if no other candidates were found
*/
public static @Nullable PsiClass correctClassByScope(@NotNull PsiClass psiClass, @NotNull GlobalSearchScope resolveScope) {
String qualifiedName = psiClass.getQualifiedName();
@@ -107,7 +107,10 @@ public final class PsiSuperMethodUtil {
if (file == null || !file.getViewProvider().isPhysical()) {
return psiClass;
}
//it shouldn't be corrected because it is not inside indexes and doesn't have FQN
if (JavaImplicitClassUtil.isFileWithImplicitClass(file)) {
return psiClass;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return psiClass;

View File

@@ -0,0 +1,27 @@
void main() {
new A() { public void a() {}}.a();
new A.B() { public void a() {}}.b();
var user = new MyUser();
user.name = "test";
}
interface A {
void a();
interface B extends A {
default void b() {
a();
}
}
}
class Person{
public String name;
public int age;
}
class MyUser extends Person{
public String email;
public String password;
}

View File

@@ -280,6 +280,10 @@ class ImplicitClassHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
})
}
fun testInheritedMembers() {
doTest()
}
private fun doTest() {
myFixture.configureByFile(getTestName(false) + ".java")
myFixture.checkHighlighting()