summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/MatchingStrategyBase.java
blob: df6e0fd468326768a7d17eb2715656d1a2ada5a2 (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
package com.intellij.structuralsearch.impl.matcher.strategies;

import com.intellij.dupLocator.util.NodeFilter;
import com.intellij.psi.*;

/**
 * Base filtering strategy to find statements
 */
public class MatchingStrategyBase extends JavaElementVisitor implements MatchingStrategy, NodeFilter {
  protected boolean result;

  @Override public void visitReferenceExpression(final PsiReferenceExpression psiReferenceExpression) {
    visitExpression(psiReferenceExpression);
  }

  @Override public void visitCodeBlock(final PsiCodeBlock block) {
    result = true;
  }
  
  @Override public void visitCatchSection(final PsiCatchSection section) {
    result = true;
  }

  @Override public void visitStatement(final PsiStatement statement) {
    result = true;
  }

  public boolean continueMatching(final PsiElement start) {
    return accepts(start);
  }

  @Override
  public boolean shouldSkip(PsiElement element, PsiElement elementToMatchWith) {
    return false;
  }

  public boolean accepts(PsiElement element) {
    result = false;
    if (element!=null) element.accept(this);
    return result;
  }
}