mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: improve annotation name value pair matching
This commit is contained in:
+9
-13
@@ -321,18 +321,14 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
|
||||
@Override
|
||||
public void visitNameValuePair(PsiNameValuePair pair) {
|
||||
final PsiIdentifier nameIdentifier = pair.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
myMatchingVisitor.setResult(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiNameValuePair elementNameValuePair = (PsiNameValuePair)myMatchingVisitor.getElement();
|
||||
PsiIdentifier matchedNameValuePair = elementNameValuePair.getNameIdentifier();
|
||||
final PsiIdentifier otherIdentifier = elementNameValuePair.getNameIdentifier();
|
||||
|
||||
PsiAnnotationMemberValue annotationInitializer = pair.getValue();
|
||||
final PsiAnnotationMemberValue annotationInitializer = pair.getValue();
|
||||
if (annotationInitializer != null) {
|
||||
boolean isTypedInitializer = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(annotationInitializer) &&
|
||||
annotationInitializer instanceof PsiReferenceExpression;
|
||||
final boolean isTypedInitializer = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(annotationInitializer) &&
|
||||
annotationInitializer instanceof PsiReferenceExpression;
|
||||
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.match(annotationInitializer, elementNameValuePair.getValue()) ||
|
||||
(isTypedInitializer &&
|
||||
@@ -344,13 +340,13 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
|
||||
final MatchingHandler handler = myMatchingVisitor.getMatchContext().getPattern().getHandler(nameIdentifier);
|
||||
|
||||
if (handler instanceof SubstitutionHandler) {
|
||||
myMatchingVisitor
|
||||
.setResult(((SubstitutionHandler)handler).handle(matchedNameValuePair,
|
||||
myMatchingVisitor.getMatchContext()));
|
||||
myMatchingVisitor.setResult(((SubstitutionHandler)handler).handle(otherIdentifier, myMatchingVisitor.getMatchContext()));
|
||||
}
|
||||
else if (nameIdentifier != null) {
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.match(nameIdentifier, otherIdentifier));
|
||||
}
|
||||
else {
|
||||
myMatchingVisitor
|
||||
.setResult(myMatchingVisitor.match(nameIdentifier, matchedNameValuePair));
|
||||
myMatchingVisitor.setResult(otherIdentifier == null || otherIdentifier.getText().equals("value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -2288,14 +2288,19 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
"@MyBean2(\"\")\n" +
|
||||
"public class TestBean {}\n" +
|
||||
"@MyBean2(\"\")\n" +
|
||||
"@MyBean(\"\")\n" +
|
||||
"@MyBean(value=\"\")\n" +
|
||||
"public class TestBean2 {}\n" +
|
||||
"public class TestBean3 {}\n";
|
||||
"public class TestBean3 {}\n" +
|
||||
"@MyBean(\"a\")\n" +
|
||||
"@MyBean2(\"a\")\n" +
|
||||
"public class TestBean4";
|
||||
String s2 = "@MyBean(\"\")\n" +
|
||||
"@MyBean2(\"\")\n" +
|
||||
"public class $a$ {}\n";
|
||||
|
||||
assertEquals("Simple find annotated class",2,findMatchesCount(s1,s2,false));
|
||||
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(\"????????? ?????????? ? ??\")\n" +
|
||||
"public class TestBean\n" +
|
||||
|
||||
Reference in New Issue
Block a user