summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/strategies/XmlMatchingStrategy.java
blob: b2ca87a176e846b0bb72ae746e8e00f56aaf8a22 (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.PsiElement;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.xml.XmlTag;

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

  @Override public void visitXmlTag(final XmlTag element) {
    result = true;
  }

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

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

  protected XmlMatchingStrategy() {}

  private static class XmlMatchingStrategyHolder {
    private static final XmlMatchingStrategy instance = new XmlMatchingStrategy();
  }

  public static MatchingStrategy getInstance() {
    return XmlMatchingStrategyHolder.instance;
  }

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