author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 27 Sep 2018 23:09:30 +0100 | |
changeset 3854 | 193b04caef42 |
parent 3420 | ccf78c0c7a3b |
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 |
||
3420
ccf78c0c7a3b
Interop: fixed access to Smalltalk class loader
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3324
diff
changeset
|
23 |
"{ NameSpace: Smalltalk }" |
ccf78c0c7a3b
Interop: fixed access to Smalltalk class loader
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3324
diff
changeset
|
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 |
||
3420
ccf78c0c7a3b
Interop: fixed access to Smalltalk class loader
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3324
diff
changeset
|
80 |
^ JavaVM smalltalkClassLoader |
2624 | 81 |
|
3420
ccf78c0c7a3b
Interop: fixed access to Smalltalk class loader
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3324
diff
changeset
|
82 |
"Modified: / 03-04-2015 / 16:25:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2624 | 83 |
! |
84 |
||
85 |
getDeclaredConstructors:publicOnly |
|
2966 | 86 |
"Returns an java.lang.reflect.Constructor[] with all constructors |
2624 | 87 |
declared by this class" |
88 |
||
89 |
"Here, return onlu default constructor. Later, all methods annotated |
|
90 |
with <jsignature: #'<init>(...)V'> wil be returned as well" |
|
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>" |
|
109 |
! |
|
110 |
||
111 |
getDeclaredFields:publicOnly |
|
2966 | 112 |
"Returns an java.lang.reflect.Field[] with all constructors |
2624 | 113 |
declared by this class." |
114 |
||
2966 | 115 |
| fields | |
2624 | 116 |
|
117 |
fields := OrderedCollection new. |
|
118 |
||
119 |
klass instVarNames withIndexDo:[:nm :index| |
|
120 |
| field | |
|
121 |
||
122 |
field := JavaField new. |
|
2966 | 123 |
field |
2624 | 124 |
setAccessFlags: JavaConstants ACC_PROTECTED; |
125 |
setClass: klass; |
|
126 |
setIndex: klass superclass instSize + index; |
|
127 |
setDescriptor: #'Ljava/lang/Object;'; |
|
128 |
setName: nm. |
|
129 |
||
130 |
fields add: (self createFieldFor: field) |
|
131 |
]. |
|
132 |
||
2966 | 133 |
^ _java_lang_reflect_Field_CLASS javaArrayClass |
2624 | 134 |
withAll:fields |
135 |
||
136 |
"Modified: / 18-05-2013 / 10:57:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
137 |
! |
|
138 |
||
2966 | 139 |
getDeclaredMethods:publicOnly |
140 |
"Returns an java.lang.reflect.Method[] with all methods |
|
2624 | 141 |
declared by this class" |
142 |
||
143 |
| methods | |
|
144 |
||
145 |
methods := OrderedCollection new. |
|
146 |
klass selectorsAndMethodsDo:[:sel :mthd| |
|
147 |
(self isJavaMethod: mthd selector: sel) ifTrue:[ |
|
148 |
methods add: (self getDeclaredMethodFor: mthd). |
|
149 |
]. |
|
150 |
]. |
|
2966 | 151 |
^_java_lang_reflect_Method_CLASS javaArrayClass withAll: methods |
2624 | 152 |
|
153 |
"Modified: / 18-05-2013 / 10:57:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
154 |
! |
|
155 |
||
156 |
getInterfaces |
|
157 |
"Return a list if interfaces" |
|
158 |
||
159 |
^ Array with: (JavaVM classForName: 'java.lang.Cloneable' definedBy: nil) |
|
160 |
||
161 |
"Modified: / 18-05-2013 / 10:57:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
162 |
! |
|
163 |
||
164 |
getModifiers |
|
165 |
"Return class modifiers (public/abstract/final...)" |
|
166 |
||
167 |
^ JavaConstants ACC_PUBLIC |
|
168 |
||
169 |
"Modified: / 22-08-2012 / 11:01:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
170 |
! |
|
171 |
||
172 |
getName |
|
173 |
"Returns name of the class" |
|
174 |
^'SMALLTALK.' , klass name |
|
175 |
||
176 |
"Created: / 22-08-2012 / 10:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
177 |
! ! |
|
178 |
||
179 |
!JavaAlienMirror methodsFor:'accessing-private'! |
|
180 |
||
181 |
getDeclaredConstructorFor: method |
|
2966 | 182 |
^ self |
183 |
createConstructorFor: klass |
|
184 |
method: method |
|
2624 | 185 |
signature: (self getSignatureForConstructor: method) |
2966 | 186 |
modifiers: JavaConstants ACC_PUBLIC |
187 |
parameterTyoes: #() |
|
188 |
exceptionTypes: #() |
|
2624 | 189 |
annotations: JavaMethodAnnotationContainer new |
190 |
||
191 |
"Created: / 22-08-2012 / 11:36:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
192 |
! |
|
193 |
||
194 |
getDeclaredMethodFor:method |
|
2626
e695e8f5dd12
Workaround in JavaAlienMirror.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2625
diff
changeset
|
195 |
| signature name | |
2624 | 196 |
|
197 |
signature := self getSignatureForMethod: method short: false. |
|
2966 | 198 |
name := signature upTo: $(. |
199 |
^ self |
|
200 |
createMethodFor: klass |
|
201 |
method: method |
|
2624 | 202 |
name: name |
203 |
signature: signature |
|
2966 | 204 |
modifiers: JavaConstants ACC_PUBLIC |
205 |
parameterTyoes: ((1 to: method selector numArgs)collect:[:i|_java_lang_Object_CLASS]) |
|
206 |
returnType: _java_lang_Object_CLASS |
|
207 |
exceptionTypes: #() |
|
2624 | 208 |
annotations: JavaMethodAnnotationContainer new |
209 |
||
210 |
"Created: / 22-08-2012 / 11:36:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 |
! |
|
212 |
||
213 |
getSignatureForConstructor: method |
|
214 |
| signature | |
|
215 |
||
216 |
signature := |
|
217 |
(String streamContents:[:s| |
|
218 |
s nextPutAll: '<init>('. |
|
219 |
method selector numArgs timesRepeat:[ |
|
220 |
s nextPutAll:'Ljava/lang/Object;'. |
|
221 |
]. |
|
222 |
s nextPutAll: ')V'. |
|
223 |
]) asSymbol. |
|
224 |
^signature |
|
225 |
||
226 |
"Created: / 22-08-2012 / 11:40:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
227 |
! |
|
228 |
||
229 |
getSignatureForMethod: method short: short |
|
230 |
| selector signature | |
|
231 |
||
232 |
selector := method selector. |
|
233 |
signature := |
|
234 |
(String streamContents:[:s| |
|
235 |
short ifTrue:[ |
|
236 |
s nextPutAll: (selector upTo: $:) |
|
237 |
] ifFalse:[ |
|
238 |
selector numArgs == 1 ifTrue:[ |
|
239 |
s nextPutAll: (selector copyTo: selector size - 1) |
|
240 |
] ifFalse:[ |
|
241 |
s nextPutAll: (selector copyReplaceAll: $: with: $_) |
|
242 |
] |
|
243 |
]. |
|
244 |
s nextPut: $(. |
|
245 |
method selector numArgs timesRepeat:[ |
|
246 |
s nextPutAll:'Ljava/lang/Object;'. |
|
247 |
]. |
|
248 |
s nextPutAll: ')'. |
|
249 |
s nextPutAll:'Ljava/lang/Object;'. |
|
250 |
]) asSymbol. |
|
251 |
^signature |
|
252 |
||
253 |
"Created: / 22-08-2012 / 11:46:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
254 |
! ! |
|
255 |
||
256 |
!JavaAlienMirror methodsFor:'testing-private'! |
|
257 |
||
258 |
isJavaConstructor: mthd selector: sel |
|
259 |
||
260 |
^sel startsWith: #initialize |
|
261 |
||
262 |
"Created: / 22-08-2012 / 11:47:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
263 |
! |
|
264 |
||
265 |
isJavaMethod: mthd selector: sel |
|
266 |
||
2966 | 267 |
^sel isBinarySelector not |
2624 | 268 |
and:[(self isJavaConstructor: mthd selector: sel) not] |
269 |
||
270 |
"Created: / 22-08-2012 / 11:47:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
271 |
! ! |
|
272 |
||
273 |
!JavaAlienMirror class methodsFor:'documentation'! |
|
274 |
||
275 |
version_HG |
|
276 |
||
277 |
^ '$Changeset: <not expanded> $' |
|
278 |
! ! |
|
279 |