src/JavaMethod.st
branchjk_new_structure
changeset 912 e651488f5741
parent 877 f5a5b93e1c78
child 913 1781f130b005
--- a/src/JavaMethod.st	Fri Aug 12 20:50:02 2011 +0000
+++ b/src/JavaMethod.st	Sat Aug 13 01:26:52 2011 +0000
@@ -146,6 +146,7 @@
     SignatureTypeCodes at:$Z put:#boolean.
     SignatureTypeCodes at:$L put:#object.
     SignatureTypeCodes at:$[ put:#array.
+    SignatureTypeCodes at:$T put:#typevar.
 
     ForceByteCodeDisplay := false.
 
@@ -156,7 +157,8 @@
      ForceByteCodeDisplay := false.
     "
 
-    "Modified: / 16.10.1998 / 01:29:48 / cg"
+    "Modified: / 16-10-1998 / 01:29:48 / cg"
+    "Modified: / 13-08-2011 / 01:02:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 reinitialize
@@ -426,44 +428,63 @@
 fieldTypeFromStream:s in:aPackage
     "parse a fieldTypeSpec - see java doc"
 
-    |typeChar typeSym elType size className nm|
+    |typeChar typeSym elType size className nm out nangles |
 
     typeChar := s next.
 
     typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.
 
     typeSym == #unknown ifTrue:[
-	^ typeSym
+        ^ typeSym
     ].
-    typeSym == #object ifTrue:[
-	className := s upTo:$;.
-	"/ strip off default
-
-	nm := className.
-	aPackage notNil ifTrue:[
-	    (nm startsWith:aPackage) ifTrue:[
-		nm := nm copyFrom:(aPackage size + 2).
-	    ].
-	].
+    (typeSym == #object or: [typeSym == #typevar]) ifTrue:[
+        "Take care about type variables"
+        out := String new writeStream.
+        [ s peek ~~ $; and:[ s peek ~~ $< ] ] whileTrue:[
+            out nextPut: s next.
+        ].
+        className := out contents.
+        "Eat possible type variables"
+        (s peek == $<) ifTrue:[
+            nangles := 1. s next.
+            [  nangles ~~ 0 ] whileTrue:[
+                s peek == $< ifTrue:[nangles := nangles + 1].
+                s peek == $> ifTrue:[nangles := nangles - 1].
+                s next.
+            ]
+        ].
+        s peek ~~ $; ifTrue:[self error: 'Signature corrupted?'].
+        s next. "/eat ;
+
+
+        typeSym == #typevar ifTrue:[^className].
+        "/ strip off default
+        nm := className.
+        aPackage notNil ifTrue:[
+            (nm startsWith:aPackage) ifTrue:[
+                nm := nm copyFrom:(aPackage size + 2).
+            ].
+        ].
         
-	nm := nm copyReplaceAll:$/ with:$..
-	^ nm
+        nm := nm copyReplaceAll:$/ with:$..
+        ^ nm
     ].
 
     typeSym == #array ifTrue:[
-	s peek isDigit ifTrue:[
-	    size := Integer readFrom:s.
-	    elType := self fieldTypeFromStream:s in:aPackage.
-	    ^ elType , '[' , size printString , ']'
-	].
-	elType := self fieldTypeFromStream:s in:aPackage.
-	^ elType , '[]'
+        s peek isDigit ifTrue:[
+            size := Integer readFrom:s.
+            elType := self fieldTypeFromStream:s in:aPackage.
+            ^ elType , '[' , size printString , ']'
+        ].
+        elType := self fieldTypeFromStream:s in:aPackage.
+        ^ elType , '[]'
     ].
 
     ^ typeSym
 
-    "Created: / 18.3.1997 / 11:07:56 / cg"
-    "Modified: / 18.7.1998 / 22:57:06 / cg"
+    "Created: / 18-03-1997 / 11:07:56 / cg"
+    "Modified: / 18-07-1998 / 22:57:06 / cg"
+    "Modified: / 13-08-2011 / 01:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 numArgsFromSignature:aSignature
@@ -472,7 +493,8 @@
     |s|
 
     s := aSignature readStream.
-    s next ~~ $( ifTrue:[self halt].
+    (aSignature includes: $() ifFalse:[self error:'Invalid signature'].
+    [s next ~~ $(] whileTrue.
 
     ^ self numArgsFromStream:s.
 
@@ -480,7 +502,10 @@
      JavaMethod numArgsFromSignature:'(LObject;)V'
      JavaMethod numArgsFromSignature:'(BB)S'      
      JavaMethod numArgsFromSignature:'()V'      
+     JavaMethod numArgsFromSignature:'(Ljava/util/ArrayList<*>;)V'
     "
+
+    "Modified (comment): / 13-08-2011 / 00:59:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 numArgsFromStream:s
@@ -1289,9 +1314,42 @@
      localVariableTable := anArray.
 !
 
-setName:nameString signature:signatureString
-    selector := (nameString , signatureString) asSymbol.
-    self setSignature:signatureString
+setName:nameString signature:aString
+
+
+    |numArgs tooManyArgs returnType|
+
+    selector := (nameString , aString) asSymbol.
+    self setSignature:aString.
+
+     numArgs := self class numArgsFromSignature:aString.
+     (tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[
+     numArgs := 0.
+     ].
+     self numberOfArgs:numArgs.
+     returnType := self class typeFromSignature:aString in:nil.
+
+     "/ for the convenience of the VM, also mirror the return type in
+     "/ the flags ...
+
+     returnType == #void ifTrue:[
+     accessFlags := accessFlags bitOr:R_VOID
+     ] ifFalse:[
+     returnType == #long ifTrue:[
+     accessFlags := accessFlags bitOr:R_LONG
+     ] ifFalse:[
+     returnType == #double ifTrue:[
+     accessFlags := accessFlags bitOr:R_DOUBLE
+     ]
+     ]
+     ].
+     tooManyArgs ifTrue:[
+     ^ ArgumentError
+     raiseRequestWith:self
+     errorString:'too many args in method'
+    ].
+
+    "Modified: / 13-08-2011 / 01:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 setSignature:aString
@@ -1299,36 +1357,9 @@
 
     signature := aString asSymbol.
 
-    numArgs := self class numArgsFromSignature:aString.
-    (tooManyArgs := (numArgs > self class maxNumberOfArguments)) ifTrue:[
-        numArgs := 0.
-    ].
-    self numberOfArgs:numArgs.
-    returnType := self class typeFromSignature:aString in:nil.
-
-    "/ for the convenience of the VM, also mirror the return type in
-    "/ the flags ...
-
-    returnType == #void ifTrue:[
-        accessFlags := accessFlags bitOr:R_VOID
-    ] ifFalse:[
-        returnType == #long ifTrue:[
-            accessFlags := accessFlags bitOr:R_LONG
-        ] ifFalse:[
-            returnType == #double ifTrue:[
-                accessFlags := accessFlags bitOr:R_DOUBLE
-            ]
-        ]
-    ].
-    tooManyArgs ifTrue:[
-        ^ ArgumentError
-            raiseRequestWith:self
-            errorString:'too many args in method'
-    ].
-
     "Created: / 16-04-1996 / 11:34:29 / cg"
     "Modified: / 16-10-1998 / 00:17:12 / cg"
-    "Modified: / 20-10-2010 / 11:29:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 13-08-2011 / 01:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 signature