mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86690 (highlight unqualified super expressions in extension methods)
This commit is contained in:
+15
-4
@@ -1324,10 +1324,21 @@ public class HighlightUtil {
|
||||
@Nullable
|
||||
public static HighlightInfo checkThisOrSuperExpressionInIllegalContext(PsiExpression expr,
|
||||
@Nullable PsiJavaCodeReferenceElement qualifier) {
|
||||
if (expr instanceof PsiSuperExpression && !(expr.getParent() instanceof PsiReferenceExpression)) {
|
||||
// like in 'Object o = super;'
|
||||
final int o = expr.getTextRange().getEndOffset();
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, o, o + 1, JavaErrorMessages.message("dot.expected.after.super.or.this"));
|
||||
if (expr instanceof PsiSuperExpression) {
|
||||
final PsiElement parent = expr.getParent();
|
||||
if (!(parent instanceof PsiReferenceExpression)) {
|
||||
// like in 'Object o = super;'
|
||||
final int o = expr.getTextRange().getEndOffset();
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, o, o + 1, JavaErrorMessages.message("dot.expected.after.super.or.this"));
|
||||
}
|
||||
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(expr)) {
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class);
|
||||
if (PsiUtil.isExtensionMethod(method) && qualifier == null) {
|
||||
//todo[r.sh] "Add qualifier" quick fix
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, parent, JavaErrorMessages.message("unqualified.super.disallowed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final PsiClass aClass;
|
||||
|
||||
@@ -198,6 +198,7 @@ not.a.statement=Not a statement
|
||||
incompatible.types=Incompatible types. Found: ''{1}'', required: ''{0}''
|
||||
valid.switch.selector.types=byte, char, short or int
|
||||
dot.expected.after.super.or.this='.' expected
|
||||
unqualified.super.disallowed=Unqualified super reference is not allowed in extension method
|
||||
|
||||
non.static.symbol.referenced.from.static.context=Non-static {0} ''{1}'' cannot be referenced from a static context
|
||||
private.symbol=''{0}'' has private access in ''{1}''
|
||||
|
||||
+9
-1
@@ -16,11 +16,19 @@
|
||||
|
||||
class C {
|
||||
interface I {
|
||||
int i = 42;
|
||||
void m() default { }
|
||||
}
|
||||
|
||||
interface II extends I {
|
||||
void m() default { I.super.m(); }
|
||||
void m() default {
|
||||
I.super.m();
|
||||
<error descr="Unqualified super reference is not allowed in extension method">super.m</error>();
|
||||
|
||||
System.out.println(I.super.i);
|
||||
System.out.println<error descr="Cannot resolve method 'println(?)'">(<error descr="Unqualified super reference is not allowed in extension method">super.i</error>)</error>;
|
||||
}
|
||||
|
||||
void ma();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user