Program: 130524
Project: 130524
Buggy source:
private static List<TextRange> collectDisabledBlocks(PsiFile templateFile,final List<String> baseVariables){
  final Ref<List<TextRange>> listRef=Ref.create();
  final Ref<List<String>> redefined=Ref.create();
  templateFile.accept(new CSharpMacroRecursiveElementVisitor(){
    @Override public void visitMacroDefine(    CSharpMacroDefine def){
      List<String> redefs=redefined.get();
      if (redefs == null) {
        redefined.set(redefs=new ArrayList<String>(baseVariables));
      }
      String name=def.getName();
      if (name != null) {
        if (def.isUnDef()) {
          redefs.remove(name);
        }
 else {
          redefs.add(name);
        }
      }
    }
    @Override public void visitMacroIf(    CSharpMacroIfImpl element){
      List<TextRange> textRanges=listRef.get();
      if (textRanges == null) {
        listRef.set(textRanges=new ArrayList<TextRange>());
      }
      CSharpMacroIfConditionBlockImpl[] conditionBlocks=element.getConditionBlocks();
      Queue<CSharpMacroIfConditionBlockImpl> queue=new ArrayDeque<CSharpMacroIfConditionBlockImpl>(conditionBlocks.length);
      Collections.addAll(queue,conditionBlocks);
      CSharpMacroIfConditionBlockImpl activeBlock=null;
      boolean forceDisable=false;
      CSharpMacroIfConditionBlockImpl block;
      while ((block=queue.poll()) != null) {
        CSharpMacroBlockStartImpl declarationTag=block.getDeclarationTag();
        if (forceDisable) {
          addTextRange(declarationTag,queue,element,textRanges);
          continue;
        }
        if (!declarationTag.isElse()) {
          CSharpMacroExpression value=declarationTag.getValue();
          if (value == null) {
            addTextRange(declarationTag,queue,element,textRanges);
          }
 else {
            String text=value.getText();
            if (isDefined(text)) {
              forceDisable=true;
              activeBlock=block;
            }
 else {
              addTextRange(declarationTag,queue,element,textRanges);
            }
          }
        }
 else {
          activeBlock=block;
        }
      }
      if (activeBlock != null) {
        activeBlock.accept(this);
      }
    }
    private void addTextRange(    CSharpMacroBlockStartImpl start,    Queue<CSharpMacroIfConditionBlockImpl> queue,    CSharpMacroIfImpl macroIf,    List<TextRange> textRanges){
      CSharpMacroIfConditionBlockImpl element=queue.peek();
      int endOffset;
      if (element == null) {
        CSharpMacroBlockStopImpl closeTag=macroIf.getCloseTag();
        if (closeTag == null) {
          endOffset=macroIf.getContainingFile().getTextLength();
        }
 else {
          endOffset=closeTag.getKeywordElement().getTextRange().getStartOffset();
        }
      }
 else {
        endOffset=element.getDeclarationTag().getKeywordElement().getTextRange().getStartOffset();
      }
      PsiElement stopElement=start.getStopElement();
      if (stopElement == null) {
        textRanges.add(new TextRange(start.getTextRange().getEndOffset(),endOffset));
      }
 else {
        textRanges.add(new TextRange(stopElement.getTextRange().getEndOffset(),endOffset));
      }
    }
    private boolean isDefined(    String text){
      List<String> defs=redefined.get();
      if (defs == null) {
        defs=baseVariables;
      }
      return !defs.isEmpty() && MacroEvaluator.evaluate(text,defs);
    }
  }
);
  List<TextRange> list=listRef.get();
  return list == null ? Collections.<TextRange>emptyList() : list;
}

Fixed version (ground truth):
private static List<TextRange> collectDisabledBlocks(PsiFile templateFile,final List<String> baseVariables){
  final Ref<List<TextRange>> listRef=Ref.create();
  final Ref<List<String>> redefined=Ref.create();
  templateFile.accept(new CSharpMacroRecursiveElementVisitor(){
    @Override public void visitMacroDefine(    CSharpMacroDefine def){
      List<String> redefs=redefined.get();
      if (redefs == null) {
        redefined.set(redefs=new ArrayList<String>(baseVariables));
      }
      String name=def.getName();
      if (name != null) {
        if (def.isUnDef()) {
          redefs.remove(name);
        }
 else {
          redefs.add(name);
        }
      }
    }
    @Override public void visitMacroIf(    CSharpMacroIfImpl element){
      List<TextRange> textRanges=listRef.get();
      if (textRanges == null) {
        listRef.set(textRanges=new ArrayList<TextRange>());
      }
      CSharpMacroIfConditionBlockImpl[] conditionBlocks=element.getConditionBlocks();
      Queue<CSharpMacroIfConditionBlockImpl> queue=new ArrayDeque<CSharpMacroIfConditionBlockImpl>(conditionBlocks.length);
      Collections.addAll(queue,conditionBlocks);
      CSharpMacroIfConditionBlockImpl activeBlock=null;
      boolean forceDisable=false;
      CSharpMacroIfConditionBlockImpl block;
      while ((block=queue.poll()) != null) {
        CSharpMacroBlockStartImpl declarationTag=block.getDeclarationTag();
        if (forceDisable) {
          addTextRange(declarationTag,queue,element,textRanges);
          continue;
        }
        if (!declarationTag.isElse()) {
          CSharpMacroExpression value=declarationTag.getValue();
          if (value == null) {
            addTextRange(declarationTag,queue,element,textRanges);
          }
 else {
            String text=value.getText();
            if (isDefined(text)) {
              forceDisable=true;
              activeBlock=block;
            }
 else {
              addTextRange(declarationTag,queue,element,textRanges);
            }
          }
        }
 else {
          activeBlock=block;
        }
      }
      if (activeBlock != null) {
        activeBlock.accept(this);
      }
    }
    private void addTextRange(    CSharpMacroBlockStartImpl start,    Queue<CSharpMacroIfConditionBlockImpl> queue,    CSharpMacroIfImpl macroIf,    List<TextRange> textRanges){
      CSharpMacroIfConditionBlockImpl element=queue.peek();
      int endOffset;
      if (element == null) {
        CSharpMacroBlockStopImpl closeTag=macroIf.getCloseTag();
        if (closeTag == null) {
          endOffset=macroIf.getContainingFile().getTextLength();
        }
 else {
          endOffset=closeTag.getKeywordElement().getTextRange().getStartOffset();
        }
      }
 else {
        endOffset=element.getDeclarationTag().getKeywordElement().getTextRange().getStartOffset();
      }
      PsiElement stopElement=start.getStopElement();
      if (stopElement == null) {
        textRanges.add(new TextRange(start.getTextRange().getEndOffset(),endOffset));
      }
 else {
        textRanges.add(new TextRange(stopElement.getTextRange().getEndOffset(),endOffset));
      }
    }
    private boolean isDefined(    String text){
      List<String> defs=redefined.get();
      if (defs == null) {
        defs=baseVariables;
      }
      return MacroEvaluator.evaluate(text,defs);
    }
  }
);
  List<TextRange> list=listRef.get();
  return list == null ? Collections.<TextRange>emptyList() : list;
}