Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/annotations/receiverParameters.java
Anna Kozlova 575105fada [java] forbid receiver parameters in annotation methods (IDEA-280218)
GitOrigin-RevId: befe655ef06c47f48e8de5c696bbd8ae28b4f7be
2021-10-15 08:41:09 +00:00

60 lines
2.2 KiB
Java

import java.lang.annotation.*;
@interface A { }
@Target(ElementType.TYPE_USE)
@interface TA { }
class C {
@Override
public String toString(@TA C this) { return ""; }
@Override
public boolean equals(@TA C this, @TA Object other) { return false; }
@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>) -> { };
}
void m1a(<error descr="Modifier 'final' not allowed here">final</error> C this) { }
void m1b(<error descr="'@A' not applicable to type use">@A</error> C this) { }
void m2(@TA Object other, @TA C <error descr="The receiver should be the first parameter">this</error>) { }
void m2b(//comment
@TA C this) { }
void m3a(@TA <error descr="The receiver type does not match the enclosing class type">Object</error> this) { }
void m3b(@TA <error descr="The receiver type does not match the enclosing class type">int</error> this) { }
void m4a(C C.this) { }
void m4b(C <error descr="The receiver name does not match the enclosing class type">C.X.this</error>) { }
void m5() {
class L {
L(C C.this) { }
}
}
static void sm1(@TA Object <error descr="The receiver cannot be used in a static context">this</error>) { }
C(C <error descr="The receiver cannot be used in a static context">this</error>) { }
static class X {
X(X <error descr="The receiver cannot be used in a static context">this</error>) { }
}
class B {
B(C C.this) { }
B(<error descr="The receiver type does not match the enclosing class type">B</error> C.this, int p) { }
B(C <error descr="The receiver name does not match the enclosing class type">B.this</error>, long p) { }
B(C <error descr="The receiver name does not match the enclosing class type">this</error>, float p) { }
}
static class CI<T> {
void m1(CI<T> this) { }
<T> void m2(<error descr="The receiver type does not match the enclosing class type">CI<T></error> this) { }
void m3(<error descr="The receiver type does not match the enclosing class type">CI<String></error> this) { }
}
}