summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/WritePredicate.java
blob: e0d86824a920cfc996a6c0d8880ba5254bf8962f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.intellij.structuralsearch.impl.matcher.predicates;

import com.intellij.psi.*;
import com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate;
import com.intellij.structuralsearch.impl.matcher.MatchContext;
import com.intellij.structuralsearch.impl.matcher.MatchUtils;

/**
 * Handler for reading
 */
public final class WritePredicate extends MatchPredicate {
  public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
    if (matchedNode instanceof PsiIdentifier) {
      matchedNode = matchedNode.getParent();
    }
    if (( matchedNode instanceof PsiReferenceExpression &&
          matchedNode.getParent() instanceof PsiAssignmentExpression &&
          ((PsiAssignmentExpression)matchedNode.getParent()).getLExpression() == matchedNode &&
          MatchUtils.getReferencedElement(matchedNode) instanceof PsiVariable
        ) ||
        (
          matchedNode instanceof PsiVariable &&
          ((PsiVariable)matchedNode).getInitializer()!=null
        ) ||
        matchedNode.getParent() instanceof PsiPostfixExpression ||
        matchedNode.getParent() instanceof PsiPrefixExpression
       ) {
      return true;
    } else {
      return false;
    }
  }
}