package com.intellij.structuralsearch.impl.matcher.filters;

import com.intellij.dupLocator.util.NodeFilter;
import com.intellij.psi.PsiElement;
import com.intellij.structuralsearch.StructuralSearchProfile;
import com.intellij.structuralsearch.StructuralSearchUtil;

/**
 * Filter for lexical nodes
 */
public final class LexicalNodesFilter  implements NodeFilter {
  private boolean careKeyWords;
  private boolean result;

  private LexicalNodesFilter() {}

  public static NodeFilter getInstance() {
    return NodeFilterHolder.instance;
  }

  public boolean getResult() {
    return result;
  }

  public void setResult(boolean result) {
    this.result = result;
  }

  private static class NodeFilterHolder {
    private static final NodeFilter instance = new LexicalNodesFilter();
  }

  public boolean isCareKeyWords() {
    return careKeyWords;
  }

  public void setCareKeyWords(boolean careKeyWords) {
    this.careKeyWords = careKeyWords;
  }

  public boolean accepts(PsiElement element) {
    result = false;
    if (element!=null) {
      final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(element);
      if (profile != null) {
        element.accept(profile.getLexicalNodesFilter(this));
      }
    }
    return result;
  }
}

@@ -334,17 +334,16 @@
 sFilter 
- 
 implemen
@@ -358,16 +358,17 @@
 ilter %7B%0A
+%0A
   privat
@@ -369,23 +369,42 @@
 private 
-b
+final ThreadLocal%3CB
 oolean
+%3E
  careKey
@@ -412,34 +412,297 @@
 ords
-;%0A  private b
+ = new ThreadLocal%3CBoolean%3E() %7B%0A    @Override%0A    protected Boolean initialValue() %7B%0A      return Boolean.FALSE;%0A    %7D%0A  %7D;%0A  private final ThreadLocal%3CB
 oolean
+%3E
  result
+ = new ThreadLocal%3CBoolean%3E() %7B%0A    @Override%0A    protected Boolean initialValue() %7B%0A      return Boolean.FALSE;%0A    %7D%0A  %7D
 ;%0A%0A 
@@ -865,24 +865,45 @@
 eturn result
+.get().booleanValue()
 ;%0A  %7D%0A%0A  pub
@@ -958,17 +958,37 @@
 sult
- = 
+.set(Boolean.valueOf(
 result
+))
 ;%0A  
@@ -1161,32 +1161,53 @@
 urn careKeyWords
+.get().booleanValue()
 ;%0A  %7D%0A%0A  public 
@@ -1272,19 +1272,37 @@
 KeyWords
- = 
+.set(Boolean.valueOf(
 careKeyW
@@ -1305,16 +1305,18 @@
 KeyWords
+))
 ;%0A  %7D%0A%0A 
@@ -1375,16 +1375,27 @@
 sult
- = false
+.set(Boolean.FALSE)
 ;%0A  
@@ -1617,24 +1617,24 @@
     %7D%0A    %7D%0A
-
     return r
@@ -1638,16 +1638,37 @@
 n result
+.get().booleanValue()
 ;%0A  %7D%0A%7D%0A

fix race condition (IDEA-137556)