summaryrefslogtreecommitdiff
path: root/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/predicates/FormalArgTypePredicate.java
blob: 02f1ee7d08e05a912f73ef5eaf0bde8cb3814290 (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
34
35
36
37
38
package com.intellij.structuralsearch.impl.matcher.predicates;

import com.intellij.structuralsearch.impl.matcher.MatchContext;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;

/**
 * Created by IntelliJ IDEA.
 * User: Maxim.Mossienko
 * Date: Mar 23, 2004
 * Time: 6:37:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class FormalArgTypePredicate extends ExprTypePredicate {

  public FormalArgTypePredicate(String type, String baseName, boolean _withinHierarchy, boolean caseSensitiveMatch,boolean target) {
    super(type, baseName, _withinHierarchy, caseSensitiveMatch, target);
  }

  protected PsiType evalType(PsiExpression match, MatchContext context) {
    final PsiMethodCallExpression expr = PsiTreeUtil.getParentOfType(match,PsiMethodCallExpression.class);
    if (expr == null) return null;

    // find our parent in parameters of the method
    final PsiMethod psiMethod = expr.resolveMethod();
    if (psiMethod == null) return null;
    final PsiParameter[] methodParameters = psiMethod.getParameterList().getParameters();
    final PsiExpression[] expressions = expr.getArgumentList().getExpressions();

    for(int i = 0;i < methodParameters.length; ++i) {
      if (expressions[i] == match) {
        if (i < methodParameters.length) return methodParameters[i].getType();
        break;
      }
    }
    return null;
  }
}