Tom Tromey writes:
 > >>>>> "Sebastian" == Sebastian Mancke <[EMAIL PROTECTED]> writes:
 > 
 > Sebastian> Now, the method getSimpleName() is merged with the one of
 > Sebastian> glibgcj. (Not changing behaviour, but avoiding recursion)
 > 
 > I noticed it is still different.
 > My recollection (I haven't looked at this in a while) is that the gcj
 > implementation is correct.  And, it relies only on the published Class
 > API.  So, why not just use it directly in Classpath's Class?
 > 
 > Sebastian> +        String fullName = getName(klass);
 > Sebastian> +        int pos = fullName.lastIndexOf("$");
 > 
 > I think relying on the name mangling is not valid.
 > That is why gcj's implementation uses isAnonymousClass and the like.

Yes, but gcj's implementation was also broken.  This is the current gcj
code; please let me know if you think it's still wrong.

Andrew.



  public String getSimpleName()
  {
    if (isAnonymousClass())
      return "";
    if (isArray())
      {
        return getComponentType().getSimpleName() + "[]";
      }
    String fullName = getName();
    int pos = fullName.lastIndexOf("$");
    if (pos == -1)
      pos = 0;
    else
      {
        ++pos;
        while (Character.isDigit(fullName.charAt(pos)))
          ++pos;
        fullName = fullName.substring(pos);
      }

    int packagePos = fullName.lastIndexOf(".");
    if (packagePos == -1)
      return fullName;
    else
      return fullName.substring(packagePos + 1);
  }


Reply via email to