749
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
4 |
SWING Research Group, Czech Technical University in Prague
|
|
5 |
|
|
6 |
Parts of the code written by Claus Gittinger are under following
|
|
7 |
license:
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
|
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
17 |
|
|
18 |
Permission is hereby granted, free of charge, to any person
|
|
19 |
obtaining a copy of this software and associated documentation
|
|
20 |
files (the 'Software'), to deal in the Software without
|
|
21 |
restriction, including without limitation the rights to use,
|
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23 |
copies of the Software, and to permit persons to whom the
|
|
24 |
Software is furnished to do so, subject to the following
|
|
25 |
conditions:
|
|
26 |
|
|
27 |
The above copyright notice and this permission notice shall be
|
|
28 |
included in all copies or substantial portions of the Software.
|
|
29 |
|
|
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
37 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
38 |
|
|
39 |
[1] Code written at SWING Research Group contain a signature
|
|
40 |
of one of the above copright owners.
|
|
41 |
"
|
|
42 |
"{ Package: 'stx:libjava' }"
|
|
43 |
|
|
44 |
Object subclass:#JavaDescriptor
|
|
45 |
instanceVariableNames:''
|
|
46 |
classVariableNames:'BaseTypes BaseTypesByTypeName ArrayTypes'
|
|
47 |
poolDictionaries:''
|
|
48 |
category:'Languages-Java-Support'
|
|
49 |
!
|
|
50 |
|
|
51 |
!JavaDescriptor class methodsFor:'documentation'!
|
|
52 |
|
|
53 |
copyright
|
|
54 |
"
|
|
55 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
56 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
57 |
SWING Research Group, Czech Technical University in Prague
|
|
58 |
|
|
59 |
Parts of the code written by Claus Gittinger are under following
|
|
60 |
license:
|
|
61 |
|
|
62 |
This software is furnished under a license and may be used
|
|
63 |
only in accordance with the terms of that license and with the
|
|
64 |
inclusion of the above copyright notice. This software may not
|
|
65 |
be provided or otherwise made available to, or used by, any
|
|
66 |
other person. No title to or ownership of the software is
|
|
67 |
hereby transferred.
|
|
68 |
|
|
69 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
70 |
|
|
71 |
Permission is hereby granted, free of charge, to any person
|
|
72 |
obtaining a copy of this software and associated documentation
|
|
73 |
files (the 'Software'), to deal in the Software without
|
|
74 |
restriction, including without limitation the rights to use,
|
|
75 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76 |
copies of the Software, and to permit persons to whom the
|
|
77 |
Software is furnished to do so, subject to the following
|
|
78 |
conditions:
|
|
79 |
|
|
80 |
The above copyright notice and this permission notice shall be
|
|
81 |
included in all copies or substantial portions of the Software.
|
|
82 |
|
|
83 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
84 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
85 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
86 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
87 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
88 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
89 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
90 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
91 |
|
|
92 |
[1] Code written at SWING Research Group contain a signature
|
|
93 |
of one of the above copright owners.
|
|
94 |
|
|
95 |
"
|
|
96 |
! !
|
|
97 |
|
|
98 |
!JavaDescriptor class methodsFor:'instance creation'!
|
|
99 |
|
|
100 |
fromString: aString
|
|
101 |
|
|
102 |
^self readFromString: aString
|
|
103 |
|
|
104 |
"Created: / 25-11-2010 / 18:20:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
105 |
!
|
|
106 |
|
|
107 |
readFrom: aStream
|
|
108 |
|
|
109 |
^ self
|
|
110 |
readFrom:aStream
|
|
111 |
onError:[ self conversionErrorSignal
|
|
112 |
raiseErrorString:'invalid java descriptor']
|
|
113 |
|
|
114 |
"Created: / 25-11-2010 / 18:04:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
115 |
!
|
|
116 |
|
|
117 |
readFrom:stream onError:exceptionBlock
|
|
118 |
|
|
119 |
(stream peek == $( or:[stream peek == $<])
|
|
120 |
ifTrue: [^self readMethodDescriptorFrom: stream onError: exceptionBlock]
|
|
121 |
ifFalse:[^self readFieldDescriptorFrom: stream onError: exceptionBlock].
|
|
122 |
|
|
123 |
"
|
|
124 |
JavaDescriptor fromString:'Ljava/lang/Object;'
|
|
125 |
JavaDescriptor fromString:'[I'
|
|
126 |
JavaDescriptor fromString:'[[I'
|
|
127 |
JavaDescriptor fromString:'(ILjava/lang/Object;)V'
|
|
128 |
JavaDescriptor fromString:'(ILjava/lang/Object;)Ljava/lang/Class;'
|
|
129 |
JavaDescriptor fromString:'<T:Ljava/lang/Object;>(Ljava/util/Collection<TT;>;I)Ljava/util/Collection<TT;>;'
|
|
130 |
|
|
131 |
"
|
|
132 |
|
|
133 |
"Created: / 25-11-2010 / 17:50:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
134 |
"Modified: / 13-08-2011 / 01:37:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
135 |
! !
|
|
136 |
|
|
137 |
!JavaDescriptor class methodsFor:'accessing'!
|
|
138 |
|
|
139 |
baseTypes
|
|
140 |
|
|
141 |
^BaseTypes
|
|
142 |
|
|
143 |
"Created: / 22-05-2011 / 17:45:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
144 |
!
|
|
145 |
|
|
146 |
baseTypesByTypeName
|
|
147 |
|
|
148 |
^BaseTypesByTypeName
|
|
149 |
|
|
150 |
"Created: / 03-02-2011 / 21:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
151 |
! !
|
|
152 |
|
|
153 |
!JavaDescriptor class methodsFor:'class initialization'!
|
|
154 |
|
|
155 |
initialize
|
|
156 |
|
|
157 |
"
|
|
158 |
Tools::NewSystemBrowser basicNew spawnClassBrowserFor: BaseTypes values label:'Java primitive types' in:#newBrowser
|
|
159 |
"
|
|
160 |
|
|
161 |
"/WARNING: If you change something here, you MUST also
|
|
162 |
"/ change JavaField class>>#initialize !!!!!!
|
|
163 |
BaseTypes := IdentityDictionary new
|
|
164 |
at: $B put: Byte;
|
|
165 |
at: $C put: Character;
|
|
166 |
at: $D put: Float;
|
|
167 |
at: $F put: ShortFloat;
|
|
168 |
at: $I put: Integer; "Kludge: instances of java int are in fact SmallIntegers"
|
|
169 |
at: $J put: LargeInteger;
|
|
170 |
at: $S put: Short;
|
|
171 |
at: $Z put: Boolean;
|
|
172 |
at: $V put: UndefinedObject;
|
|
173 |
yourself.
|
|
174 |
|
|
175 |
BaseTypesByTypeName := Dictionary new
|
|
176 |
at: 'byte' put: Byte;
|
|
177 |
at: 'char' put: Character;
|
|
178 |
at: 'double' put: Float;
|
|
179 |
at: 'float' put: ShortFloat;
|
|
180 |
at: 'int' put: Integer; "Kludge: instances of java int are in fact SmallIntegers"
|
|
181 |
at: 'long' put: LargeInteger;
|
|
182 |
at: 'short' put: Short;
|
|
183 |
at: 'boolean' put: Boolean;
|
|
184 |
at: 'void' put: UndefinedObject;
|
|
185 |
yourself.
|
|
186 |
|
|
187 |
"
|
|
188 |
Tools::NewSystemBrowser basicNew spawnClassBrowserFor: ArrayTypes values label:'Java primitive array types' in:#newBrowser
|
|
189 |
"
|
|
190 |
|
|
191 |
"/WARNING: If you change something here, you MUST also
|
|
192 |
"/ change JavaField class>>#initialize !!!!!!
|
|
193 |
|
|
194 |
ArrayTypes := IdentityDictionary new
|
|
195 |
at: $B put: ByteArray;
|
|
196 |
at: $C put: Unicode16String;
|
|
197 |
at: $D put: DoubleArray;
|
|
198 |
at: $F put: FloatArray;
|
|
199 |
at: $I put: SignedIntegerArray;
|
|
200 |
at: $J put: SignedLongIntegerArray;
|
|
201 |
at: $S put: WordArray;
|
|
202 |
at: $Z put: BooleanArray;
|
|
203 |
yourself
|
|
204 |
|
|
205 |
"Created: / 25-11-2010 / 17:51:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
206 |
"Modified: / 10-08-2011 / 00:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
207 |
! !
|
|
208 |
|
|
209 |
!JavaDescriptor class methodsFor:'reading-private'!
|
|
210 |
|
|
211 |
readArrayTypeFrom: stream onError: exceptionBlock
|
|
212 |
|
|
213 |
| p c |
|
|
214 |
stream next. "eat $["
|
|
215 |
p := stream peek.
|
|
216 |
(#(
|
|
217 |
$B "byte"
|
|
218 |
$C "char"
|
|
219 |
$D "double"
|
|
220 |
$F "float"
|
|
221 |
$I "int"
|
|
222 |
$J "long"
|
|
223 |
$S "short"
|
|
224 |
$Z "boolean"
|
|
225 |
) includes: p) ifTrue:[^JavaFieldDescriptor javaClass: (ArrayTypes at: stream next)].
|
|
226 |
|
|
227 |
"OK, not a primitive array..."
|
|
228 |
c := self readFrom: stream onError: exceptionBlock.
|
|
229 |
^JavaFieldDescriptor javaClass: (JavaVM javaArrayClassFor: c javaClass)
|
|
230 |
|
|
231 |
"Created: / 25-11-2010 / 18:12:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
232 |
"Modified: / 06-02-2011 / 23:15:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
233 |
!
|
|
234 |
|
|
235 |
readBaseTypeFrom: stream onError: exceptionBlock
|
|
236 |
|
|
237 |
^JavaFieldDescriptor javaClass: (BaseTypes at: (stream next) ifAbsent: exceptionBlock)
|
|
238 |
|
|
239 |
"Created: / 25-11-2010 / 18:11:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
240 |
!
|
|
241 |
|
|
242 |
readFieldDescriptorFrom: stream onError: exceptionBlock
|
|
243 |
|
|
244 |
| p |
|
|
245 |
p := stream peek.
|
|
246 |
|
|
247 |
p == $L ifTrue:[^self readObjectTypeFrom: stream onError: exceptionBlock].
|
|
248 |
p == $[ ifTrue:[^self readArrayTypeFrom: stream onError: exceptionBlock].
|
|
249 |
(#(
|
|
250 |
$B "byte"
|
|
251 |
$C "char"
|
|
252 |
$D "double"
|
|
253 |
$F "float"
|
|
254 |
$I "int"
|
|
255 |
$J "long"
|
|
256 |
$S "short"
|
|
257 |
$Z "boolean"
|
|
258 |
$V "void"
|
|
259 |
) includes: p) ifTrue:[^self readBaseTypeFrom: stream onError: exceptionBlock].
|
|
260 |
|
|
261 |
exceptionBlock value
|
|
262 |
|
|
263 |
"Created: / 25-11-2010 / 17:55:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
264 |
"Modified: / 21-12-2010 / 22:47:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
265 |
!
|
|
266 |
|
|
267 |
readMethodDescriptorFrom: stream onError: exceptionBlock
|
|
268 |
|
|
269 |
| parameterDescriptors returnDescriptor |
|
|
270 |
|
|
271 |
stream peek == $< ifTrue:[
|
|
272 |
self readTypeVariableFrom: stream onError: exceptionBlock
|
|
273 |
].
|
|
274 |
stream next. "eat $("
|
|
275 |
parameterDescriptors := OrderedCollection new.
|
|
276 |
[ stream peek ~= $) ] whileTrue:[
|
|
277 |
parameterDescriptors add:( self readFieldDescriptorFrom: stream onError: exceptionBlock).
|
|
278 |
].
|
|
279 |
stream next. "eat $)"
|
|
280 |
stream peek == $V ifFalse:[
|
|
281 |
returnDescriptor := self readFieldDescriptorFrom: stream onError: exceptionBlock.
|
|
282 |
] ifTrue:[
|
|
283 |
stream next. "eat $V"
|
|
284 |
].
|
|
285 |
^JavaMethodDescriptor parameters: parameterDescriptors return: returnDescriptor
|
|
286 |
|
|
287 |
"
|
|
288 |
JavaDescriptor fromString:'(ILjava/lang/Object;)V'
|
|
289 |
JavaDescriptor fromString:'(ILjava/lang/Object;)Ljava/lang/Class;'
|
|
290 |
"
|
|
291 |
|
|
292 |
"Created: / 25-11-2010 / 18:36:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
293 |
"Modified: / 13-08-2011 / 01:39:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
294 |
!
|
|
295 |
|
|
296 |
readObjectTypeFrom: stream onError: exceptionBlock
|
|
297 |
|
|
298 |
| clsName out |
|
|
299 |
|
|
300 |
stream next. "/eat $L.
|
|
301 |
out := String new writeStream.
|
|
302 |
[ stream peek ~~ $; and:[stream peek ~~ $< ]] whileTrue:[out nextPut: stream next].
|
|
303 |
clsName := out contents.
|
|
304 |
stream peek == $< ifTrue:[
|
|
305 |
self readTypeVariableFrom: stream onError: exceptionBlock
|
|
306 |
].
|
|
307 |
|
|
308 |
"Just a check"
|
|
309 |
stream next ~= $; ifTrue:[exceptionBlock value].
|
|
310 |
^JavaFieldDescriptor javaClassName: clsName.
|
|
311 |
|
|
312 |
"Created: / 25-11-2010 / 18:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
313 |
!
|
|
314 |
|
|
315 |
readTypeVariableFrom: stream onError: exceptionBlock
|
|
316 |
|
|
317 |
| nangles |
|
|
318 |
|
|
319 |
stream next. "/eat $<.
|
|
320 |
nangles := 1.
|
|
321 |
[ nangles ~~ 0 ] whileTrue:[
|
|
322 |
stream peek == $< ifTrue:[nangles := nangles + 1].
|
|
323 |
stream peek == $> ifTrue:[nangles := nangles - 1].
|
|
324 |
stream next.
|
|
325 |
]
|
|
326 |
|
|
327 |
"Created: / 13-08-2011 / 01:39:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
328 |
! !
|
|
329 |
|
|
330 |
!JavaDescriptor class methodsFor:'documentation'!
|
|
331 |
|
|
332 |
version_SVN
|
2152
|
333 |
^ '$Id: JavaDescriptor.st,v 1.1 2011-08-18 19:06:53 vrany Exp $'
|
749
|
334 |
! !
|
|
335 |
|
2152
|
336 |
JavaDescriptor initialize!
|