code: public int rank(Type t) {
          t = t.unannotatedType();
          switch(t.getTag()) {
          case CLASS: {
              ClassType cls = (ClassType)t;
              if (cls.rank_field < 0) {
                  Name fullname = cls.tsym.getQualifiedName();
                  if (fullname == names.java_lang_Object)
                      cls.rank_field = 0;
                  else {
                      int r = rank(supertype(cls));
                      for (List<Type> l = interfaces(cls);
                           l.nonEmpty();
                           l = l.tail) {
                          if (rank(l.head) > r)
                              r = rank(l.head);
                      }
                      cls.rank_field = r + 1;
                  }
              }
              return cls.rank_field;
          }
          case TYPEVAR: {
              TypeVar tvar = (TypeVar)t;
              if (tvar.rank_field < 0) {
                  int r = rank(supertype(tvar));
                  for (List<Type> l = interfaces(tvar);
                       l.nonEmpty();
                       l = l.tail) {
                      if (rank(l.head) > r) r = rank(l.head);
                  }
                  tvar.rank_field = r + 1;
              }
              return tvar.rank_field;
          }
          case ERROR:
          case NONE:
              return 0;
          default:
              throw new AssertionError();
          }
      }
docs: The rank of a class is the length of the longest path between
  the class and java.lang.Object in the class inheritance
  graph. Undefined for all but reference types.