Program: 135970
Project: 135970
Buggy source:
/** 
 * Returns the   {@link LevelNode} in the tree rooted at levelNode that is the innermoststep such that lineNum is between the begin and end lines of the step or its proof. If there is more than one step or proof on lineNum, then this method returns the step that is first on lineNum (or whose proof is first on lineNum). Returns null if no such node found. Assumes that levelNode is one of {@link UseOrHideNode}{@link InstanceNode}{@link TheoremNode}{@link DefStepNode}If that is not true, this method returns null. In this example: line 10: <2>1. X line 11: \* The following proof is simple line 12:    <3>1. Y line 13:       OBVIOUS <3>2. Z if lineNum = 10, this method returns <2>1. If lineNum = 11, this method again returns <2>1. If lineNum = 12, this method returns <3>1. If lineNum = 13, this method again returns <3>1.
 * @param levelNode
 * @param lineNum
 * @return
 */
public static LevelNode getLevelNodeFromTree(LevelNode levelNode,int lineNum){
  int nodeBeginLine=levelNode.getLocation().beginLine();
  int nodeEndLine=0;
  if (levelNode instanceof TheoremNode) {
    nodeEndLine=((TheoremNode)levelNode).getTheorem().getLocation().endLine();
  }
 else   if (levelNode instanceof UseOrHideNode || levelNode instanceof InstanceNode || levelNode instanceof DefStepNode) {
    nodeEndLine=levelNode.getLocation().endLine();
  }
 else {
    return null;
  }
  if (nodeBeginLine <= lineNum && nodeEndLine >= lineNum) {
    return levelNode;
  }
  if (levelNode instanceof TheoremNode) {
    TheoremNode theoremNode=(TheoremNode)levelNode;
    ProofNode proof=theoremNode.getProof();
    if (proof != null) {
      Location proofLoc=proof.getLocation();
      if (lineNum >= nodeBeginLine && lineNum <= proofLoc.endLine()) {
        if (proof instanceof NonLeafProofNode) {
          NonLeafProofNode nonLeafProof=(NonLeafProofNode)proof;
          LevelNode[] steps=nonLeafProof.getSteps();
          for (int i=0; i < steps.length; i++) {
            LevelNode node=getLevelNodeFromTree(steps[i],lineNum);
            if (node != null) {
              return node;
            }
          }
          return levelNode;
        }
 else {
          return levelNode;
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Returns the   {@link LevelNode} in the tree rooted at levelNode that is the innermoststep such that lineNum is between the begin line of the step and the end line of the proof if there is a proof or the begin and end lines of the step if there is no proof. If there is more than one step or proof on lineNum, then this method returns the step that is first on lineNum (or whose proof is first on lineNum). Returns null if no such node found. Assumes that levelNode is one of {@link UseOrHideNode}{@link InstanceNode}{@link TheoremNode}{@link DefStepNode}If that is not true, this method returns null. In this example: line 10: <2>1. X line 11: \* The following proof is simple line 12:    <3>1. Y line 13:       OBVIOUS <3>2. Z if lineNum = 10, this method returns <2>1. If lineNum = 11, this method again returns <2>1. If lineNum = 12, this method returns <3>1. If lineNum = 13, this method again returns <3>1.
 * @param levelNode
 * @param lineNum
 * @return
 */
public static LevelNode getLevelNodeFromTree(LevelNode levelNode,int lineNum){
  int nodeBeginLine=levelNode.getLocation().beginLine();
  int nodeEndLine=0;
  if (levelNode instanceof TheoremNode) {
    nodeEndLine=((TheoremNode)levelNode).getTheorem().getLocation().endLine();
  }
 else   if (levelNode instanceof UseOrHideNode || levelNode instanceof InstanceNode || levelNode instanceof DefStepNode) {
    nodeEndLine=levelNode.getLocation().endLine();
  }
 else {
    return null;
  }
  if (nodeBeginLine <= lineNum && nodeEndLine >= lineNum) {
    return levelNode;
  }
  if (levelNode instanceof TheoremNode) {
    TheoremNode theoremNode=(TheoremNode)levelNode;
    ProofNode proof=theoremNode.getProof();
    if (proof != null) {
      Location proofLoc=proof.getLocation();
      if (lineNum >= nodeEndLine && lineNum <= proofLoc.endLine()) {
        if (proof instanceof NonLeafProofNode) {
          NonLeafProofNode nonLeafProof=(NonLeafProofNode)proof;
          LevelNode[] steps=nonLeafProof.getSteps();
          for (int i=0; i < steps.length; i++) {
            LevelNode node=getLevelNodeFromTree(steps[i],lineNum);
            if (node != null) {
              return node;
            }
          }
          return levelNode;
        }
 else {
          return levelNode;
        }
      }
    }
  }
  return null;
}