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