author | vranyj1 |
Tue, 26 Jul 2011 16:31:02 +0000 | |
branch | jk_new_structure |
changeset 877 | f5a5b93e1c78 |
parent 851 | fc38cc6ed478 |
child 882 | f41881c0c866 |
permissions | -rw-r--r-- |
877 | 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 |
" |
|
758 | 42 |
"{ Package: 'stx:libjava' }" |
43 |
||
44 |
Object subclass:#JavaResolver |
|
761 | 45 |
instanceVariableNames:'exceptionThrower' |
758 | 46 |
classVariableNames:'uniqueInstance' |
47 |
poolDictionaries:'' |
|
48 |
category:'Languages-Java-Reader-Support-new' |
|
49 |
! |
|
50 |
||
877 | 51 |
!JavaResolver 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 |
! ! |
|
758 | 97 |
|
98 |
!JavaResolver class methodsFor:'initialization'! |
|
99 |
||
100 |
initialize |
|
101 |
uniqueInstance := JavaResolver new. |
|
761 | 102 |
uniqueInstance exceptionThrower: JavaVM. |
103 |
||
758 | 104 |
"/has methods at: and at: put: |
759
66d28d2fa62e
JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents:
758
diff
changeset
|
105 |
"/uniqueInstance resolvedClasses: Java. |
758 | 106 |
|
759
66d28d2fa62e
JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents:
758
diff
changeset
|
107 |
"Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 108 |
"Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 109 |
! ! |
110 |
||
111 |
!JavaResolver class methodsFor:'instance creation'! |
|
112 |
||
113 |
uniqueInstance |
|
761 | 114 |
^uniqueInstance. |
758 | 115 |
|
116 |
"Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
761 | 117 |
"Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
118 |
! ! |
|
119 |
||
120 |
!JavaResolver methodsFor:'accessing'! |
|
121 |
||
122 |
exceptionThrower |
|
123 |
^ exceptionThrower |
|
124 |
! |
|
125 |
||
126 |
exceptionThrower:something |
|
127 |
exceptionThrower := something. |
|
758 | 128 |
! ! |
129 |
||
130 |
!JavaResolver methodsFor:'class resolving'! |
|
131 |
||
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
132 |
checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
133 |
|
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
134 |
^ (JavaDescriptor readFromString: aJavaClassRef name) javaClass. |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
135 |
|
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
136 |
"Created: / 23-05-2011 / 21:12:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
137 |
! |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
138 |
|
761 | 139 |
resolveClassIndentifiedByRef: aJavaClassRef |
758 | 140 |
| classLoader result | |
141 |
||
761 | 142 |
self validateClassRef: aJavaClassRef. |
143 |
result := self lookupClassIfAlreadyResolved: aJavaClassRef javaClassName. |
|
758 | 144 |
result ifNotNil: |
145 |
[ "/wrap result with array(s) if needed and return it |
|
761 | 146 |
self checkIfArrayRef: aJavaClassRef andWrap: result ]. |
758 | 147 |
" |
148 |
To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, |
|
149 |
the following steps are performed: |
|
150 |
The defining class loader of D is used to create a class or interface denoted by N. |
|
151 |
This class or interface is C. Any exception that can be thrown as a result of failure |
|
152 |
of class or interface creation can thus be thrown as a result of failure of class and |
|
153 |
interface resolution. The details of the process are given in Section 5.3. |
|
154 |
" |
|
761 | 155 |
classLoader := aJavaClassRef classLoader. |
758 | 156 |
classLoader isNil |
814
68df82c46fb0
finally forced myself to refactor tests.. fieldRef tests are ok now.. methodRef to come..
hlopkmar
parents:
813
diff
changeset
|
157 |
ifTrue: [ result := self loadUnresolvedClass: aJavaClassRef ] |
758 | 158 |
ifFalse: |
761 | 159 |
[ result := self loadUnresolvedClass: aJavaClassRef |
160 |
withJavaClassLoader: classLoader. ]. |
|
774 | 161 |
result ifNil: |
784 | 162 |
[ self halt. |
814
68df82c46fb0
finally forced myself to refactor tests.. fieldRef tests are ok now.. methodRef to come..
hlopkmar
parents:
813
diff
changeset
|
163 |
"tell mh, he will throw exception instead, for now, he wants to halt." ]. |
68df82c46fb0
finally forced myself to refactor tests.. fieldRef tests are ok now.. methodRef to come..
hlopkmar
parents:
813
diff
changeset
|
164 |
result isJavaPrimitiveType |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
165 |
ifTrue: [ ^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result ]. |
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
166 |
result classInit. |
758 | 167 |
" |
168 |
If C is an array class and its element type is a reference type, then the symbolic reference |
|
169 |
to the class or interface representing the element type is resolved by invoking the algorithm |
|
170 |
in Section 5.4.3.1 recursively." |
|
761 | 171 |
result := self checkIfArrayRef: aJavaClassRef andWrap: result. |
758 | 172 |
"Finally, access permissions to C are checked: |
761 | 173 |
If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError. |
758 | 174 |
This condition can occur, for example, if C is a class that was originally declared to be |
175 |
public but was changed to be non-public after D was compiled. |
|
176 |
||
177 |
If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution |
|
178 |
fails, and D is prohibited from accessing C." |
|
761 | 179 |
(self checkPermissionsFrom: aJavaClassRef owner to: result) |
180 |
ifTrue: [ ^ result ] |
|
181 |
ifFalse: [ self throwIllegalAccessError ]. |
|
758 | 182 |
|
761 | 183 |
"Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
184 |
"Modified: / 22-05-2011 / 17:59:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
185 |
"Modified: / 23-05-2011 / 21:11:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 186 |
! ! |
187 |
||
188 |
!JavaResolver methodsFor:'class resolving helpers'! |
|
189 |
||
761 | 190 |
checkIfArrayRef: aJavaClassRef andWrap: result |
191 |
"/wrap result with array(s) if needed and return it |
|
192 |
^ aJavaClassRef isJavaArrayClassRef |
|
193 |
ifFalse: [ result ] |
|
194 |
ifTrue: [ self wrapJavaClass: result withArrayAsSpecifiedIn: aJavaClassRef ] |
|
195 |
||
196 |
"Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
197 |
! |
|
198 |
||
199 |
checkPermissionsFrom: refOwner to: resolvedClass |
|
200 |
" |
|
201 |
A class or interface C is accessible to a class or interface D if and only if either of the following conditions are true: |
|
202 |
C is public. |
|
203 |
C and D are members of the same runtime package (§5.3). |
|
204 |
Finally, access permissions to C are checked: |
|
205 |
If C is not accessible (§5.4.4) to D, class or interface resolution throws an IllegalAccessError. |
|
206 |
This condition can occur, for example, if C is a class that was originally declared to be |
|
207 |
public but was changed to be non-public after D was compiled. |
|
208 |
At run time, a class or interface is determined not by its name alone, |
|
209 |
but by a pair: its fully qualified name and its defining class loader. |
|
210 |
Each such class or interface belongs to a single runtime package. The runtime |
|
211 |
package of a class or interface is determined by the package name and |
|
212 |
defining class loader of the class or interface." |
|
213 |
||
214 |
resolvedClass isPublic ifTrue: [ ^ true ]. |
|
215 |
resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false ]. |
|
216 |
^ refOwner javaPackage = resolvedClass javaPackage. |
|
217 |
||
218 |
"Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
219 |
"Modified: / 13-04-2011 / 23:13:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
220 |
! |
|
221 |
||
222 |
loadUnresolvedClass: aJavaClassRef |
|
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
223 |
| nm | |
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
224 |
|
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
225 |
nm := aJavaClassRef javaClassName. |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
226 |
nm size == 1 |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
227 |
and: [ JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] ]. |
805 | 228 |
^ Java classForName: aJavaClassRef javaClassName. |
761 | 229 |
|
230 |
"Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
231 |
"Modified: / 22-05-2011 / 17:58:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
232 |
"Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 233 |
! |
234 |
||
235 |
loadUnresolvedClass: aJavaClassRef withJavaClassLoader: classLoader |
|
798
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
236 |
| jClass | |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
237 |
|
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
238 |
jClass := classLoader |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
239 |
perform: #'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
240 |
with: (Java as_String: (aJavaClassRef name)). |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
241 |
^JavaVM reflection classForJavaClassObject: jClass. |
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
242 |
|
b534e73eaf7e
JavaClassReader2 now uses correct superclass loading
hlopkmar
parents:
796
diff
changeset
|
243 |
"Modified: / 18-05-2011 / 14:52:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 244 |
! |
245 |
||
246 |
lookupClassIfAlreadyResolved: javaClassName |
|
247 |
^ nil |
|
248 |
||
249 |
"Modified: / 13-04-2011 / 14:05:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
250 |
! |
|
251 |
||
252 |
validateClassRef: aJavaClassRef |
|
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
253 |
self assert: aJavaClassRef isJavaRef. |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
254 |
self assert: aJavaClassRef isJavaClassRef . |
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
255 |
|
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
256 |
"Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 257 |
! |
258 |
||
851 | 259 |
wrapJavaClass:aJavaClass withArrayAsSpecifiedIn:aJavaClassRef |
758 | 260 |
"wraps aJavaClass with as many array dimensions as needed (zero means no array)" |
813
cb429d02faca
fixed my really stupid bug in JavaResolver>>wrapJavaClas..
hlopkmar
parents:
812
diff
changeset
|
261 |
|
851 | 262 |
|arrayClass| |
758 | 263 |
|
851 | 264 |
aJavaClassRef isJavaArrayClassRef ifFalse:[ ^ aJavaClass ]. |
265 |
aJavaClassRef arrayDimensions timesRepeat: |
|
813
cb429d02faca
fixed my really stupid bug in JavaResolver>>wrapJavaClas..
hlopkmar
parents:
812
diff
changeset
|
266 |
[ arrayClass := aJavaClass. |
851 | 267 |
arrayClass := arrayClass javaArrayClass. ]. |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
268 |
^ arrayClass. |
758 | 269 |
|
270 |
"Created: / 08-04-2011 / 18:40:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
271 |
"Modified: / 22-05-2011 / 17:48:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
817
3f2405c6ef88
its nice to work after jv :) after writing tests I surprisedly realized, that he already implemented primitives and primitive arrays in JavaClassRef2 :)
hlopkmar
parents:
816
diff
changeset
|
272 |
"Modified: / 23-05-2011 / 21:06:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 273 |
! ! |
274 |
||
761 | 275 |
!JavaResolver methodsFor:'common helpers'! |
276 |
||
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
277 |
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass |
761 | 278 |
"A class or interface C is accessible to a class or interface D if |
279 |
and only if either of the following conditions are true: |
|
280 |
C is public. |
|
281 |
C and D are members of the same runtime package (§5.3). |
|
282 |
A field or method R is accessible to a class or interface D if and only |
|
283 |
if any of the following conditions is true: |
|
284 |
R is public. |
|
285 |
R is protected and is declared in a class C, and D is either a subclass |
|
286 |
of C or C itself. |
|
287 |
R is either protected or package private (that is, neither public nor |
|
288 |
protected nor private), and is declared by a class in the same runtime |
|
289 |
package as D. |
|
290 |
R is private and is declared in D. |
|
291 |
This discussion of access control omits a related restriction on the target |
|
292 |
of a protected field access or method invocation (the target must be of class |
|
293 |
D or a subtype of D). That requirement is checked as part of the verification |
|
294 |
process (§5.4.1); it is not part of link-time access control." |
|
295 |
||
846 | 296 |
(self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [ |
297 |
^ false |
|
298 |
]. |
|
299 |
aJavaMethodOrField isPublic ifTrue: [ |
|
300 |
^ true |
|
301 |
]. |
|
302 |
((aJavaMethodOrField isProtected |
|
303 |
and: [ |
|
304 |
resolvedJavaClass javaComponentClass |
|
305 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
306 |
]) |
|
307 |
and: [ |
|
308 |
accessingJavaClass javaComponentClass |
|
309 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
310 |
]) |
|
821
560f60ad3a2a
fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents:
819
diff
changeset
|
311 |
ifTrue: [ ^ true ]. |
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
312 |
((aJavaMethodOrField isPrivate not |
761 | 313 |
and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) |
314 |
and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) |
|
315 |
ifTrue: [ ^ true ]. |
|
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
316 |
(aJavaMethodOrField isPrivate |
846 | 317 |
and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) |
821
560f60ad3a2a
fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents:
819
diff
changeset
|
318 |
ifTrue: [ ^ true ]. |
761 | 319 |
^ false. |
320 |
||
321 |
"Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
846 | 322 |
"Modified: / 04-06-2011 / 20:49:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 323 |
! ! |
324 |
||
325 |
!JavaResolver methodsFor:'exceptions'! |
|
326 |
||
327 |
throwAbstractMethodError |
|
328 |
exceptionThrower throwAbstractMethodError. |
|
329 |
||
330 |
"Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
331 |
"Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
332 |
! |
|
333 |
||
334 |
throwIllegalAccessError |
|
335 |
exceptionThrower throwIllegalAccessError. |
|
336 |
||
337 |
"Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
338 |
"Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
339 |
! |
|
340 |
||
341 |
throwIncompatibleClassChangeError |
|
342 |
exceptionThrower throwIncompatibleClassChangeError. |
|
343 |
||
344 |
"Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
345 |
"Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
346 |
! |
|
347 |
||
348 |
throwNoSuchFieldException |
|
349 |
exceptionThrower throwNoSuchFieldException. |
|
350 |
||
351 |
"Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
352 |
"Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
353 |
! |
|
354 |
||
355 |
throwNoSuchMethodError |
|
356 |
exceptionThrower throwNoSuchMethodError. |
|
357 |
||
358 |
"Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
359 |
"Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
360 |
! ! |
|
361 |
||
362 |
!JavaResolver methodsFor:'field resolving'! |
|
363 |
||
364 |
resolveFieldIndentifiedByRef: aJavaFieldRef |
|
365 |
| result class | |
|
366 |
||
367 |
self validateFieldRef: aJavaFieldRef. |
|
368 |
result := self lookupFieldIfAlreadyResolved: aJavaFieldRef. |
|
369 |
result ifNotNil: [ ^ result ]. |
|
370 |
class := aJavaFieldRef classRef resolve. |
|
371 |
class ifNil: [ self halt: 'should not happen - tell mh' ]. |
|
372 |
result := class lookupFieldByNameAndType: aJavaFieldRef nameAndType. |
|
373 |
result ifNil: [ self throwNoSuchFieldException ]. |
|
374 |
(self |
|
375 |
checkPermissionsForField: result |
|
376 |
from: aJavaFieldRef classRef owner |
|
377 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
378 |
^ result. |
|
379 |
||
380 |
" |
|
381 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
382 |
or interface C, the symbolic reference to C given by the field reference |
|
383 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
384 |
thrown as a result of failure of resolution of a class or interface reference |
|
385 |
can be thrown as a result of failure of field resolution. If the reference |
|
386 |
to C can be successfully resolved, an exception relating to the failure of |
|
387 |
resolution of the field reference itself can be thrown. |
|
388 |
When resolving a field reference, field resolution first attempts to look |
|
389 |
up the referenced field in C and its superclasses: |
|
390 |
||
391 |
If C declares a field with the name and descriptor specified by the field |
|
392 |
reference, field lookup succeeds. The declared field is the result of the |
|
393 |
field lookup. |
|
394 |
||
395 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
396 |
of the specified class or interface C. |
|
397 |
||
398 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
399 |
||
400 |
Otherwise, field lookup fails. |
|
401 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
402 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
403 |
to D, field resolution throws an IllegalAccessError. |
|
404 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
405 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
406 |
the name of the type of the referenced field. The Java virtual machine must |
|
407 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
408 |
||
409 |
"Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
410 |
"Modified: / 13-04-2011 / 11:57:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
411 |
! |
|
412 |
||
413 |
resolveStaticFieldIndentifiedByRef: aJavaFieldRef |
|
414 |
| result class | |
|
415 |
||
416 |
self validateFieldRef: aJavaFieldRef. |
|
417 |
result := self lookupFieldIfAlreadyResolved: aJavaFieldRef. |
|
418 |
result ifNotNil: [ ^ result ]. |
|
419 |
class := aJavaFieldRef classRef resolve. |
|
420 |
class ifNil: [ self halt: 'should not happen - tell mh' ]. |
|
421 |
result := class lookupStaticFieldByNameAndType: aJavaFieldRef nameAndType. |
|
422 |
result ifNil: [ self throwNoSuchFieldException ]. |
|
423 |
(self |
|
424 |
checkPermissionsForField: result |
|
425 |
from: aJavaFieldRef classRef owner |
|
426 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
427 |
^ result. |
|
428 |
||
429 |
" |
|
430 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
431 |
or interface C, the symbolic reference to C given by the field reference |
|
432 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
433 |
thrown as a result of failure of resolution of a class or interface reference |
|
434 |
can be thrown as a result of failure of field resolution. If the reference |
|
435 |
to C can be successfully resolved, an exception relating to the failure of |
|
436 |
resolution of the field reference itself can be thrown. |
|
437 |
When resolving a field reference, field resolution first attempts to look |
|
438 |
up the referenced field in C and its superclasses: |
|
439 |
||
440 |
If C declares a field with the name and descriptor specified by the field |
|
441 |
reference, field lookup succeeds. The declared field is the result of the |
|
442 |
field lookup. |
|
443 |
||
444 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
445 |
of the specified class or interface C. |
|
446 |
||
447 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
448 |
||
449 |
Otherwise, field lookup fails. |
|
450 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
451 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
452 |
to D, field resolution throws an IllegalAccessError. |
|
453 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
454 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
455 |
the name of the type of the referenced field. The Java virtual machine must |
|
456 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
457 |
||
458 |
"Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
459 |
! ! |
|
460 |
||
461 |
!JavaResolver methodsFor:'field resolving helpers'! |
|
462 |
||
463 |
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass |
|
464 |
"A class or interface C is accessible to a class or interface D if and only |
|
465 |
if either of the following conditions are true: |
|
466 |
C is public. |
|
467 |
C and D are members of the same runtime package (5.3). |
|
468 |
A field or method R is accessible to a class or interface D if and only |
|
469 |
if any of the following conditions is true: |
|
470 |
R is public. |
|
471 |
R is protected and is declared in a class C, and D is either a subclass of |
|
472 |
C or C itself. |
|
473 |
R is either protected or package private (that is, neither public nor protected |
|
474 |
nor private), and is declared by a class in the same runtime package as D. |
|
475 |
R is private and is declared in D. |
|
476 |
This discussion of access control omits a related restriction on the target of |
|
477 |
a protected field access or method invocation (the target must be of class D or |
|
478 |
a subtype of D). That requirement is checked as part of the verification process |
|
479 |
(5.4.1); it is not part of link-time access control." |
|
480 |
||
481 |
^ self |
|
482 |
checkPermissionsForMethodOrField: aJavaField from: accessingJavaClass |
|
483 |
to: resolvedJavaClass. |
|
484 |
||
485 |
"Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
486 |
"Modified: / 14-04-2011 / 14:21:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
487 |
! |
|
488 |
||
489 |
lookupFieldIfAlreadyResolved: aJavaFieldRef |
|
490 |
^ nil. |
|
491 |
||
492 |
"Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
493 |
"Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
494 |
! |
|
495 |
||
496 |
validateFieldRef: aJavaFieldRef |
|
497 |
aJavaFieldRef isJavaRef ifFalse:[self halt:'I expected Java Ref']. |
|
498 |
aJavaFieldRef isJavaFieldRef ifFalse:[self halt:'I expected Java Field Ref']. |
|
499 |
||
500 |
"Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
501 |
! ! |
|
502 |
||
503 |
!JavaResolver methodsFor:'interface method resolving'! |
|
504 |
||
505 |
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef |
|
506 |
| result class | |
|
507 |
||
508 |
self validateInterfaceMethodRef: aJavaInterfaceMethodRef. |
|
509 |
result := self |
|
510 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef. |
|
511 |
result ifNotNil: [ ^ result ]. |
|
512 |
class := aJavaInterfaceMethodRef classRef resolve. |
|
513 |
class ifNil: [ self halt: 'should not happen - tell mh' ]. |
|
816
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
514 |
class isInterface ifFalse: [ self throwIncompatibleClassChangeError ]. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
515 |
result := class |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
516 |
lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
517 |
result ifNil: [ self throwNoSuchMethodError ]. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
518 |
(self |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
519 |
checkPermissionsForMethod: result |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
520 |
from: aJavaInterfaceMethodRef classRef owner |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
521 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
522 |
^ result. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
523 |
" |
761 | 524 |
To resolve an unresolved symbolic reference from D to an interface method in an |
525 |
interface C, the symbolic reference to C given by the interface method reference is |
|
526 |
first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result |
|
527 |
of failure of resolution of an interface reference can be thrown as a result of |
|
528 |
failure of interface method resolution. If the reference to C can be successfully |
|
529 |
resolved, exceptions relating to the resolution of the interface method reference |
|
530 |
itself can be thrown. |
|
531 |
When resolving an interface method reference: |
|
816
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
532 |
|
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
533 |
If C is not an interface, interface method resolution throws an IncompatibleClassChangeError.""Otherwise, if the referenced method does not have the same name and descriptor as |
761 | 534 |
a method in C or in one of the superinterfaces of C, or in class Object, interface |
535 |
method resolution throws a NoSuchMethodError. |
|
536 |
Otherwise, let <E, L1> be the interface in which the referenced interface method is |
|
537 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
538 |
the type returned by the referenced method, and let T1, ..., Tn be the names of the |
|
539 |
argument types of the referenced method. The Java virtual machine must impose the |
|
540 |
loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)." |
|
541 |
||
816
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
542 |
"Modified: / 23-05-2011 / 17:56:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 543 |
! ! |
544 |
||
545 |
!JavaResolver methodsFor:'interface method resolving helpers'! |
|
546 |
||
547 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef |
|
548 |
^ nil. |
|
549 |
||
550 |
"Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
551 |
! |
|
552 |
||
553 |
validateInterfaceMethodRef: aJavaInterfaceMethodRef |
|
554 |
aJavaInterfaceMethodRef isJavaRef |
|
555 |
ifFalse: [ self halt: 'I expected JavaRef instance as an argument' ]. |
|
556 |
aJavaInterfaceMethodRef isJavaInterfaceMethodRef |
|
557 |
ifFalse: [ self halt: 'I expected JavaMethodRef instance as an argument' ]. |
|
558 |
||
559 |
"Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
560 |
! ! |
|
561 |
||
562 |
!JavaResolver methodsFor:'method resolving'! |
|
563 |
||
564 |
resolveMethodIndentifiedByRef: aJavaMethodRef |
|
565 |
| result class | |
|
566 |
||
567 |
self validateMethodRef: aJavaMethodRef. |
|
568 |
result := self lookupMethodIfAlreadyResolved: aJavaMethodRef. |
|
569 |
result ifNotNil: [ ^ result ]. |
|
570 |
class := aJavaMethodRef classRef resolve. |
|
850 | 571 |
class ifNil: [ self error: 'should not happen - tell mh' ]. |
572 |
"Array types responds to all method of class java.lang.Object" |
|
573 |
class isJavaArrayClass ifTrue:[ |
|
574 |
class := Java classForName:'java.lang.Object'. |
|
575 |
]. |
|
576 |
||
577 |
||
761 | 578 |
" |
579 |
To resolve an unresolved symbolic reference from D to a method in |
|
580 |
a class C, the symbolic reference to C given by the method reference |
|
581 |
is first resolved (§5.4.3.1). Therefore, any exceptions that can be |
|
582 |
thrown due to resolution of a class reference can be thrown as a result |
|
583 |
of method resolution. If the reference to C can be successfully resolved, |
|
584 |
exceptions relating to the resolution of the method reference itself |
|
585 |
can be thrown. |
|
586 |
When resolving a method reference: |
|
587 |
||
588 |
Method resolution checks whether C is a class or an interface. |
|
589 |
If C is an interface, method resolution throws an IncompatibleClassChangeError." |
|
590 |
class isInterface ifTrue: [ self throwIncompatibleClassChangeError ]. |
|
591 |
"Method resolution attempts to look up the referenced method in C and its |
|
592 |
superclasses: |
|
593 |
If C declares a method with the name and descriptor specified by the method |
|
594 |
reference, method lookup succeeds. |
|
595 |
Otherwise, if C has a superclass, step 2 of method lookup is recursively |
|
596 |
invoked on the direct superclass of C. |
|
597 |
||
598 |
Otherwise, method lookup attempts to locate the referenced method in any of |
|
599 |
the superinterfaces of the specified class C. |
|
600 |
If any superinterface of C declares a method with the name and descriptor |
|
601 |
specified by the method reference, method lookup succeeds. |
|
602 |
Otherwise, method lookup fails. |
|
603 |
If method lookup fails, method resolution throws a NoSuchMethodError. If method |
|
604 |
lookup succeeds and the method is abstract, but C is not abstract, method resolution |
|
605 |
throws an AbstractMethodError. Otherwise, if the referenced method is not accessible |
|
606 |
(§5.4.4) to D, method resolution throws an IllegalAccessError." |
|
607 |
result := class lookupMethodByNameAndType: aJavaMethodRef nameAndType. |
|
608 |
result ifNil: [ self throwNoSuchMethodError ]. |
|
609 |
(result isAbstract and: [ class isAbstract not ]) |
|
610 |
ifTrue: [ self throwAbstractMethodError ]. |
|
611 |
(self |
|
612 |
checkPermissionsForMethod: result |
|
613 |
from: aJavaMethodRef classRef owner |
|
614 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
615 |
^ result. |
|
616 |
||
617 |
"Otherwise, let <E, L1> be the class or interface in which the referenced method is |
|
618 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
619 |
the type returned by the referenced method, and let T1, ..., Tn be the names of |
|
620 |
the argument types of the referenced method. The Java virtual machine must impose |
|
621 |
the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)." |
|
622 |
||
623 |
"Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
624 |
"Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
850 | 625 |
"Modified: / 11-06-2011 / 17:45:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 626 |
! |
627 |
||
628 |
resolveStaticMethodIndentifiedByRef: aJavaMethodRef |
|
629 |
| result class | |
|
630 |
||
631 |
self validateMethodRef: aJavaMethodRef. |
|
632 |
result := self lookupMethodIfAlreadyResolved: aJavaMethodRef. |
|
633 |
result ifNotNil: [ ^ result ]. |
|
634 |
class := aJavaMethodRef classRef resolve. |
|
635 |
class ifNil: [ self halt: 'should not happen - tell mh' ]. |
|
636 |
" |
|
637 |
To resolve an unresolved symbolic reference from D to a method in |
|
638 |
a class C, the symbolic reference to C given by the method reference |
|
639 |
is first resolved (§5.4.3.1). Therefore, any exceptions that can be |
|
640 |
thrown due to resolution of a class reference can be thrown as a result |
|
641 |
of method resolution. If the reference to C can be successfully resolved, |
|
642 |
exceptions relating to the resolution of the method reference itself |
|
643 |
can be thrown. |
|
644 |
When resolving a method reference: |
|
645 |
||
646 |
Method resolution checks whether C is a class or an interface. |
|
647 |
If C is an interface, method resolution throws an IncompatibleClassChangeError." |
|
648 |
class isInterface ifTrue: [ self throwIncompatibleClassChangeError ]. |
|
649 |
"Method resolution attempts to look up the referenced method in C and its |
|
650 |
superclasses: |
|
651 |
If C declares a method with the name and descriptor specified by the method |
|
652 |
reference, method lookup succeeds. |
|
653 |
Otherwise, if C has a superclass, step 2 of method lookup is recursively |
|
654 |
invoked on the direct superclass of C. |
|
655 |
||
656 |
Otherwise, method lookup attempts to locate the referenced method in any of |
|
657 |
the superinterfaces of the specified class C. |
|
658 |
If any superinterface of C declares a method with the name and descriptor |
|
659 |
specified by the method reference, method lookup succeeds. |
|
660 |
Otherwise, method lookup fails. |
|
661 |
If method lookup fails, method resolution throws a NoSuchMethodError. If method |
|
662 |
lookup succeeds and the method is abstract, but C is not abstract, method resolution |
|
663 |
throws an AbstractMethodError. Otherwise, if the referenced method is not accessible |
|
664 |
(§5.4.4) to D, method resolution throws an IllegalAccessError." |
|
665 |
result := class lookupStaticMethodByNameAndType: aJavaMethodRef nameAndType. |
|
666 |
result ifNil: [ self throwNoSuchMethodError ]. |
|
667 |
(result isAbstract and: [ class isAbstract not ]) |
|
668 |
ifTrue: [ self throwAbstractMethodError ]. |
|
669 |
(self |
|
670 |
checkPermissionsForMethod: result |
|
671 |
from: aJavaMethodRef classRef owner |
|
672 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
673 |
^ result. |
|
674 |
||
675 |
"Otherwise, let <E, L1> be the class or interface in which the referenced method is |
|
676 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
677 |
the type returned by the referenced method, and let T1, ..., Tn be the names of |
|
678 |
the argument types of the referenced method. The Java virtual machine must impose |
|
679 |
the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)." |
|
680 |
||
681 |
"Created: / 28-04-2011 / 22:50:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
682 |
! ! |
|
683 |
||
684 |
!JavaResolver methodsFor:'method resolving helpers'! |
|
685 |
||
686 |
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass |
|
687 |
"A class or interface C is accessible to a class or interface D if |
|
688 |
and only if either of the following conditions are true: |
|
689 |
C is public. |
|
690 |
C and D are members of the same runtime package (§5.3). |
|
691 |
A field or method R is accessible to a class or interface D if and only |
|
692 |
if any of the following conditions is true: |
|
693 |
R is public. |
|
694 |
R is protected and is declared in a class C, and D is either a subclass |
|
695 |
of C or C itself. |
|
696 |
R is either protected or package private (that is, neither public nor |
|
697 |
protected nor private), and is declared by a class in the same runtime |
|
698 |
package as D. |
|
699 |
R is private and is declared in D. |
|
700 |
This discussion of access control omits a related restriction on the target |
|
701 |
of a protected field access or method invocation (the target must be of class |
|
702 |
D or a subtype of D). That requirement is checked as part of the verification |
|
703 |
process (§5.4.1); it is not part of link-time access control." |
|
819 | 704 |
|
705 |
"JV@2011-05-24: Temporary hack, since access checking |
|
706 |
is somewhat broken. Marcle should fix it :-)" |
|
707 |
OperatingSystem getLoginName = 'jv' ifTrue:[^true]. |
|
761 | 708 |
|
709 |
^ self checkPermissionsForMethodOrField: aJavaMethod from: accessingJavaClass to: resolvedJavaClass. |
|
710 |
||
711 |
"Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
712 |
"Modified: / 14-04-2011 / 14:20:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
819 | 713 |
"Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 714 |
! |
715 |
||
716 |
lookupMethodIfAlreadyResolved: aJavaMethodRef |
|
717 |
^ nil. |
|
718 |
||
719 |
"Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
720 |
"Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
721 |
! |
|
722 |
||
723 |
validateMethodRef: aJavaMethodRef |
|
724 |
aJavaMethodRef isJavaRef ifFalse:[self halt: 'I expected JavaRef instance as an argument']. |
|
725 |
aJavaMethodRef isJavaMethodRef ifFalse: [self halt: 'I expected JavaMethodRef instance as an argument']. |
|
726 |
||
727 |
"Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
728 |
! ! |
|
729 |
||
758 | 730 |
!JavaResolver class methodsFor:'documentation'! |
731 |
||
732 |
version_SVN |
|
733 |
^ '$Id$' |
|
734 |
! ! |
|
735 |
||
736 |
JavaResolver initialize! |