[java] forbid receiver parameters in annotation methods (IDEA-280218)

GitOrigin-RevId: befe655ef06c47f48e8de5c696bbd8ae28b4f7be
This commit is contained in:
Anna Kozlova
2021-10-15 08:41:09 +00:00
committed by intellij-monorepo-bot
parent df4439ba6c
commit 575105fada
2 changed files with 3 additions and 2 deletions
@@ -3248,7 +3248,8 @@ public final class HighlightUtil {
static HighlightInfo checkAnnotationMethodParameters(@NotNull PsiParameterList list) {
final PsiElement parent = list.getParent();
if (PsiUtil.isAnnotationMethod(parent) && !list.isEmpty()) {
if (PsiUtil.isAnnotationMethod(parent) &&
(!list.isEmpty() || PsiTreeUtil.getChildOfType(list, PsiReceiverParameter.class) != null)) {
final String message = JavaErrorBundle.message("annotation.interface.members.may.not.have.parameters");
final HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(message).create();
@@ -12,7 +12,7 @@ class C {
@Override
public boolean equals(@TA C this, @TA Object other) { return false; }
@interface Anno { String f(Anno this); }
@interface Anno { String f<error descr="@interface members may not have parameters">(Anno this)</error>; }
void m0() {
Runnable r = (C <error descr="Receivers are not allowed outside of method parameter list">C.this</error>) -> { };