summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/JavaMatchPredicateProvider.java
blob: 042912e0354c91ab93aea99a8682e742a8188f9c (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.intellij.structuralsearch.impl.matcher;

import com.intellij.openapi.util.text.StringUtil;
import com.intellij.structuralsearch.MatchOptions;
import com.intellij.structuralsearch.MatchVariableConstraint;
import com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate;
import com.intellij.structuralsearch.impl.matcher.predicates.*;

import java.util.Set;

public class JavaMatchPredicateProvider extends MatchPredicateProvider{
  @Override
  public void collectPredicates(MatchVariableConstraint constraint, String name, MatchOptions options, Set<MatchPredicate> predicates) {
    if (constraint.isReadAccess()) {
      MatchPredicate predicate = new ReadPredicate();

      if (constraint.isInvertReadAccess()) {
        predicate = new NotPredicate(predicate);
      }
      predicates.add(predicate);
    }

    if (constraint.isWriteAccess()) {
      MatchPredicate predicate = new WritePredicate();

      if (constraint.isInvertWriteAccess()) {
        predicate = new NotPredicate(predicate);
      }
      predicates.add(predicate);
    }

    if (!StringUtil.isEmptyOrSpaces(constraint.getNameOfExprType())) {
      MatchPredicate predicate = new ExprTypePredicate(
        constraint.getNameOfExprType(),
        name,
        constraint.isExprTypeWithinHierarchy(),
        options.isCaseSensitiveMatch(),
        constraint.isPartOfSearchResults()
      );

      if (constraint.isInvertExprType()) {
        predicate = new NotPredicate(predicate);
      }
      predicates.add(predicate);
    }

    if (!StringUtil.isEmptyOrSpaces(constraint.getNameOfFormalArgType())) {
      MatchPredicate predicate = new FormalArgTypePredicate(
        constraint.getNameOfFormalArgType(),
        name,
        constraint.isFormalArgTypeWithinHierarchy(),
        options.isCaseSensitiveMatch(),
        constraint.isPartOfSearchResults()
      );
      if (constraint.isInvertFormalType()) {
        predicate = new NotPredicate(predicate);
      }
      predicates.add(predicate);
    }

  }
}