code: @Override
      public Tree getAncestor(int ttype) {
          Tree t = this;
          t = t.getParent();
          while ( t!=null ) {
              if ( t.getType()==ttype ) return t;
              t = t.getParent();
          }
          return null;
      }
docs: Walk upwards and get first ancestor with this token type.