package annotator.find;

import java.util.List;

import annotator.scanner.CastScanner;

import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.util.Pair;

public class CastCriterion implements Criterion {

  private String methodName;
  private Integer offset;

  public CastCriterion(String methodName, Integer offset) {
    this.methodName = methodName.substring(0, methodName.lastIndexOf(")") + 1);
    this.offset = offset;
  }

  /** {@inheritDoc} */
  @Override
  public boolean isSatisfiedBy(TreePath path, Tree leaf) {
    assert path == null || path.getLeaf() == leaf;
    return isSatisfiedBy(path);
  }

  /** {@inheritDoc} */
  @Override
  public boolean isSatisfiedBy(TreePath path) {
    if (path == null) {
      return false;
    }

    Tree leaf = path.getLeaf();

    if (leaf.getKind() == Tree.Kind.TYPE_CAST) {
      int indexInSource = CastScanner.indexOfCastTree(path, leaf);
      int indexInClass = CastScanner.getMethodCastIndex(methodName, offset);
      boolean b = (indexInSource == indexInClass);
      return b;
    } else {
      boolean b = this.isSatisfiedBy(path.getParentPath());
      return b;
    }
  }

  public Kind getKind() {
    return Kind.CAST;
  }

  public String toString() {
    return "CastCriterion: in method: " + methodName + " offset: " + offset;
  }
}

@@ -42,16 +42,56 @@
 .List;%0A%0A
+import annotations.el.RelativeLocation;%0A
 import a
@@ -361,30 +361,36 @@
 private 
-Integer offset
+RelativeLocation loc
 ;%0A%0A  pub
@@ -430,22 +430,28 @@
 me, 
-Integer offset
+RelativeLocation loc
 ) %7B%0A
@@ -543,23 +543,17 @@
 his.
-offset = offset
+loc = loc
 ;%0A  
@@ -1022,24 +1022,78 @@
 eaf);%0A      
+boolean b;%0A      if (loc.isBytecodeOffset()) %7B%0A    %09  
 int indexInC
@@ -1142,16 +1142,20 @@
 odName, 
+loc.
 offset);
@@ -1155,34 +1155,27 @@
 ffset);%0A    
+%09
   
-boolean 
 b = (indexIn
@@ -1197,32 +1197,93 @@
 InClass);%0A      
+%7D else %7B%0A    %09  b = (indexInSource == loc.index);%0A      %7D%0A%09  
 return b;%0A    %7D 
@@ -1272,24 +1272,25 @@
   return b;%0A
+%0A
     %7D else %7B
@@ -1520,26 +1520,25 @@
 + %22 
-offset: %22 + offset
+location: %22 + loc
 ;%0A  

Use the new RelativeLocation instead of plain Integers.