mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-91665 (highlight extension methods outside interfaces)
This commit is contained in:
+8
-3
@@ -850,16 +850,21 @@ public class HighlightMethodUtil {
|
||||
static HighlightInfo checkMethodCanHaveBody(PsiMethod method) {
|
||||
if (method.getBody() == null) return null;
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
boolean isInterface = aClass != null && aClass.isInterface();
|
||||
boolean isExtension = PsiUtil.isExtensionMethod(method);
|
||||
|
||||
String message = null;
|
||||
if (aClass != null && aClass.isInterface()) {
|
||||
if (!PsiUtil.isExtensionMethod(method)) {
|
||||
if (isInterface) {
|
||||
if (!isExtension) {
|
||||
message = JavaErrorMessages.message("interface.methods.cannot.have.body");
|
||||
}
|
||||
else {
|
||||
return HighlightUtil.checkExtensionMethodsFeature(method);
|
||||
}
|
||||
}
|
||||
else if (isExtension) {
|
||||
message = JavaErrorMessages.message("extension.method.in.class");
|
||||
}
|
||||
else if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
message = JavaErrorMessages.message("abstract.methods.cannot.have.a.body");
|
||||
}
|
||||
@@ -871,7 +876,7 @@ public class HighlightMethodUtil {
|
||||
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
|
||||
HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, message);
|
||||
QuickFixAction.registerQuickFixAction(info, new DeleteMethodBodyFix(method));
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT) && aClass != null && !aClass.isInterface()) {
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT) && isInterface) {
|
||||
IntentionAction fix = QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false);
|
||||
QuickFixAction.registerQuickFixAction(info, fix);
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ incompatible.types.html.tooltip=\
|
||||
interface.methods.cannot.have.body=Interface methods cannot have body
|
||||
abstract.methods.cannot.have.a.body=Abstract methods cannot have a body
|
||||
native.methods.cannot.have.a.body=Native methods cannot have a body
|
||||
extension.method.in.class=Extension methods can only be used within an interface
|
||||
|
||||
instance.method.cannot.override.static.method=Instance method ''{0}'' in ''{1}'' cannot override static method ''{2}'' in ''{3}''
|
||||
static.method.cannot.override.instance.method=Static method ''{0}'' in ''{1}'' cannot override instance method ''{2}'' in ''{3}''
|
||||
|
||||
+4
@@ -43,4 +43,8 @@ class C {
|
||||
}
|
||||
}.m();
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
<error descr="Extension methods can only be used within an interface">void m()</error> default { }
|
||||
}
|
||||
Reference in New Issue
Block a user