JavaUnresolvedClassConstant.st
changeset 2151 c0b6570c6f9b
parent 2108 ca8c4e7db2e8
child 2208 6413aafdbd1f
--- a/JavaUnresolvedClassConstant.st	Tue Apr 13 13:26:06 2010 +0200
+++ b/JavaUnresolvedClassConstant.st	Thu Aug 18 20:42:48 2011 +0200
@@ -1,6 +1,10 @@
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -8,10 +12,33 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
-"
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
 
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
 
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+"
 "{ Package: 'stx:libjava' }"
 
 JavaUnresolvedConstant subclass:#JavaUnresolvedClassConstant
@@ -25,8 +52,12 @@
 
 copyright
 "
- COPYRIGHT (c) 1997 by eXept Software AG
-              All Rights Reserved
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -34,9 +65,34 @@
  be provided or otherwise made available to, or used by, any
  other person.  No title to or ownership of the software is
  hereby transferred.
-"
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
 
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+
+"
 ! !
 
 !JavaUnresolvedClassConstant class methodsFor:'instance creation'!
@@ -69,6 +125,15 @@
     "Modified: / 4.2.1998 / 22:13:38 / cg"
 ! !
 
+!JavaUnresolvedClassConstant methodsFor:'* As yet uncategorized *'!
+
+javaClassForNew
+
+    ^self javaClass
+
+    "Created: / 16-03-2011 / 16:09:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaUnresolvedClassConstant methodsFor:'accessing'!
 
 className
@@ -114,7 +179,9 @@
 !
 
 javaClass
-    |clsName|
+    | cls clsName |
+
+    "/fullName first == $[ ifTrue:[self halt].
 
     fullName isNil ifTrue:[
         self preResolve.
@@ -122,14 +189,41 @@
             self halt.
         ]
     ].
+    (fullName first = $[) 
+        ifTrue:
+            [cls := (JavaDescriptor fromString: fullName) javaClass]
+        ifFalse:
+            [cls := Java classForName:fullName].
+    constantPool at: constantPoolIndex put: cls.
+    ^cls
+
+    "old code:"
+    "
     (fullName startsWith:$[) ifTrue:[
-        clsName := self className
+        self halt.
+        clsName := self className.
+        (Java classForName:clsName) ifNil:
+            [self error: 'Cannot resolve class ' , clsName].
+        cls := (JavaDescriptor fromString: fullName) javaClass.
     ] ifFalse:[
         clsName := fullName
     ].
-    ^ Java classForName:clsName.
+    cls := Java classForName:clsName.
+    constantPool at: constantPoolIndex put: cls.
+    ^cls
+    "
 
-    "Modified: / 10.11.1998 / 19:29:28 / cg"
+    "Modified: / 10-11-1998 / 19:29:28 / cg"
+    "Modified: / 11-02-2011 / 07:53:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+lastName
+
+    | idx |
+    idx := fullName lastIndexOf: $/.
+    ^idx ifNil:[fullName] ifNotNil:[fullName copyFrom: idx + 1].
+
+    "Created: / 18-10-2010 / 22:20:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 name
@@ -238,7 +332,7 @@
 !JavaUnresolvedClassConstant methodsFor:'resolving'!
 
 preResolve
-    |clsName cls nm s ref|
+    |clsName cls nm ref|
 
     fullName isNil ifTrue:[
         "/ first, resolve my name ...
@@ -248,198 +342,62 @@
         clsName isString ifFalse:[
             self halt:'oops - no class name string in const pool'.
         ].
-
         fullName := clsName
     ].
 
     "/ try to resolve the class
 
-    "/ 'resolve: ' print. fullName printCR.
-
-    cls := Java classNamed:fullName.
-    cls notNil ifTrue:[
-        "/ good - the class is already loaded.
-
-        constantPool at:constantPoolIndex put:cls.
-        ^ cls
-    ].
-
-    fullName size == 2 ifTrue:[
-        "/ look for specials like byte[], int[] etc.
-        "/ there are only a few of them - forgive me nameing them here ...
-        fullName = '[B' ifTrue:[    "/ byte[]
-            ref := JavaBuiltInClassPointerRef class:ByteArray nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        fullName = '[Z' ifTrue:[    "/ boolean[]
-            ref := JavaBuiltInClassPointerRef class:ByteArray nameandType:fullName.
+    (fullName size == 1) ifTrue:[
+            "/ good - this is a primitive
+            ref := JavaBuiltInClassPointerRef class:(JavaDescriptor fromString: fullName) javaClass nameandType:fullName.
             constantPool at:constantPoolIndex put:ref.
             ^ ref
-        ].
-        fullName = '[I' ifTrue:[     "/ int[]
-            ref := JavaBuiltInClassPointerRef class:SignedIntegerArray nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        fullName = '[J' ifTrue:[     "/ long[]
-            ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
+    ].
+
+    (fullName includes:$[) ifFalse:[
+        cls := Java classNamed:fullName.
+        cls notNil ifTrue:[
+            "/ good - the class is already loaded.
+            constantPool at:constantPoolIndex put:cls.
+            ^ cls
         ].
-        fullName = '[S' ifTrue:[     "/ short[]
-            ref := JavaBuiltInClassPointerRef class:SignedWordArray nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        fullName = '[C' ifTrue:[     "/ char[]
-            "/ should be TwoByteString ...
-            ref := JavaBuiltInClassPointerRef class:String nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        fullName = '[F' ifTrue:[     "/ float[]
-            ref := JavaBuiltInClassPointerRef class:FloatArray nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        fullName = '[D' ifTrue:[     "/ double[]
-            ref := JavaBuiltInClassPointerRef class:DoubleArray nameandType:fullName.
+    ] ifTrue:[
+        "
+            Deal with Sun's malformed class refs generated by
+            sun.misc.ProxyGenerator -  it generates
+            java/lang/annotation/ElementType[] instead of
+            [Ljava/lang/annotation/ElementType[];
+            as the spec requires!!
+        "
+        (fullName last == $] and:[(fullName at: fullName size - 1) == $[]) ifTrue:
+            [fullName := '[L', (fullName copyTo: fullName size - 2) , ';'].
+
+        (fullName includes: $L) ifFalse:[
+            "/ good - this is a primitive array
+            ref := JavaBuiltInClassPointerRef class:(JavaDescriptor fromString: fullName) javaClass nameandType:fullName.
             constantPool at:constantPoolIndex put:ref.
             ^ ref
         ].
     ].
 
-    (fullName startsWith:$[) ifTrue:[
-        "/ a ref for newarray or new
 
-        s := fullName readStream.
-        [s peek == $[ ] whileTrue:[
-            s next
-        ].
-        nm := s upToEnd.
-
-        (nm startsWith:$L) ifFalse:[
-            nm = 'F' ifTrue:[    "/ float[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'D' ifTrue:[    "/ double[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'I' ifTrue:[    "/ int[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'C' ifTrue:[    "/ char[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'B' ifTrue:[    "/ byte[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'Z' ifTrue:[    "/ bool[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            nm = 'S' ifTrue:[    "/ short[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            self halt.
-        ].
-        nm := nm copyFrom:2.
-        (nm endsWith:$;) ifFalse:[
-            self halt.
-        ].
-        nm := nm copyWithoutLast:1.
-
-        cls := Java classNamed:nm.
-        cls notNil ifTrue:[
-            ref := JavaClassPointerRef class:cls nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-        self rememberForResolveWith:nm.
-        ^ self.
-
-        nm := JavaMethod retvalSpecFromStream:(ReadStream on:fullName) in:nil.
-        [nm endsWith:'[]'] whileTrue:[
-            nm := nm copyWithoutLast:2
-        ].
-
-        cls := Java classNamed:nm.
-        cls notNil ifTrue:[
-            ref := JavaClassPointerRef class:cls nameandType:fullName.
-            constantPool at:constantPoolIndex put:ref.
-            ^ ref
-        ].
-
-        (fullName startsWith:'[[') ifTrue:[
-            fullName = '[[F' ifTrue:[    "/ float[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[D' ifTrue:[    "/ double[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[I' ifTrue:[    "/ int[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[C' ifTrue:[    "/ char[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[B' ifTrue:[    "/ byte[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[Z' ifTrue:[    "/ bool[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-            fullName = '[[S' ifTrue:[    "/ short[][]
-                ref := JavaBuiltInClassPointerRef class:Array nameandType:fullName.
-                constantPool at:constantPoolIndex put:ref.
-                ^ ref
-            ].
-        ].
-        (fullName startsWith:'[L') ifFalse:[
-            (fullName startsWith:'[[L') ifFalse:[
-                ('JAVA: oops - unresolvable funny class: ' , fullName) errorPrintCR.
-                self halt.
-            ]
-        ]
-    ] ifFalse:[
+    (fullName startsWith:$[) ifFalse:[
         nm := self className.
+        self rememberForResolveWith:nm.            
     ].
-
-    self rememberForResolveWith:nm.
     ^ self
 
-    "Created: / 15.4.1996 / 15:51:42 / cg"
-    "Modified: / 6.7.1999 / 23:41:04 / cg"
+    "Created: / 15-04-1996 / 15:51:42 / cg"
+    "Modified: / 06-07-1999 / 23:41:04 / cg"
+    "Modified: / 11-02-2011 / 10:41:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaUnresolvedClassConstant class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libjava/JavaUnresolvedClassConstant.st,v 1.43 2002-11-22 20:11:24 cg Exp $'
+    ^ '$Id: JavaUnresolvedClassConstant.st,v 1.44 2011-08-18 18:42:48 vrany Exp $'
+!
+
+version_SVN
+    ^ '$Id: JavaUnresolvedClassConstant.st,v 1.44 2011-08-18 18:42:48 vrany Exp $'
 ! !