summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/ReferencePredicate.java
blob: 17570ed8f5df8b926364976d58051a6a0edc0795 (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
package com.intellij.structuralsearch.impl.matcher.predicates;

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

/**
 * Handles finding method
 */
public final class ReferencePredicate extends SubstitutionHandler {
  public ReferencePredicate(String _name) {
    super(_name, true, 1, 1, true);
  }

  public boolean match(PsiElement node, PsiElement match, MatchContext context) {
    if (StructuralSearchUtil.isIdentifier(match)) {
      // since we pickup tokens
      match = match.getParent();
    }

    PsiElement result = MatchUtils.getReferencedElement(match);
    if (result == null) {
      result = match;
      //return false;
    }

    return handle(result,context);
  }
}