summaryrefslogtreecommitdiff
path: root/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/handlers/StatementHandler.java
blob: c6361e2ad4e7c936e6034aae56c7ad9c17b1a1b6 (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
package com.intellij.structuralsearch.impl.matcher.handlers;

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

/**
 * Handler for statement search
 */
public class StatementHandler extends MatchingHandler {

  public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
    // filtering is done on SubstituionHandler level
    if (patternNode==null) return false;
    patternNode = ((PsiExpressionStatement)patternNode).getExpression();

    /*if (matchedNode instanceof PsiExpressionStatement) {
      //matchedNode = ((PsiExpressionStatement)matchedNode).getExpression();
    } else*/ if (( !(matchedNode instanceof PsiStatement) &&
                 !(matchedNode instanceof PsiComment) // comments to be matched as statements
               ) ||
        ( matchedNode instanceof PsiBlockStatement &&
          !(matchedNode.getParent() instanceof PsiBlockStatement) &&
          !(matchedNode.getParent().getParent() instanceof PsiSwitchStatement)
        )) {
      // typed statement does not match this things
      // (BlockStatement could be nontop level in if, etc)
      return false;
    }

    return context.getMatcher().match(patternNode,matchedNode);
  }
}