Re: [cp-patches] Fix for Class.getSimpleName()

2008-05-28 Thread Andrew Haley
Tom Tromey wrote:

 
 The test class is something like:
 
 public class Foo$What { }
 
 The simple name of this is Foo$What, not What.

Ahh, *that's* what you're talking about.
Fixed thusly.

Andrew.


2008-05-28  Andrew Haley  [EMAIL PROTECTED]

* java/lang/Class.java (getSimpleName): Use getEnclosingClass().
* testsuite/libjava.lang/PR35020.java: New cases.
* testsuite/libjava.lang/PR35020.out: New cases.

Index: java/lang/Class.java
===
*** java/lang/Class.java(revision 135801)
--- java/lang/Class.java(working copy)
***
*** 1077,1104 
{
  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);
}

/**
 * Returns the class which immediately encloses this class.  If this class
--- 1077,1102 
{
  if (isAnonymousClass())
return ;
  if (isArray())
!   return getComponentType().getSimpleName() + [];
!
  String fullName = getName();
! Class enclosingClass = getEnclosingClass();
! if (enclosingClass == null)
!   // It's a top level class.
!   return fullName.substring(fullName.lastIndexOf(.) + 1);
!
! fullName = fullName.substring(enclosingClass.getName().length());
!
! // We've carved off the enclosing class name; now we must have '$'
! // followed optionally by digits, followed by the class name.
! int pos = 1;
! while (Character.isDigit(fullName.charAt(pos)))
!   ++pos;
! fullName = fullName.substring(pos);

! return fullName;
}

/**
 * Returns the class which immediately encloses this class.  If this class
Index: testsuite/libjava.lang/PR35020.java
===
*** testsuite/libjava.lang/PR35020.java (revision 135801)
--- testsuite/libjava.lang/PR35020.java (working copy)
***
*** 1,21 
  public class PR35020
  {
!class inner
!{
!}
!public static void main(String[] args)
!{
!   System.out.println(inner.class.getSimpleName());
!   System.out.println(PR35020.class.getSimpleName());
!   System.out.println(Class.class.getSimpleName());
!   System.out.println((new int[7]).getClass().getSimpleName());
!   System.out.println((new 
Object[1][1][1][1][1][1][1][1]).getClass().getSimpleName());
!   System.out.println((new java.security.PrivilegedAction()
!   {
! public Object run() {
!   return null;
! }
!   }).getClass().getSimpleName());
!}
  }
-
--- 1,31 
+ class outer$inner
+ {
+   public class inner{};
+ };
+
  public class PR35020
  {
!   class PR35020$Inner
!   {
!   };
!   class inner
!   {
!   }
!   public static void main(String[] args)
!   {
! System.out.println(inner.class.getSimpleName());
! System.out.println(PR35020.class.getSimpleName());
! System.out.println(Class.class.getSimpleName());
! System.out.println((new int[7]).getClass().getSimpleName());
! System.out.println((new 
Object[1][1][1][1][1][1][1][1]).getClass().getSimpleName());
! System.out.println((new java.security.PrivilegedAction()
!   {
!   public Object run() {
! return null;
!   }
!   }).getClass().getSimpleName());
! System.out.println(PR35020$Inner.class.getSimpleName());
! System.out.println(outer$inner.class.getSimpleName());
! System.out.println(outer$inner.inner.class.getSimpleName());
!   }
  }
Index: testsuite/libjava.lang/PR35020.out
===
*** testsuite/libjava.lang/PR35020.out  (revision 135801)
--- testsuite/libjava.lang/PR35020.out  (working copy)
***
*** 3,6 
--- 3,9 
  Class
  int[]
  Object[][][][][][][][]

+ PR35020$Inner
+ outer$inner
+ inner



Re: [cp-patches] Fix for Class.getSimpleName()

2008-05-27 Thread Tom Tromey
 Andrew == Andrew Haley [EMAIL PROTECTED] writes:

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

I think looking for a $ in general is wrong.  I think instead the
name should be looked up in the InnerClasses attribute.  AFAIK that's
the only guaranteed-reliable way to do this.

That said, I doubt this implementation will fail in real life.

Tom



Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-20 Thread Tom Tromey
Sebastian GCJ's implementation seems not to handle inner and local classes.

Thanks.

Sebastian I don't have a good overview of the classpath architecture,
Sebastian yet. Maybe it would be better to remove the method
Sebastian getSimpleName() in VMClass.java and implement it directly
Sebastian in java.lang.Class?

Yes, if it can be written using other parts of the defined API, then I
think that would be preferable.

In general it is best to only put something in VMClass if there is a
need -- either when it can't be done using the public API, or when
there is a performance issue with the straightforward approach.

Tom



Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-19 Thread Sebastian Mancke
Hi.

Now, the method getSimpleName() is merged with the one of glibgcj. (Not
changing behaviour, but avoiding recursion)

The Testcase has additional checks for array types and is converted to
mauve, now. I could not find regression due to my changes

--Sebastian

Sebastian Mancke schrieb:
 
 
 Mark Wielaard schrieb:
 Hi,
 
 On Thu, 2008-04-17 at 00:50 +0100, Andrew John Hughes wrote:
 As to your contribution, the Classpath part (i.e. the java.lang.Class
 changes, Mauve has different contribution rules) looks minor enough to
 not require an assignment, but I'll let Mark (CCed) answer that for
 definite.  However, if you intend to do further Classpath
 contributions, I'd suggest sorting out the necessary paperwork with
 the FSF; you need to assign copyright to them.  Either Mark or I
 should be able to send you the form.
 Yes, you are right. This is small enough to be obvious, but it would
 be nice to have paperwork on file with the FSF stating your willingness
 to contribute (larger) patches in the future. I'll send you the request
 form.
 I have sent the request to the FSF.
 
 BTW. libgcj has a slightly different implementation of
 Class.getSimpleName() that might be worth merging with the classpath
 version: http://gcc.gnu.org/ml/java-patches/2006-q3/msg00192.html
 Yes, looks good.
 
 --Sebastian
 

-- 
tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
fax: +49(228) / 52675-25| fax: +49(30) / 78709617
durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

Geschäftsführer:
Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168
Ust-ID: DE122264941
Index: vm/reference/java/lang/VMClass.java
===
RCS file: /sources/classpath/classpath/vm/reference/java/lang/VMClass.java,v
retrieving revision 1.20
diff -u -r1.20 VMClass.java
--- vm/reference/java/lang/VMClass.java 18 Sep 2007 21:52:38 -  1.20
+++ vm/reference/java/lang/VMClass.java 19 Apr 2008 15:19:00 -
@@ -296,27 +296,43 @@
*/
   static String getSimpleName(Class klass)
   {
+int arrayCount = 0;
+while (klass.isArray())
+  {
+klass = klass.getComponentType();
+++arrayCount;
+  }
+// now klass is the component type
+
+String simpleComponentName = null;
 if (isAnonymousClass(klass))
-  return ;
-if (isArray(klass))
   {
-   return getComponentType(klass).getSimpleName() + [];
+simpleComponentName = ;
   }
-String fullName = getName(klass);
-int pos = fullName.lastIndexOf($);
-if (pos == -1)
-  pos = 0;
 else
   {
-   ++pos;
-   while (Character.isDigit(fullName.charAt(pos)))
- ++pos;
+String fullName = getName(klass);
+int pos = fullName.lastIndexOf($);
+if (pos != -1) 
+  { //inner class or local class
+// skip digits of local classes
+while (Character.isDigit(fullName.charAt(pos+1)))
+  pos++;
+  } 
+else 
+  {
+pos = fullName.lastIndexOf(.);
+  }
+simpleComponentName = fullName.substring(pos+1);
   }
-int packagePos = fullName.lastIndexOf(., pos);
-if (packagePos == -1)
-  return fullName.substring(pos);
-else
-  return fullName.substring(packagePos + 1);
+
+if (arrayCount == 0)
+  return simpleComponentName;
+
+StringBuffer sb = new StringBuffer(simpleComponentName);
+while (arrayCount--  0)
+  sb.append([]);
+return sb.toString();
   }
 
   /**
Index: gnu/testlet/java/lang/Class/SimpleNameTest.java
===
RCS file: gnu/testlet/java/lang/Class/SimpleNameTest.java
diff -N gnu/testlet/java/lang/Class/SimpleNameTest.java
--- /dev/null   1 Jan 1970 00:00:00 -
+++ gnu/testlet/java/lang/Class/SimpleNameTest.java 19 Apr 2008 15:18:25 
-
@@ -0,0 +1,82 @@
+// Copyright (C) 2008 Sebastian Mancke, Tarent GmbH [EMAIL PROTECTED]
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.lang.Class;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**

Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-19 Thread Tom Tromey
 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.

Tom



Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-17 Thread Christian Thalinger
On Thu, 2008-04-17 at 00:50 +0100, Andrew John Hughes wrote:
 twisti, we should also maybe port the CACAO test if it's not VM specific?

No, the testcase is not VM specific.  IIRC I also encouraged the student
to write the testcase for Mauve, but that does not work all the time :-)

- twisti




Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-17 Thread Mark Wielaard
Hi,

On Thu, 2008-04-17 at 00:50 +0100, Andrew John Hughes wrote:
 As to your contribution, the Classpath part (i.e. the java.lang.Class
 changes, Mauve has different contribution rules) looks minor enough to
 not require an assignment, but I'll let Mark (CCed) answer that for
 definite.  However, if you intend to do further Classpath
 contributions, I'd suggest sorting out the necessary paperwork with
 the FSF; you need to assign copyright to them.  Either Mark or I
 should be able to send you the form.

Yes, you are right. This is small enough to be obvious, but it would
be nice to have paperwork on file with the FSF stating your willingness
to contribute (larger) patches in the future. I'll send you the request
form.

BTW. libgcj has a slightly different implementation of
Class.getSimpleName() that might be worth merging with the classpath
version: http://gcc.gnu.org/ml/java-patches/2006-q3/msg00192.html

Cheers,

Mark




Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-17 Thread Sebastian Mancke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Mark Wielaard schrieb:
 Hi,
 
 On Thu, 2008-04-17 at 00:50 +0100, Andrew John Hughes wrote:
 As to your contribution, the Classpath part (i.e. the java.lang.Class
 changes, Mauve has different contribution rules) looks minor enough to
 not require an assignment, but I'll let Mark (CCed) answer that for
 definite.  However, if you intend to do further Classpath
 contributions, I'd suggest sorting out the necessary paperwork with
 the FSF; you need to assign copyright to them.  Either Mark or I
 should be able to send you the form.
 
 Yes, you are right. This is small enough to be obvious, but it would
 be nice to have paperwork on file with the FSF stating your willingness
 to contribute (larger) patches in the future. I'll send you the request
 form.
I have sent the request to the FSF.

 BTW. libgcj has a slightly different implementation of
 Class.getSimpleName() that might be worth merging with the classpath
 version: http://gcc.gnu.org/ml/java-patches/2006-q3/msg00192.html
Yes, looks good.

- --Sebastian

- --
tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
fax: +49(228) / 52675-25| fax: +49(30) / 78709617
durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

Geschäftsführer:
Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168
Ust-ID: DE122264941
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIB1mgsMJ2Yk81wE0RAkNSAJwLyLs+lOg/UfkloI7rHe1V3goYtgCg+xj+
zpAvV2K7It3KZ9u2nt1TTX0=
=SOH2
-END PGP SIGNATURE-



Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Christian Thalinger
On Tue, 2008-04-15 at 23:28 +0200, Sebastian Mancke wrote:
 Hi,
 
 attached is a fix for the method Class.getSimpleName(), together with a
 small testcase. The old implementation failed on usual class names, as
 well as on inner classes.
 
 Please comment/commit.

This reminds me of this patch:

http://www.mail-archive.com/classpath-patches@gnu.org/msg10378.html

And I think your changes will break it (but I haven't tested).

- twisti




Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Sebastian Mancke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Christian Thalinger schrieb:
 On Tue, 2008-04-15 at 23:28 +0200, Sebastian Mancke wrote:
 Hi,

 attached is a fix for the method Class.getSimpleName(), together with a
 small testcase. The old implementation failed on usual class names, as
 well as on inner classes.

 Please comment/commit.
 
 This reminds me of this patch:
 
 http://www.mail-archive.com/classpath-patches@gnu.org/msg10378.html
 
 And I think your changes will break it (but I haven't tested).

I saw this patch and think it broke the behaviour, because of the wrong
usage of fullName.lastIndexOf(., pos): The pos argument, counted from
left makes no sense in this method.

Also, I think, that advancing 'pos', dependent on
Character.isDigit(fullName.charAt(pos)) make no sense, because we return
 for anonymous classes already.

- --Sebastian


- --
tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
fax: +49(228) / 52675-25| fax: +49(30) / 78709617
durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

Geschäftsführer:
Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168
Ust-ID: DE122264941
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIBb+lsMJ2Yk81wE0RAjE8AJ9FsNX2ApT6kU3eZz3RLdYWFasZDACg9vhk
4aiBh4P6d5bce9jFqisJ5mU=
=aKq8
-END PGP SIGNATURE-



Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Christian Thalinger
On Wed, 2008-04-16 at 10:58 +0200, Sebastian Mancke wrote:
 I saw this patch and think it broke the behaviour, because of the wrong
 usage of fullName.lastIndexOf(., pos): The pos argument, counted from
 left makes no sense in this method.
 
 Also, I think, that advancing 'pos', dependent on
 Character.isDigit(fullName.charAt(pos)) make no sense, because we return
  for anonymous classes already.

I see.  Can you try the CACAO testcase (I hope this is the right one):

tests/regression/TestAnnotations.java

- twisti




Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Sebastian Mancke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Christian Thalinger schrieb:
 On Wed, 2008-04-16 at 10:58 +0200, Sebastian Mancke wrote:
 I saw this patch and think it broke the behaviour, because of the wrong
 usage of fullName.lastIndexOf(., pos): The pos argument, counted from
 left makes no sense in this method.

 Also, I think, that advancing 'pos', dependent on
 Character.isDigit(fullName.charAt(pos)) make no sense, because we return
  for anonymous classes already.
 
 I see.  Can you try the CACAO testcase (I hope this is the right one):
 tests/regression/TestAnnotations.java
TestAnnotations hangs the current cacao. Dump is attached.

But maybe the testcase you mean is MinimalClassReflection, right?
I have diff'ed cacaos output to the jdks output. In fact, I have missed
one case: The Digits after the '$' exist for local classes and have to
be skipped for the simple name. I will overwork my patch.

- --Sebastian

- --
tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
fax: +49(228) / 52675-25| fax: +49(30) / 78709617
durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

Geschäftsführer:
Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168
Ust-ID: DE122264941
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIBdTQsMJ2Yk81wE0RAiSsAKD6Oat3rw6HGWzV0jTiPBbrWD2cQgCeMnJa
gQYpAZmnkZMwxFmqAegbNVA=
=AgQ5
-END PGP SIGNATURE-
== Testing EnumA ==
LOG: [0x401b96b0] We received a SIGSEGV and tried to handle it, but we were
LOG: [0x401b96b0] unable to find a Java method at:
LOG: [0x401b96b0] 
LOG: [0x401b96b0] PC=0x4024ff33
LOG: [0x401b96b0] 
LOG: [0x401b96b0] Dumping the current stacktrace:
at 
java.lang.reflect.VMMethod.getDefaultValue()Ljava/lang/Object;(Native Method)
at 
java.lang.reflect.Method.getDefaultValue()Ljava/lang/Object;(Method.java:440)
at 
sun.reflect.annotation.AnnotationType.init(Ljava/lang/Class;)V(AnnotationType.java:132)
at 
sun.reflect.annotation.AnnotationType.getInstance(Ljava/lang/Class;)Lsun/reflect/annotation/AnnotationType;(AnnotationType.java:99)
at 
sun.reflect.annotation.AnnotationParser.parseAnnotation(Ljava/nio/ByteBuffer;Lsun/reflect/ConstantPool;Ljava/lang/Class;Z)Ljava/lang/annotation/Annotation;(AnnotationParser.java:300)
at 
sun.reflect.annotation.AnnotationParser.parseAnnotations2([BLsun/reflect/ConstantPool;Ljava/lang/Class;)Ljava/util/Map;(AnnotationParser.java:167)
at 
sun.reflect.annotation.AnnotationParser.parseAnnotations([BLsun/reflect/ConstantPool;Ljava/lang/Class;)Ljava/util/Map;(AnnotationParser.java:150)
at 
sun.reflect.annotation.AnnotationParser.parseAnnotationsIntoArray([BLsun/reflect/ConstantPool;Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;(AnnotationParser.java:63)
at 
java.lang.VMClass.getDeclaredAnnotations(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;(Native
 Method)
at 
java.lang.Class.getDeclaredAnnotations()[Ljava/lang/annotation/Annotation;(Class.java:1575)
at 
AnnotatedElementAnnotationTester.testGetDeclaredAnnotations()Z(TestAnnotations.java:862)
at AnnotatedElementAnnotationTester.test()Z(TestAnnotations.java:851)
at ClassAnnotationTester.test()Z(TestAnnotations.java:1268)
at TestAnnotations.main([Ljava/lang/String;)V(TestAnnotations.java:1773)
LOG: [0x401b96b0] Exiting...


Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Sebastian Mancke


Sebastian Mancke schrieb:
 
 
 Christian Thalinger schrieb:
 On Wed, 2008-04-16 at 10:58 +0200, Sebastian Mancke wrote:
 I saw this patch and think it broke the behaviour, because of the wrong
 usage of fullName.lastIndexOf(., pos): The pos argument, counted from
 left makes no sense in this method.

 Also, I think, that advancing 'pos', dependent on
 Character.isDigit(fullName.charAt(pos)) make no sense, because we return
  for anonymous classes already.
 I see.  Can you try the CACAO testcase (I hope this is the right one):
 tests/regression/TestAnnotations.java
 TestAnnotations hangs the current cacao. Dump is attached.
 
 But maybe the testcase you mean is MinimalClassReflection, right?
 I have diff'ed cacaos output to the jdks output. In fact, I have missed
 one case: The Digits after the '$' exist for local classes and have to
 be skipped for the simple name. I will overwork my patch.

So, here is my patch again, now handling local classes as well.
I have tested it against the attached testcase, as well as against
cacaos MinimalClassReflection.java.

The following class name situations are covered:
Class in default package
Class in package
Inner Class (e.g. xyz.Abc$Inner - Inner)
Local Class (e.g. xyz.Abc$1Local - Local)
Anonymous (e.g. xyz.Abc$2 - )

--Sebastian


-- 
tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
fax: +49(228) / 52675-25| fax: +49(30) / 78709617
durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

Geschäftsführer:
Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168
Ust-ID: DE122264941
Index: vm/reference/java/lang/VMClass.java
===
RCS file: /sources/classpath/classpath/vm/reference/java/lang/VMClass.java,v
retrieving revision 1.20
diff -u -r1.20 VMClass.java
--- vm/reference/java/lang/VMClass.java 18 Sep 2007 21:52:38 -  1.20
+++ vm/reference/java/lang/VMClass.java 16 Apr 2008 11:12:18 -
@@ -304,19 +304,14 @@
   }
 String fullName = getName(klass);
 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);
+if (pos != -1) { //inner class or local class
+// skip digits of local classes
+while (Character.isDigit(fullName.charAt(pos+1)))
+pos++;
+} else {
+pos = fullName.lastIndexOf(.);
+}
+return fullName.substring(pos+1);
   }
 
   /**
Index: testsuite/java.lang/SimpleNameTest.java
===
RCS file: testsuite/java.lang/SimpleNameTest.java
diff -N testsuite/java.lang/SimpleNameTest.java
--- /dev/null   1 Jan 1970 00:00:00 -
+++ testsuite/java.lang/SimpleNameTest.java 16 Apr 2008 11:12:18 -
@@ -0,0 +1,54 @@
+package simplename;
+
+public class SimpleNameTest
+{
+public static void main(final String[] args) {
+new SimpleNameTest();
+}
+
+private SimpleNameTest() {
+
+if (Object.equals(Object.class.getSimpleName()))
+passed(Object.class.getSimpleName() is \Object\);
+else
+failed(Object.class.getSimpleName() should be \Object\, but is 
+Object.class.getSimpleName());
+
+
+if (SimpleNameTest.equals(SimpleNameTest.class.getSimpleName()))
+passed(SimpleNameTest.class.getSimpleName() is 
\SimpleNameTest\);
+else
+failed(SimpleNameTest.class.getSimpleName() should be 
\SimpleNameTest\, but is +SimpleNameTest.class.getSimpleName());
+
+Object anonymous = new Object(){};
+if (.equals(anonymous.getClass().getSimpleName()))
+passed(anonymous.getClass().getSimpleName() is \\);
+else
+failed(anonymous.getClass().getSimpleName() should be \\,  but 
is +anonymous.getClass().getSimpleName());
+
+
+if (Inner.equals(Inner.class.getSimpleName()))
+passed(Inner.class.getSimpleName() is \Inner\);
+else
+failed(Inner.class.getSimpleName() should be \Inner\,  but is 
+Inner.class.getSimpleName());
+
+
+class Local {
+}
+if (Local.equals(Local.class.getSimpleName()))
+passed(Local.class.getSimpleName() is \Local\);
+else
+failed(Local.class.getSimpleName() should be \Local\,  but is 
+Local.class.getSimpleName());
+}
+
+public class Inner {
+
+}
+
+static void passed(String msg) {
+System.out.println(PASSED: +msg);
+}
+
+static void failed(String msg) {
+System.out.println(FAILED: +msg);
+}
+}


Re: [cp-patches] Fix for Class.getSimpleName()

2008-04-16 Thread Andrew John Hughes
On 16/04/2008, Sebastian Mancke [EMAIL PROTECTED] wrote:


  Sebastian Mancke schrieb:

 
  
   Christian Thalinger schrieb:
   On Wed, 2008-04-16 at 10:58 +0200, Sebastian Mancke wrote:
   I saw this patch and think it broke the behaviour, because of the wrong
   usage of fullName.lastIndexOf(., pos): The pos argument, counted from
   left makes no sense in this method.
  
   Also, I think, that advancing 'pos', dependent on
   Character.isDigit(fullName.charAt(pos)) make no sense, because we return
for anonymous classes already.
   I see.  Can you try the CACAO testcase (I hope this is the right one):
   tests/regression/TestAnnotations.java
   TestAnnotations hangs the current cacao. Dump is attached.
  
   But maybe the testcase you mean is MinimalClassReflection, right?
   I have diff'ed cacaos output to the jdks output. In fact, I have missed
   one case: The Digits after the '$' exist for local classes and have to
   be skipped for the simple name. I will overwork my patch.


 So, here is my patch again, now handling local classes as well.
  I have tested it against the attached testcase, as well as against
  cacaos MinimalClassReflection.java.

  The following class name situations are covered:
  Class in default package
  Class in package
  Inner Class (e.g. xyz.Abc$Inner - Inner)
  Local Class (e.g. xyz.Abc$1Local - Local)
  Anonymous (e.g. xyz.Abc$2 - )


  --Sebastian


  --
  tarent Gesellschaft für Softwareentwicklung und IT-Beratung mbH

  Heilsbachstr. 24, 53123 Bonn| Poststr. 4-5, 10178 Berlin
  fon: +49(228) / 52675-0 | fon: +49(30) / 27594853
  fax: +49(228) / 52675-25| fax: +49(30) / 78709617
  durchwahl: +49(228) / 52675-17  | mobil: +49(171) / 7673249

  Geschäftsführer:
  Boris Esser, Elmar Geese, Thomas Müller-Ackermann
  HRB AG Bonn 5168
  Ust-ID: DE122264941

 Index: vm/reference/java/lang/VMClass.java
  ===
  RCS file: /sources/classpath/classpath/vm/reference/java/lang/VMClass.java,v
  retrieving revision 1.20
  diff -u -r1.20 VMClass.java
  --- vm/reference/java/lang/VMClass.java 18 Sep 2007 21:52:38 -  1.20
  +++ vm/reference/java/lang/VMClass.java 16 Apr 2008 11:12:18 -
  @@ -304,19 +304,14 @@
}
  String fullName = getName(klass);
  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);
  +if (pos != -1) { //inner class or local class
  +// skip digits of local classes
  +while (Character.isDigit(fullName.charAt(pos+1)))
  +pos++;
  +} else {
  +pos = fullName.lastIndexOf(.);
  +}
  +return fullName.substring(pos+1);
}

/**
  Index: testsuite/java.lang/SimpleNameTest.java
  ===
  RCS file: testsuite/java.lang/SimpleNameTest.java
  diff -N testsuite/java.lang/SimpleNameTest.java
  --- /dev/null   1 Jan 1970 00:00:00 -
  +++ testsuite/java.lang/SimpleNameTest.java 16 Apr 2008 11:12:18 -
  @@ -0,0 +1,54 @@
  +package simplename;
  +
  +public class SimpleNameTest
  +{
  +public static void main(final String[] args) {
  +new SimpleNameTest();
  +}
  +
  +private SimpleNameTest() {
  +
  +if (Object.equals(Object.class.getSimpleName()))
  +passed(Object.class.getSimpleName() is \Object\);
  +else
  +failed(Object.class.getSimpleName() should be \Object\, but 
 is +Object.class.getSimpleName());
  +
  +
  +if (SimpleNameTest.equals(SimpleNameTest.class.getSimpleName()))
  +passed(SimpleNameTest.class.getSimpleName() is 
 \SimpleNameTest\);
  +else
  +failed(SimpleNameTest.class.getSimpleName() should be 
 \SimpleNameTest\, but is +SimpleNameTest.class.getSimpleName());
  +
  +Object anonymous = new Object(){};
  +if (.equals(anonymous.getClass().getSimpleName()))
  +passed(anonymous.getClass().getSimpleName() is \\);
  +else
  +failed(anonymous.getClass().getSimpleName() should be \\,  
 but is +anonymous.getClass().getSimpleName());
  +
  +
  +if (Inner.equals(Inner.class.getSimpleName()))
  +passed(Inner.class.getSimpleName() is \Inner\);
  +else
  +failed(Inner.class.getSimpleName() should be \Inner\,  but 
 is +Inner.class.getSimpleName());
  +
  +
  +class Local {
  +}
  +if (Local.equals(Local.class.getSimpleName()))
  +passed(Local.class.getSimpleName() is \Local\);
  +else
  +failed(Local.class.getSimpleName() should be \Local\,  but 
 is