mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: operator assignment is also read access
This commit is contained in:
+13
-11
@@ -10,19 +10,21 @@ import com.intellij.structuralsearch.impl.matcher.MatchUtils;
|
||||
*/
|
||||
public final class ReadPredicate extends MatchPredicate {
|
||||
public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
|
||||
PsiElement parent = matchedNode.getParent();
|
||||
if (matchedNode instanceof PsiIdentifier) {
|
||||
matchedNode = matchedNode.getParent();
|
||||
matchedNode = parent;
|
||||
parent = matchedNode.getParent();
|
||||
}
|
||||
if (matchedNode instanceof PsiReferenceExpression &&
|
||||
( !(matchedNode.getParent() instanceof PsiMethodCallExpression) &&
|
||||
( !(matchedNode.getParent() instanceof PsiAssignmentExpression) ||
|
||||
((PsiAssignmentExpression)matchedNode.getParent()).getLExpression() != matchedNode
|
||||
)
|
||||
) &&
|
||||
MatchUtils.getReferencedElement(matchedNode) instanceof PsiVariable
|
||||
) {
|
||||
return true;
|
||||
if (!(matchedNode instanceof PsiReferenceExpression) || parent instanceof PsiMethodCallExpression) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
if (assignmentExpression.getLExpression() == matchedNode &&
|
||||
assignmentExpression.getOperationTokenType() == JavaTokenType.EQ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return MatchUtils.getReferencedElement(matchedNode) instanceof PsiVariable;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -1233,6 +1233,21 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
"find sym finds declaration",
|
||||
2, findMatchesCount(s133_2, s134, true)
|
||||
);
|
||||
final String in = "class C {" +
|
||||
" {" +
|
||||
" int i = 0;" +
|
||||
" i += 1;" +
|
||||
" i = 3;" +
|
||||
" int j = i;" +
|
||||
" i();" +
|
||||
" }" +
|
||||
" void i() {}" +
|
||||
"}";
|
||||
final String pattern1 = "'_:[read]";
|
||||
assertEquals("Find reads of symbol (including operator assignment)", 2, findMatchesCount(in, pattern1));
|
||||
|
||||
final String pattern2 = "'_:[write && regex( i )]";
|
||||
assertEquals("Find writes of symbol", 3, findMatchesCount(in, pattern2));
|
||||
}
|
||||
|
||||
public void testSearchGenerics() {
|
||||
@@ -1900,14 +1915,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
|
||||
assertEquals(
|
||||
"fields of class read",
|
||||
findMatchesCount(s117,s118_2),
|
||||
2
|
||||
2,
|
||||
findMatchesCount(s117,s118_2)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
"fields of class written",
|
||||
findMatchesCount(s117,s118_3),
|
||||
2
|
||||
2,
|
||||
findMatchesCount(s117,s118_3)
|
||||
);
|
||||
|
||||
final String s119 = "try { a.b(); } catch(IOException e) { c(); } catch(Exception ex) { d(); }";
|
||||
|
||||
Reference in New Issue
Block a user