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

import com.intellij.psi.PsiElement;
import com.intellij.structuralsearch.impl.matcher.MatchContext;

/**
 * @author Maxim.Mossienko
 */
public class ScriptPredicate extends AbstractStringBasedPredicate {
  private final ScriptSupport scriptSupport;

  public ScriptPredicate(String name, String within) {
    super(name, within);
    scriptSupport = new ScriptSupport(within, name);
  }

  public boolean match(PsiElement node, PsiElement match, int start, int end, MatchContext context) {
    if (match == null) return false;

    return Boolean.TRUE.equals(
      Boolean.valueOf(scriptSupport.evaluate(
        context.hasResult() ? context.getResult() : null,
        match
      ))
    );
  }

}