mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java] report static interface field accessed via instance (IDEA-348722)
GitOrigin-RevId: f8b1b2036656ff5a4579dff82592e7bf4cfad8f9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
babfae316e
commit
b474e948e3
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection.accessStaticViaInstance;
|
||||
|
||||
import com.intellij.codeInsight.daemon.JavaErrorBundle;
|
||||
@@ -53,7 +53,7 @@ public class AccessStaticViaInstanceBase extends AbstractBaseJavaLocalInspection
|
||||
JavaResolveResult result = expr.advancedResolve(false);
|
||||
PsiElement resolved = result.getElement();
|
||||
|
||||
if (!(resolved instanceof PsiMember)) return;
|
||||
if (!(resolved instanceof PsiMember member)) return;
|
||||
PsiExpression qualifierExpression = expr.getQualifierExpression();
|
||||
if (qualifierExpression == null) return;
|
||||
|
||||
@@ -63,11 +63,11 @@ public class AccessStaticViaInstanceBase extends AbstractBaseJavaLocalInspection
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!((PsiMember)resolved).hasModifierProperty(PsiModifier.STATIC)) return;
|
||||
if (!member.hasModifierProperty(PsiModifier.STATIC)) return;
|
||||
|
||||
//don't report warnings on compilation errors
|
||||
PsiClass containingClass = ((PsiMember)resolved).getContainingClass();
|
||||
if (containingClass != null && containingClass.isInterface()) return;
|
||||
PsiClass containingClass = member.getContainingClass();
|
||||
if (containingClass != null && containingClass.isInterface() && member instanceof PsiMethod) return;
|
||||
if (containingClass instanceof PsiAnonymousClass || containingClass instanceof PsiImplicitClass) return;
|
||||
|
||||
String description = JavaErrorBundle.message("static.member.accessed.via.instance.reference",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Qualify static 'NAME' access with reference to class 'Grotesk'" "true-preview"
|
||||
class Dreadful implements Grotesk {
|
||||
void x() {
|
||||
System.out.println(Grotesk.NAME);
|
||||
}
|
||||
}
|
||||
interface Grotesk {
|
||||
String NAME = "Grotesk";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Qualify static 'NAME' access with reference to class 'Grotesk'" "true-preview"
|
||||
class Dreadful implements Grotesk {
|
||||
void x() {
|
||||
System.out.println(this<caret>.NAME);
|
||||
}
|
||||
}
|
||||
interface Grotesk {
|
||||
String NAME = "Grotesk";
|
||||
}
|
||||
Reference in New Issue
Block a user