001: package visualdebugger.views;
002:
003: import org.eclipse.jdt.core.dom.*;
004:
005: import de.uka.ilkd.key.visualdebugger.SourceElementId;
006:
007: public class FindStatementById extends ASTVisitor {
008:
009: private int currentId = 0;
010:
011: private final int idToFind;
012:
013: private Statement st = null;
014:
015: private Expression expr = null;
016:
017: public FindStatementById(SourceElementId idToFind) {
018: super ();
019: this .idToFind = idToFind.getId();
020: }
021:
022: public boolean visit(Block node) {
023: for (int i = 0; i < node.statements().size(); i++) {
024: currentId++;
025: // System.out.println(node.statements().get(i)+" "+currentId);
026: if (currentId == idToFind) {
027: st = (Statement) node.statements().get(i);
028: }
029: }
030: return true;
031: }
032:
033: public void endVisit(FieldAccess node) {
034: final ITypeBinding expressionTypeBinding = node.getExpression()
035: .resolveTypeBinding();
036: if (expressionTypeBinding != null) {
037: currentId++;
038: if (currentId == idToFind) {
039: expr = node;
040: }
041: }
042: }
043:
044: public void endVisit(QualifiedName node) {
045:
046: if (node.getParent() instanceof QualifiedName)
047: return;
048:
049: if ((node.getQualifier().resolveBinding().getKind() == IBinding.PACKAGE))
050: return;
051:
052: final IBinding simpleNameBinding = node.getName()
053: .resolveBinding();
054:
055: if (simpleNameBinding == null
056: || Modifier.isStatic(simpleNameBinding.getModifiers())) {
057: return;
058: }
059:
060: if (node.getQualifier().resolveTypeBinding().isArray())
061: return;
062: currentId++;
063: // System.out.println(node+" "+currentId);
064: if (currentId == idToFind) {
065: expr = node;
066: }
067:
068: }
069:
070: public void endVisit(ArrayAccess node) {
071: currentId++;
072: // System.out.println(node+" "+currentId);
073: if (currentId == idToFind) {
074: expr = node;
075: }
076:
077: }
078:
079: public void endVisit(ForStatement node) {
080: final Expression guard = node.getExpression();
081: currentId++;
082: if (currentId == idToFind) {
083: expr = guard;
084: }
085: }
086:
087: public void endVisit(WhileStatement node) {
088: final Expression guard = node.getExpression();
089: currentId++;
090: if (currentId == idToFind) {
091: expr = guard;
092: }
093: }
094:
095: public Statement getStatement() {
096: return st;
097: }
098:
099: public Expression getExpression() {
100: return expr;
101: }
102:
103: }
|