mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: improved matching for annotation array value (IDEA-292608)
GitOrigin-RevId: 8d843f3e7b08c8e54e0a6c52e252d9179b783b3e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f853c0acbb
commit
1eb79a33c4
+13
-7
@@ -297,8 +297,10 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
|
||||
if (nameIdentifier != null) context.pushResult();
|
||||
final PsiIdentifier otherIdentifier = other.getNameIdentifier();
|
||||
try {
|
||||
final PsiAnnotationMemberValue value = pair.getValue();
|
||||
if (myMatchingVisitor.setResult(myMatchingVisitor.match(value, other.getValue()))) {
|
||||
final PsiAnnotationMemberValue value1 = pair.getValue();
|
||||
final PsiAnnotationMemberValue value2 = other.getValue();
|
||||
if (myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(getElementToMatch(value1), getElementToMatch(value2)) ||
|
||||
value1 instanceof PsiReferenceExpression && myMatchingVisitor.match(value1, value2))) {
|
||||
if (nameIdentifier != null) {
|
||||
myMatchingVisitor.setResult(isTypedVar ||
|
||||
myMatchingVisitor.matchText(nameIdentifier.getText(),
|
||||
@@ -324,11 +326,15 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAnnotationArrayInitializer(@NotNull PsiArrayInitializerMemberValue initializer) {
|
||||
final PsiArrayInitializerMemberValue otherInitializer = (PsiArrayInitializerMemberValue)myMatchingVisitor.getElement();
|
||||
final PsiAnnotationMemberValue[] initializers = initializer.getInitializers();
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.matchSequentially(initializers, otherInitializer.getInitializers()));
|
||||
private static PsiElement getElementToMatch(PsiAnnotationMemberValue value) {
|
||||
if (value instanceof PsiArrayInitializerMemberValue) {
|
||||
PsiArrayInitializerMemberValue arrayInitializer = (PsiArrayInitializerMemberValue)value;
|
||||
PsiAnnotationMemberValue[] initializers = arrayInitializer.getInitializers();
|
||||
if (initializers.length > 0) {
|
||||
return initializers[0];
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private boolean checkHierarchy(PsiMember element, PsiMember patternElement) {
|
||||
|
||||
+21
@@ -1893,6 +1893,27 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
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 {\n" +
|
||||
" String[] value() default {};\n" +
|
||||
" }\n" +
|
||||
" @Annotation(\"Hello\")\n" +
|
||||
" static void singleValue() {}\n" +
|
||||
" @Annotation({\"Hello\"})\n" +
|
||||
" static void multiValue() {}\n" +
|
||||
" @Annotation(value = \"Hello\")\n" +
|
||||
" static void explicitSingleValue() {}\n" +
|
||||
" @Annotation(value = {\"Hello\"})\n" +
|
||||
" static void explicitMultiValue() {}\n" +
|
||||
" @Annotation({\"Hello\", \"World\"})\n" +
|
||||
" static void different() {}\n" +
|
||||
" @Annotation(\"Bye!\")\n" +
|
||||
" static void end() {}\n" +
|
||||
"}";
|
||||
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)"));
|
||||
}
|
||||
|
||||
public void testBoxingAndUnboxing() {
|
||||
|
||||
Reference in New Issue
Block a user