This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR libgcj/35020: Class.getSimpleName() differs from Sun Java


2008-05-22  Andrew Haley  <aph@redhat.com>

        PR libgcj/35020
        * java/lang/Class.java (getSimpleName): Import from GNU Classpath.

Index: java/lang/Class.java
===================================================================
*** java/lang/Class.java        (revision 135765)
--- java/lang/Class.java        (working copy)
***************
*** 1075,1096 ****
     */
    public String getSimpleName()
    {
!     StringBuffer sb = new StringBuffer();
!     Class klass = this;
!     int arrayCount = 0;
!     while (klass.isArray())
        {
!       klass = klass.getComponentType();
!       ++arrayCount;
        }
!     if (! klass.isAnonymousClass())
        {
!       String fullName = klass.getName();
!       sb.append(fullName, fullName.lastIndexOf(".") + 1, fullName.length());
        }
!     while (arrayCount-- > 0)
!       sb.append("[]");
!     return sb.toString();
    }
  
    /**
--- 1075,1101 ----
     */
    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;
        }
!     int packagePos = fullName.lastIndexOf(".", pos);
!     if (packagePos == -1)
!       return fullName.substring(pos);
!     else
!       return fullName.substring(packagePos + 1);
    }
  
    /**


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]