author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 24 May 2013 17:55:42 +0100 | |
branch | builtin-class-support |
changeset 2629 | cedb88626902 |
parent 2625 | a91a1db9718e |
child 2966 | afd174546057 |
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:#JavaClassMirror |
|
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 |
!JavaClassMirror 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 |
" |
|
58 |
A specialized mirror for all Java classes |
|
59 |
||
60 |
[author:] |
|
61 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
|
62 |
||
63 |
[instance variables:] |
|
64 |
||
65 |
[class variables:] |
|
66 |
||
67 |
[see also:] |
|
68 |
||
69 |
" |
|
70 |
! ! |
|
71 |
||
72 |
!JavaClassMirror methodsFor:'accessing'! |
|
73 |
||
74 |
getClassLoader |
|
75 |
"Returns a class loader that loaded this class" |
|
76 |
||
77 |
^ klass classLoader |
|
78 |
||
79 |
"Modified: / 31-07-2012 / 18:26:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
80 |
! |
|
81 |
||
82 |
getDeclaredConstructors:publicOnly |
|
83 |
"Returns an java.lang.reflect.Constructor[] with all constructors |
|
84 |
declared by this class" |
|
85 |
||
86 |
| ctors | |
|
87 |
||
88 |
ctors := OrderedCollection new. |
|
89 |
klass selectorsAndMethodsDo:[:sel :mthd| |
|
90 |
(mthd isJavaConstructor and:[publicOnly not or:[mthd isPublic]]) ifTrue:[ |
|
91 |
ctors add: (self getDeclaredConstructorFor: mthd). |
|
92 |
]. |
|
93 |
]. |
|
2625
a91a1db9718e
Make JavaMirror to access classes through pool vars.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2624
diff
changeset
|
94 |
^java_lang_reflect_Constructor javaArrayClass withAll: ctors |
2624 | 95 |
|
96 |
"Modified: / 18-05-2013 / 10:56:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
97 |
! |
|
98 |
||
99 |
getDeclaredFields:publicOnly |
|
100 |
"Returns an java.lang.reflect.Field[] with all constructors |
|
101 |
declared by this class." |
|
102 |
||
103 |
| fields | |
|
104 |
||
105 |
fields := klass fields , klass staticFields. |
|
106 |
publicOnly ifTrue:[ fields := fields select:[:f | f isPublic ] ]. |
|
107 |
JavaClassReader classLoaderQuerySignal answer: klass classLoader do:[ |
|
108 |
fields := fields collect:[:f | self createFieldFor:f ]. |
|
109 |
]. |
|
2625
a91a1db9718e
Make JavaMirror to access classes through pool vars.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2624
diff
changeset
|
110 |
^ java_lang_reflect_Field javaArrayClass |
2624 | 111 |
withAll:fields |
112 |
||
113 |
"Modified: / 18-05-2013 / 10:57:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
114 |
! |
|
115 |
||
116 |
getDeclaredMethods:publicOnly |
|
117 |
"Returns an java.lang.reflect.Constructor[] with all constructors |
|
118 |
declared by this class" |
|
119 |
||
120 |
| methods | |
|
121 |
||
122 |
methods := OrderedCollection new. |
|
123 |
klass selectorsAndMethodsDo:[:sel :mthd| |
|
124 |
mthd isJavaMethod and:[ |
|
125 |
(mthd isJavaConstructor not |
|
126 |
and:[mthd isJavaStaticInitializer not |
|
127 |
and:[publicOnly not or:[mthd isPublic]]]) ifTrue:[ |
|
128 |
methods add: (self getDeclaredMethodFor: mthd). |
|
129 |
] |
|
130 |
]. |
|
131 |
]. |
|
2625
a91a1db9718e
Make JavaMirror to access classes through pool vars.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2624
diff
changeset
|
132 |
^java_lang_reflect_Method javaArrayClass withAll: methods |
2624 | 133 |
|
134 |
"Modified: / 18-05-2013 / 10:57:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
135 |
! |
|
136 |
||
137 |
getGenericSignature |
|
138 |
"Returns Java generic signature (if a generic class) or nil" |
|
139 |
||
140 |
^klass signatureJ |
|
141 |
||
142 |
"Created: / 22-08-2012 / 11:58:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
143 |
! |
|
144 |
||
145 |
getInterfaces |
|
146 |
"Return a list if interfaces" |
|
147 |
||
148 |
^ klass interfaces |
|
149 |
||
150 |
"Modified: / 22-08-2012 / 11:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
151 |
! |
|
152 |
||
153 |
getModifiers |
|
154 |
"Return class modifiers (public/abstract/final...)" |
|
155 |
||
156 |
| modifiers | |
|
157 |
||
158 |
"According to OpenJDK JVM, strip ACC_SUPER" |
|
159 |
modifiers := (klass accessFlags & JavaConstants ACC_SUPER bitInvert) & 16r7FFF. |
|
160 |
"JV@2011-10-30: It seems that private inner classes has no |
|
161 |
private bit set, sigh" |
|
162 |
(modifiers & 16r0007) == 0 ifTrue:[ |
|
163 |
modifiers := modifiers | JavaConstants ACC_PRIVATE. |
|
164 |
]. |
|
165 |
^modifiers |
|
166 |
||
167 |
"Modified: / 22-08-2012 / 11:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! |
|
169 |
||
170 |
getProtectionDomain |
|
171 |
^klass protectionDomain |
|
172 |
||
173 |
"Created: / 22-08-2012 / 12:56:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
174 |
! ! |
|
175 |
||
176 |
!JavaClassMirror methodsFor:'accessing-private'! |
|
177 |
||
178 |
getDeclaredConstructorFor: method |
|
179 |
||
180 |
^self createConstructorFor: method javaClass |
|
181 |
method: method |
|
182 |
signature: method signature |
|
183 |
modifiers: method accessFlags |
|
184 |
parameterTyoes: (method descriptor parameterClassesUsingClassLoader: method javaClass classLoader) |
|
185 |
exceptionTypes: method exceptionClasses |
|
186 |
annotations: method method annotations. |
|
187 |
||
188 |
"Created: / 01-08-2012 / 00:46:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
189 |
! |
|
190 |
||
191 |
getDeclaredMethodFor: method |
|
192 |
||
193 |
^self createMethodFor: method javaClass |
|
194 |
method: method |
|
195 |
name: (method selector upTo: $() |
|
196 |
signature: method signature |
|
197 |
modifiers: method accessFlags |
|
198 |
parameterTyoes: (method descriptor parameterClassesUsingClassLoader: method javaClass classLoader) |
|
199 |
returnType: (method descriptor returnClassUsingClassLoader: method javaClass classLoader) |
|
200 |
exceptionTypes: method exceptionClasses |
|
201 |
annotations: method method annotations. |
|
202 |
||
203 |
"Created: / 01-08-2012 / 11:11:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
204 |
! ! |
|
205 |
||
206 |
!JavaClassMirror class methodsFor:'documentation'! |
|
207 |
||
208 |
version_HG |
|
209 |
||
210 |
^ '$Changeset: <not expanded> $' |
|
211 |
! ! |
|
212 |