author | mawalch |
Mon, 19 Jun 2017 14:41:39 +0200 | |
branch | cvs_MAIN |
changeset 3725 | 1514301e67b4 |
parent 3324 | a58245c0e83a |
permissions | -rw-r--r-- |
2624 | 1 |
" |
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2966
diff
changeset
|
2 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
2624 | 3 |
|
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2966
diff
changeset
|
6 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
2624 | 7 |
SWING Research Group, Czech Technical University in Prague |
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 |
[1] Code written at SWING Research Group contains a signature |
|
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
3725 | 23 |
"{ NameSpace: Smalltalk }" |
24 |
||
2624 | 25 |
JavaMirror subclass:#JavaAlienMirror |
26 |
instanceVariableNames:'' |
|
27 |
classVariableNames:'' |
|
2625
a91a1db9718e
Make JavaMirror to access classes through pool vars.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2624
diff
changeset
|
28 |
poolDictionaries:'JavaVMData' |
2624 | 29 |
category:'Languages-Java-Classes' |
30 |
! |
|
31 |
||
32 |
!JavaAlienMirror class methodsFor:'documentation'! |
|
33 |
||
34 |
copyright |
|
35 |
" |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2966
diff
changeset
|
36 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
2624 | 37 |
|
38 |
New code and modifications done at SWING Research Group [1]: |
|
39 |
||
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2966
diff
changeset
|
40 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
2624 | 41 |
SWING Research Group, Czech Technical University in Prague |
42 |
||
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
||
50 |
[1] Code written at SWING Research Group contains a signature |
|
51 |
of one of the above copright owners. For exact set of such code, |
|
52 |
see the differences between this version and version stx:libjava |
|
53 |
as of 1.9.2010 |
|
54 |
||
55 |
" |
|
56 |
! |
|
57 |
||
58 |
documentation |
|
59 |
" |
|
2966 | 60 |
Specialized mirror for Smalltalk (and all other |
2624 | 61 |
non-Java classes) |
62 |
||
63 |
[author:] |
|
64 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
65 |
||
66 |
[instance variables:] |
|
67 |
||
68 |
[class variables:] |
|
69 |
||
70 |
[see also:] |
|
71 |
||
72 |
" |
|
73 |
! ! |
|
74 |
||
75 |
!JavaAlienMirror methodsFor:'accessing'! |
|
76 |
||
77 |
getClassLoader |
|
78 |
"Returns a class loader that loaded this class" |
|
79 |
||
80 |
^ (JavaVM classForName:'stx.libjava.ClassLoader' definedBy: nil) instVarNamed: #scl. |
|
81 |
||
82 |
"Modified: / 18-05-2013 / 10:57:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
83 |
! |
|
84 |
||
85 |
getDeclaredConstructors:publicOnly |
|
2966 | 86 |
"Returns an java.lang.reflect.Constructor[] with all constructors |
2624 | 87 |
declared by this class" |
88 |
||
3725 | 89 |
"Here, return only default constructor. Later, all methods annotated |
90 |
with <jsignature: #'<init>(...)V'> will be returned as well" |
|
2624 | 91 |
|
92 |
| ctors | |
|
93 |
||
94 |
ctors := OrderedCollection new. |
|
95 |
klass selectorsAndMethodsDo:[:sel :mthd| |
|
96 |
(self isJavaConstructor: mthd selector: sel) ifTrue:[ |
|
97 |
ctors add: (self getDeclaredConstructorFor: mthd). |
|
98 |
]. |
|
99 |
]. |
|
100 |
||
101 |
ctors isEmpty ifTrue:[ |
|
2966 | 102 |
"/If no constructor is found, fake default one... |
2624 | 103 |
ctors add: (self getDeclaredConstructorFor: (klass lookupMethodFor: #initialize)). |
104 |
]. |
|
105 |
||
2966 | 106 |
^_java_lang_reflect_Constructor_CLASS javaArrayClass withAll: ctors |
2624 | 107 |
|
108 |
"Modified: / 18-05-2013 / 10:57:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3725 | 109 |
"Modified (comment): / 19-06-2017 / 14:35:18 / mawalch" |
2624 | 110 |
! |
111 |
||
112 |
getDeclaredFields:publicOnly |
|
2966 | 113 |
"Returns an java.lang.reflect.Field[] with all constructors |
2624 | 114 |
declared by this class." |
115 |
||
2966 | 116 |
| fields | |
2624 | 117 |
|
118 |
fields := OrderedCollection new. |
|
119 |
||
120 |
klass instVarNames withIndexDo:[:nm :index| |
|
121 |
| field | |
|
122 |
||
123 |
field := JavaField new. |
|
2966 | 124 |
field |
2624 | 125 |
setAccessFlags: JavaConstants ACC_PROTECTED; |
126 |
setClass: klass; |
|
127 |
setIndex: klass superclass instSize + index; |
|
128 |
setDescriptor: #'Ljava/lang/Object;'; |
|
129 |
setName: nm. |
|
130 |
||
131 |
fields add: (self createFieldFor: field) |
|
132 |
]. |
|
133 |
||
2966 | 134 |
^ _java_lang_reflect_Field_CLASS javaArrayClass |
2624 | 135 |
withAll:fields |
136 |
||
137 |
"Modified: / 18-05-2013 / 10:57:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
138 |
! |
|
139 |
||
2966 | 140 |
getDeclaredMethods:publicOnly |
141 |
"Returns an java.lang.reflect.Method[] with all methods |
|
2624 | 142 |
declared by this class" |
143 |
||
144 |
| methods | |
|
145 |
||
146 |
methods := OrderedCollection new. |
|
147 |
klass selectorsAndMethodsDo:[:sel :mthd| |
|
148 |
(self isJavaMethod: mthd selector: sel) ifTrue:[ |
|
149 |
methods add: (self getDeclaredMethodFor: mthd). |
|
150 |
]. |
|
151 |
]. |
|
2966 | 152 |
^_java_lang_reflect_Method_CLASS javaArrayClass withAll: methods |
2624 | 153 |
|
154 |
"Modified: / 18-05-2013 / 10:57:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
155 |
! |
|
156 |
||
157 |
getInterfaces |
|
158 |
"Return a list if interfaces" |
|
159 |
||
160 |
^ Array with: (JavaVM classForName: 'java.lang.Cloneable' definedBy: nil) |
|
161 |
||
162 |
"Modified: / 18-05-2013 / 10:57:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
163 |
! |
|
164 |
||
165 |
getModifiers |
|
166 |
"Return class modifiers (public/abstract/final...)" |
|
167 |
||
168 |
^ JavaConstants ACC_PUBLIC |
|
169 |
||
170 |
"Modified: / 22-08-2012 / 11:01:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
171 |
! |
|
172 |
||
173 |
getName |
|
174 |
"Returns name of the class" |
|
175 |
^'SMALLTALK.' , klass name |
|
176 |
||
177 |
"Created: / 22-08-2012 / 10:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
178 |
! ! |
|
179 |
||
180 |
!JavaAlienMirror methodsFor:'accessing-private'! |
|
181 |
||
182 |
getDeclaredConstructorFor: method |
|
2966 | 183 |
^ self |
184 |
createConstructorFor: klass |
|
185 |
method: method |
|
2624 | 186 |
signature: (self getSignatureForConstructor: method) |
2966 | 187 |
modifiers: JavaConstants ACC_PUBLIC |
188 |
parameterTyoes: #() |
|
189 |
exceptionTypes: #() |
|
2624 | 190 |
annotations: JavaMethodAnnotationContainer new |
191 |
||
192 |
"Created: / 22-08-2012 / 11:36:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
193 |
! |
|
194 |
||
195 |
getDeclaredMethodFor:method |
|
2626
e695e8f5dd12
Workaround in JavaAlienMirror.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2625
diff
changeset
|
196 |
| signature name | |
2624 | 197 |
|
198 |
signature := self getSignatureForMethod: method short: false. |
|
2966 | 199 |
name := signature upTo: $(. |
200 |
^ self |
|
201 |
createMethodFor: klass |
|
202 |
method: method |
|
2624 | 203 |
name: name |
204 |
signature: signature |
|
2966 | 205 |
modifiers: JavaConstants ACC_PUBLIC |
206 |
parameterTyoes: ((1 to: method selector numArgs)collect:[:i|_java_lang_Object_CLASS]) |
|
207 |
returnType: _java_lang_Object_CLASS |
|
208 |
exceptionTypes: #() |
|
2624 | 209 |
annotations: JavaMethodAnnotationContainer new |
210 |
||
211 |
"Created: / 22-08-2012 / 11:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
212 |
! |
|
213 |
||
214 |
getSignatureForConstructor: method |
|
215 |
| signature | |
|
216 |
||
217 |
signature := |
|
218 |
(String streamContents:[:s| |
|
219 |
s nextPutAll: '<init>('. |
|
220 |
method selector numArgs timesRepeat:[ |
|
221 |
s nextPutAll:'Ljava/lang/Object;'. |
|
222 |
]. |
|
223 |
s nextPutAll: ')V'. |
|
224 |
]) asSymbol. |
|
225 |
^signature |
|
226 |
||
227 |
"Created: / 22-08-2012 / 11:40:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
228 |
! |
|
229 |
||
230 |
getSignatureForMethod: method short: short |
|
231 |
| selector signature | |
|
232 |
||
233 |
selector := method selector. |
|
234 |
signature := |
|
235 |
(String streamContents:[:s| |
|
236 |
short ifTrue:[ |
|
237 |
s nextPutAll: (selector upTo: $:) |
|
238 |
] ifFalse:[ |
|
239 |
selector numArgs == 1 ifTrue:[ |
|
240 |
s nextPutAll: (selector copyTo: selector size - 1) |
|
241 |
] ifFalse:[ |
|
242 |
s nextPutAll: (selector copyReplaceAll: $: with: $_) |
|
243 |
] |
|
244 |
]. |
|
245 |
s nextPut: $(. |
|
246 |
method selector numArgs timesRepeat:[ |
|
247 |
s nextPutAll:'Ljava/lang/Object;'. |
|
248 |
]. |
|
249 |
s nextPutAll: ')'. |
|
250 |
s nextPutAll:'Ljava/lang/Object;'. |
|
251 |
]) asSymbol. |
|
252 |
^signature |
|
253 |
||
254 |
"Created: / 22-08-2012 / 11:46:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 |
! ! |
|
256 |
||
257 |
!JavaAlienMirror methodsFor:'testing-private'! |
|
258 |
||
259 |
isJavaConstructor: mthd selector: sel |
|
260 |
||
261 |
^sel startsWith: #initialize |
|
262 |
||
263 |
"Created: / 22-08-2012 / 11:47:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
264 |
! |
|
265 |
||
266 |
isJavaMethod: mthd selector: sel |
|
267 |
||
2966 | 268 |
^sel isBinarySelector not |
2624 | 269 |
and:[(self isJavaConstructor: mthd selector: sel) not] |
270 |
||
271 |
"Created: / 22-08-2012 / 11:47:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
272 |
! ! |
|
273 |
||
274 |
!JavaAlienMirror class methodsFor:'documentation'! |
|
275 |
||
3725 | 276 |
version |
277 |
^ '$Header$' |
|
278 |
! |
|
279 |
||
280 |
version_CVS |
|
281 |
^ '$Header$' |
|
282 |
! |
|
283 |
||
2624 | 284 |
version_HG |
285 |
||
286 |
^ '$Changeset: <not expanded> $' |
|
287 |
! ! |
|
288 |