void () { String s1 = """ @MyBean("") @MyBean2("") public class TestBean {} @MyBean2("") @MyBean(value="") public class TestBean2 {} public class TestBean3 {} @MyBean("a") @MyBean2("a") public class TestBean4{}"""; String s2 = """ @MyBean("") @MyBean2("") public class '_a {} """; assertEquals("Simple find annotated class", 2, findMatchesCount(s1, s2)); assertEquals("Match value of anonymous name value pair 1", 1, findMatchesCount(s1, "@MyBean(\"a\") class '_a {}")); assertEquals("Match value of anonymous name value pair 2", 2, findMatchesCount(s1, "@MyBean(\"\") class '_a {}")); String s3 = """ @VisualBean("????????? ?????????? ? ??") public class TestBean { @VisualBeanField( name = "??? ????????????", initialValue = "?????????????" ) public String user; @VisualBeanField( name = "??????", initialValue = "", fieldType = FieldTypeEnum.PASSWORD_FIELD ) public String password; @VisualBeanField( initialValue = "User", name = "????? ???????", name = "Second name", fieldType = FieldTypeEnum.COMBOBOX_FIELD, comboValues = { @ComboFieldValue("Administrator"), @ComboFieldValue("User"), @ComboFieldValue("Guest")} ) public String accessRights; public String otherField; }"""; String s4 = """ class '_a { @'_Annotation+ ( 'AnnotationMember:name = '_AnnotationValue ) String '_field* ; }"""; assertEquals("Find annotation members of annotated field class", 4, findMatchesCount(s3, s4)); String s4_2 = """ class '_a { @'_Annotation+ () String 'field ; }"""; assertEquals("Find annotation fields", 3, findMatchesCount(s3, s4_2)); String s5 = """ class A { @NotNull private static Collection<PsiElement> resolveElements(final PsiReference reference, final Project project) {} @NotNull private static Collection resolveElements2(final PsiReference reference, final Project project) {} }"""; assertEquals("Find annotated methods", 2, findMatchesCount(s5, "class '_c {@NotNull '_rt 'method ('_pt '_p*){ '_inst*; } }")); assertEquals("Find annotated methods, 2", 2, findMatchesCount(s5, "class '_c {@'_:NotNull '_rt 'method ('_pt '_p*){ '_inst*; } }")); String s7 = """ class A { void message(@NonNls String msg); } class B { void message2(String msg); } class C { void message2(String msg); }"""; assertEquals("Find not annotated methods", 2, findMatchesCount(s7, "class '_A { void 'b( @'_Ann{0,0}:NonNls String '_); }")); String s9 = """ class A { Object[] method1() {} Object method1_2() {} Object method1_3() {} Object method1_4() {} @MyAnnotation Object[] method2(int a) {} @NonNls Object[] method3() {} }"""; assertEquals("Find not annotated methods, 2", 2, findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type:Object\\[\\] 'b( '_pt '_p* ); }")); assertEquals("Find not annotated methods, 2", 2, findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type [] 'b( '_pt '_p* ); }")); assertEquals("Find not annotated methods, 2", 2, findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type:Object [] 'b( '_pt '_p* ); }")); String s11 = """ class A { @Foo(value=baz) int a; @Foo(value=baz2) int a2; @Foo(baz2) int a3; @Foo(value2=baz2) int a4; @Foo(value2=baz2) int a5; @Foo(value2=baz3) int a6; @Foo(value2=baz3) int a7; @Foo(value2=baz3) int a8; @Foo(value2=baz4) int a9; @Foo int a10; }"""; assertEquals("Find anno parameter value 1", 1, findMatchesCount(s11, "@Foo(value=baz) int 'a;")); assertEquals("Find anno parameter value 2", 2, findMatchesCount(s11, "@Foo(value='_value:baz2 ) int '_a;")); assertEquals("Find anno parameter value 3", 2, findMatchesCount(s11, "@Foo('_name:value ='_value:baz2 ) int '_a;")); assertEquals("Find anno parameter value 4", 3, findMatchesCount(s11, "@Foo('_name:value2 = baz3 ) int '_a;")); assertEquals("Find anno parameter value 5", 3, findMatchesCount(s11, "@Foo('_name:value2 = '_value:baz3 ) int '_a;")); assertEquals("Find anno parameter value 6", 0, findMatchesCount(s11, "@Foo('_name:value2 = '_value:baz ) int '_a;")); assertEquals("Find anno parameter value 7", 6, findMatchesCount(s11, "@Foo('_name:value2 = '_value ) int '_a;")); assertEquals("Find anno parameter value 8", 9, findMatchesCount(s11, "@Foo('_name = '_value ) int '_a;")); try { findMatchesCount(s11, "@Foo('_name:value2 = ) int '_a;"); fail("should report missing value"); } catch (MalformedPatternException ignored) {} assertEquals("Match anno parameter name", 6, findMatchesCount(s11, "@Foo(value2='_value)")); assertEquals("Match anno parameter name 2", 3, findMatchesCount(s11, "@Foo(value='_value)")); assertEquals("Match value anno parameter only", 2, findMatchesCount(s11, "@Foo(baz2)")); assertEquals("Match value anno parameters", 3, findMatchesCount(s11, "@Foo('_value)")); assertEquals("Match all annotations", 10, findMatchesCount(s11, "@Foo('_value?)")); assertEquals("Match all annotations 2", 10, findMatchesCount(s11, "@Foo")); assertEquals("Match annotations without parameters", 1, findMatchesCount(s11, "@Foo('_name{0,0}='_v)")); String s12 = "@X(value=1, x=2) @Y(1) @Z(x=0, y=0, z=0) @W(2) @V(x=0, y=0, z=0) class One {}"; assertEquals("Match annotations with two parameters", 1, findMatchesCount(s12, "@'_anno('_name{2,2}='_v)")); String source1 = """ class A { void m() { new @B Object(); } }"""; assertEquals("Find annotated new expression", 1, findMatchesCount(source1, "new Object()")); assertEquals("Find annotated new expression", 1, findMatchesCount(source1, "new @B Object()")); assertEquals("Find annotated new expression", 0, findMatchesCount(source1, "new @C Object()")); String source2 = """ @X class A { @Y int value; @Y int m(@Z int i) { return 1; } } """; assertEquals("Find all annotations", 4, findMatchesCount(source2, "@'_Annotation")); String source3 = """ class A<@HH T> extends @HH Object { @HH final String s = (@HH String) new @HH Object(); final String t = (String) new Object(); Map<@HH String, @HH List<@HH String>> map; } """; assertEquals("Find annotated casts", 1, findMatchesCount(source3, "(@'_A 'Cast) '_Expression")); assertEquals("Find annotated new expressions", 1, findMatchesCount(source3, "new @'_A 'Type()")); assertEquals("Find all annotations 2", 8, findMatchesCount(source3, "@'_Annotation")); // package-info.java final String source4 = """ /** * documentation */ @Deprecated package one.two;"""; assertEquals("Find annotation on package statement", 1, findMatchesCount(source4, "@'_Annotation")); final String source5 = """ class A { boolean a(Object o) { return o instanceof @HH String; } }"""; assertEquals("Find annotation on instanceof expression", 1, findMatchesCount(source5, "'_a instanceof @HH String")); assertEquals("Match annotation correctly on instanceof expression", 0, findMatchesCount(source5, "'_a instanceof @GG String")); String source6 = """ @SuppressWarnings({"WeakerAccess", "unused", "UnnecessaryInterfaceModifier"}) class A { @SuppressWarnings({"unused"}) @NotNull int i; }"""; assertEquals("Find SuppressWarnings annotations", 2, findMatchesCount(source6, "@SuppressWarnings")); assertEquals("Find SuppressWarnings annotations", 2, findMatchesCount(source6, "@SuppressWarnings(value='_any)")); assertEquals("Find annotation with 3 value array initializer", 1, findMatchesCount(source6, "@SuppressWarnings({'_value{3,3} })")); String source7 = """ class X { @interface Annotation { String[] value() default {}; } @Annotation("Hello") static void singleValue() {} @Annotation({"Hello"}) static void multiValue() {} @Annotation(value = "Hello") static void explicitSingleValue() {} @Annotation(value = {"Hello"}) static void explicitMultiValue() {} @Annotation({"Hello", "World"}) static void different() {} @Annotation("Bye!") static void end() {} }"""; assertEquals("Find all equivalent annotations", 4, findMatchesCount(source7, "@Annotation(\"Hello\")")); assertEquals("Find all annotations with a specific value", 5, findMatchesCount(source7, "@Annotation({\"Hello\", '_O*})")); assertEquals("Find all annotations", 6, findMatchesCount(source7, "@Annotation('_V)")); String source8 = """ @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface NotNull {} class X { boolean a(@NotNull String s, @NotNull String t, String u) { java.util.Objects.equals(s, t); return java.util.Objects.equals(t, u); } }"""; assertEquals("Call with @NotNull annotated argument", 1, findMatchesCount(source8, "Objects.equals('_a:[exprtype( ~@NotNull.* )], '_b:[exprtype( ~@NotNull.* )])")); assertEquals("Call with arguments with @NotNull String type", 1, findMatchesCount(source8, "Objects.equals('_a:[exprtype( @NotNull String )], '_b:[exprtype( @NotNull String )])")); }