author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 02 Jan 2013 18:51:13 +0100 | |
branch | development |
changeset 1922 | 7fa6a6a8f1d8 |
parent 1864 | 60a8dc26c8c6 |
child 1989 | 131b7459fdab |
permissions | -rw-r--r-- |
877 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
877 | 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 |
||
1155 | 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 |
|
1152 | 19 |
as of 1.9.2010 |
877 | 20 |
" |
758 | 21 |
"{ Package: 'stx:libjava' }" |
22 |
||
23 |
Object subclass:#JavaResolver |
|
761 | 24 |
instanceVariableNames:'exceptionThrower' |
758 | 25 |
classVariableNames:'uniqueInstance' |
26 |
poolDictionaries:'' |
|
27 |
category:'Languages-Java-Reader-Support-new' |
|
28 |
! |
|
29 |
||
877 | 30 |
!JavaResolver class methodsFor:'documentation'! |
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
877 | 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 |
||
1155 | 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 |
|
1152 | 51 |
as of 1.9.2010 |
877 | 52 |
|
53 |
" |
|
54 |
! ! |
|
758 | 55 |
|
56 |
!JavaResolver class methodsFor:'initialization'! |
|
57 |
||
58 |
initialize |
|
59 |
uniqueInstance := JavaResolver new. |
|
761 | 60 |
uniqueInstance exceptionThrower: JavaVM. |
61 |
||
758 | 62 |
"/has methods at: and at: put: |
759
66d28d2fa62e
JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents:
758
diff
changeset
|
63 |
"/uniqueInstance resolvedClasses: Java. |
758 | 64 |
|
759
66d28d2fa62e
JavaResolver: fixed bug in JavaResolver class>>#initialize
vranyj1
parents:
758
diff
changeset
|
65 |
"Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 66 |
"Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 67 |
! ! |
68 |
||
69 |
!JavaResolver class methodsFor:'instance creation'! |
|
70 |
||
71 |
uniqueInstance |
|
761 | 72 |
^uniqueInstance. |
758 | 73 |
|
74 |
"Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
761 | 75 |
"Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
76 |
! ! |
|
77 |
||
78 |
!JavaResolver methodsFor:'accessing'! |
|
79 |
||
80 |
exceptionThrower |
|
81 |
^ exceptionThrower |
|
82 |
! |
|
83 |
||
84 |
exceptionThrower:something |
|
85 |
exceptionThrower := something. |
|
758 | 86 |
! ! |
87 |
||
88 |
!JavaResolver methodsFor:'class resolving'! |
|
89 |
||
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
|
90 |
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
|
91 |
|
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
|
92 |
^ (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
|
93 |
|
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
|
94 |
"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
|
95 |
! |
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
|
96 |
|
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
908
diff
changeset
|
97 |
resolveClassIndentifiedByRef: aJavaClassRef init: doInit |
1014 | 98 |
"marcel is back working harder then ever :)" |
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
99 |
|
992 | 100 |
| result | |
761 | 101 |
self validateClassRef: aJavaClassRef. |
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
102 |
JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader) |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
103 |
do: [ |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
104 |
result := self lookupClassIfAlreadyResolved: aJavaClassRef javaClassName. |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
105 |
|
1041 | 106 |
"/ result notNil ifTrue:[ |
107 |
"/ "/wrap result with array(s) if needed and return it |
|
108 |
"/ "/FIXME: Marcel, can you have a look? Is that correct? |
|
109 |
"/ ^self checkIfArrayRef: aJavaClassRef andWrap: result. |
|
110 |
"/ ]. |
|
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
111 |
]. |
758 | 112 |
" |
113 |
To resolve an unresolved symbolic reference from D to a class or interface C denoted by N, |
|
114 |
the following steps are performed: |
|
115 |
The defining class loader of D is used to create a class or interface denoted by N. |
|
116 |
This class or interface is C. Any exception that can be thrown as a result of failure |
|
117 |
of class or interface creation can thus be thrown as a result of failure of class and |
|
118 |
interface resolution. The details of the process are given in Section 5.3. |
|
119 |
" |
|
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
120 |
result isNil ifTrue: [ |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
121 |
JavaClassReader classLoaderQuerySignal answer: (aJavaClassRef classLoader) |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
122 |
do: [ |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
123 |
"#loadUnresolvedClass: wraps the class!!!!!!" |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
124 |
result := self loadUnresolvedClass: aJavaClassRef. |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
125 |
((aJavaClassRef name first == $[) and: [ result isJavaArrayClass not ]) ifTrue: [ |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
126 |
self breakPoint: #jv. |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
127 |
] |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
128 |
]. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
129 |
] ifFalse: [ result := self checkIfArrayRef: aJavaClassRef andWrap: result. ]. |
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
130 |
result isNil ifTrue: [ self breakPoint: #mh ]. |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
131 |
result isJavaPrimitiveType ifTrue: [ |
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
132 |
^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result |
883 | 133 |
]. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
134 |
(doInit and: [ result isJavaClass and: [ result isJavaArrayClass not ] ]) ifTrue: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
135 |
result classInit |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
136 |
]. |
758 | 137 |
" |
138 |
If C is an array class and its element type is a reference type, then the symbolic reference |
|
139 |
to the class or interface representing the element type is resolved by invoking the algorithm |
|
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
140 |
in Section 5.4.3.1 recursively.""Finally, access permissions to C are checked: |
761 | 141 |
If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError. |
758 | 142 |
This condition can occur, for example, if C is a class that was originally declared to be |
143 |
public but was changed to be non-public after D was compiled. |
|
144 |
||
145 |
If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
146 |
fails, and D is prohibited from accessing C." "JV@2011-08-10: HACK FOR SAXON DEMO!!!!!!" "(self checkPermissionsFrom: aJavaClassRef owner to: result)" "JV@2011-12-07: HACK FOR TOMCAT DEMO :-))" |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
147 |
(self checkPermissionsFrom: aJavaClassRef owner to: result) ifTrue: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
148 |
^ result |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
149 |
] ifFalse: [ self throwIllegalAccessError ]. |
758 | 150 |
|
761 | 151 |
"Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
912
e651488f5741
Many fixes in reflection, expecially for generic types support
vranyj1
parents:
908
diff
changeset
|
152 |
"Created: / 12-08-2011 / 22:19:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1014 | 153 |
"Modified (comment): / 03-10-2011 / 23:03:01 / m" |
1649
0af82006c0b2
- some more support for calling Smalltalk from Groovy. Crashes VM now :-)
vranyj1
parents:
1469
diff
changeset
|
154 |
"Modified: / 22-08-2012 / 13:02:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
155 |
"Modified: / 01-12-2012 / 13:44:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 156 |
! ! |
157 |
||
158 |
!JavaResolver methodsFor:'class resolving helpers'! |
|
159 |
||
1041 | 160 |
checkIfArrayRef: aJavaClassRef andWrap: nonArrayClass |
161 |
||
162 |
"/wrap result with array(s) if needed and return it |
|
163 |
| class| |
|
164 |
class := nonArrayClass. |
|
165 |
aJavaClassRef name do:[:c| |
|
166 |
c ~~ $[ ifTrue:[ ^ class ]. |
|
167 |
class := class javaArrayClass. |
|
168 |
]. |
|
169 |
^class |
|
761 | 170 |
|
171 |
"Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1041 | 172 |
"Modified: / 23-10-2011 / 23:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 173 |
! |
174 |
||
1843
eff50e345dff
enabling permission checking for everybody.. expect some code to start crashing
hlopkmar
parents:
1831
diff
changeset
|
175 |
checkPermissionsFrom: refOwner to: resolvedClass |
1830
ef4a91a5d32c
MagicAccessorImpl has his magic now (permissions not checked for subclasses)
hlopkmar
parents:
1829
diff
changeset
|
176 |
refOwner hasMagicAccessRights ifTrue: [ ^ true ]. |
1275 | 177 |
(JavaDescriptor isJavaPrimitiveArrayName: resolvedClass javaName) ifTrue: [ |
178 |
^ true |
|
179 |
]. |
|
761 | 180 |
resolvedClass isPublic ifTrue: [ ^ true ]. |
1225
30600ca8173c
ok now we enabled permissions and groovy maybe does not work :/
hlopkmar
parents:
1224
diff
changeset
|
181 |
resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false. ]. |
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
182 |
refOwner javaPackage = resolvedClass javaPackage ifTrue: [ ^ true ]. |
1224
b8a0cc35baaa
permission testing enabled again, groovy works => we are awesome
hlopkmar
parents:
1155
diff
changeset
|
183 |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
184 |
"/a little bit too verbose here just so it's clear what's in query |
1224
b8a0cc35baaa
permission testing enabled again, groovy works => we are awesome
hlopkmar
parents:
1155
diff
changeset
|
185 |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
186 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
761 | 187 |
|
188 |
"Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
189 |
"Modified (comment): / 09-10-2011 / 23:11:54 / Marcel Hlopko <hlopik@gmail.com>" |
1674 | 190 |
"Modified: / 23-08-2012 / 20:21:40 / m" |
1843
eff50e345dff
enabling permission checking for everybody.. expect some code to start crashing
hlopkmar
parents:
1831
diff
changeset
|
191 |
"Modified: / 30-11-2012 / 20:34:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 192 |
! |
193 |
||
194 |
loadUnresolvedClass: aJavaClassRef |
|
1393 | 195 |
| nm cls i | |
812
62e917825364
- JavaDescriptor, JavaResolver, JavaArray: fixes for primitive and array types
vranyj1
parents:
809
diff
changeset
|
196 |
|
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
1021
diff
changeset
|
197 |
nm := aJavaClassRef name. |
1393 | 198 |
nm size == 1 ifTrue:[ |
199 |
JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] |
|
200 |
]. |
|
201 |
"Note, that JavaVM>>classForName: itself deals with class loaders. |
|
992 | 202 |
The caller of me should set one using code like: |
1026
5badd1d31864
introduced JavaClassRegistry, taken loading responsibilities from JavaClassReader, got rid of stringConstants and started using StringRefs.. Bugs very likely :)
hlopkmar
parents:
1021
diff
changeset
|
203 |
|
1393 | 204 |
JavaClassReader classLoaderQuerySignal answer: loader do:[call me] |
992 | 205 |
" |
1393 | 206 |
cls := JavaVM classForName: nm. |
207 |
(nm startsWith:$[) ifTrue:[ |
|
208 |
i := 1. |
|
209 |
[ (nm at:i) == $[ ] whileTrue:[ |
|
210 |
cls := cls javaArrayClass. |
|
211 |
i := i + 1. |
|
212 |
]. |
|
213 |
self assert: (nm at:i) == $L. |
|
214 |
]. |
|
215 |
||
216 |
^cls. |
|
761 | 217 |
|
218 |
"Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.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
|
219 |
"Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1393 | 220 |
"Modified: / 29-02-2012 / 09:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
761 | 221 |
! |
222 |
||
223 |
lookupClassIfAlreadyResolved: javaClassName |
|
1036 | 224 |
^ JavaVM classNamed: javaClassName |
761 | 225 |
|
883 | 226 |
"Modified: / 06-08-2011 / 16:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1036 | 227 |
"Modified: / 21-10-2011 / 13:40:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 228 |
! |
229 |
||
230 |
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
|
231 |
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
|
232 |
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
|
233 |
|
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
|
234 |
"Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 235 |
! ! |
236 |
||
761 | 237 |
!JavaResolver methodsFor:'common helpers'! |
238 |
||
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
239 |
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass |
761 | 240 |
"A class or interface C is accessible to a class or interface D if |
241 |
and only if either of the following conditions are true: |
|
242 |
C is public. |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
243 |
C and D are members of the same runtime package (§5.3). |
761 | 244 |
A field or method R is accessible to a class or interface D if and only |
245 |
if any of the following conditions is true: |
|
246 |
R is public. |
|
247 |
R is protected and is declared in a class C, and D is either a subclass |
|
248 |
of C or C itself. |
|
249 |
R is either protected or package private (that is, neither public nor |
|
250 |
protected nor private), and is declared by a class in the same runtime |
|
251 |
package as D. |
|
252 |
R is private and is declared in D. |
|
253 |
This discussion of access control omits a related restriction on the target |
|
254 |
of a protected field access or method invocation (the target must be of class |
|
255 |
D or a subtype of D). That requirement is checked as part of the verification |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
256 |
process (§5.4.1); it is not part of link-time access control." |
1831
40e9cfb269d4
magic accessor enabled for fields and methods as well..
hlopkmar
parents:
1830
diff
changeset
|
257 |
|
40e9cfb269d4
magic accessor enabled for fields and methods as well..
hlopkmar
parents:
1830
diff
changeset
|
258 |
accessingJavaClass hasMagicAccessRights ifTrue: [ ^true ]. |
40e9cfb269d4
magic accessor enabled for fields and methods as well..
hlopkmar
parents:
1830
diff
changeset
|
259 |
|
846 | 260 |
(self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [ |
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
261 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ]. |
846 | 262 |
^ false |
263 |
]. |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
264 |
aJavaMethodOrField isPublic ifTrue: [ ^ true ]. |
846 | 265 |
((aJavaMethodOrField isProtected |
266 |
and: [ |
|
267 |
resolvedJavaClass javaComponentClass |
|
268 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
269 |
]) |
|
270 |
and: [ |
|
271 |
accessingJavaClass javaComponentClass |
|
272 |
equalsOrIsSubclassOf: aJavaMethodOrField javaClass |
|
273 |
]) |
|
821
560f60ad3a2a
fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents:
819
diff
changeset
|
274 |
ifTrue: [ ^ true ]. |
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
275 |
((aJavaMethodOrField isPrivate not |
761 | 276 |
and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) |
1831
40e9cfb269d4
magic accessor enabled for fields and methods as well..
hlopkmar
parents:
1830
diff
changeset
|
277 |
and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) |
761 | 278 |
ifTrue: [ ^ true ]. |
796
9b3e00dd3196
Small fix, so JavaFields have their javaClass always set.
hlopkmar
parents:
784
diff
changeset
|
279 |
(aJavaMethodOrField isPrivate |
846 | 280 |
and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) |
821
560f60ad3a2a
fixed (hopefully:) bug in permissions (new resolving)
hlopkmar
parents:
819
diff
changeset
|
281 |
ifTrue: [ ^ true ]. |
1224
b8a0cc35baaa
permission testing enabled again, groovy works => we are awesome
hlopkmar
parents:
1155
diff
changeset
|
282 |
|
b8a0cc35baaa
permission testing enabled again, groovy works => we are awesome
hlopkmar
parents:
1155
diff
changeset
|
283 |
"/a little bit too verbose here just so it's clear what's in query |
b8a0cc35baaa
permission testing enabled again, groovy works => we are awesome
hlopkmar
parents:
1155
diff
changeset
|
284 |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
285 |
JavaVM privilegedAccessQuery query ifTrue: [ ^ true ] ifFalse: [ ^ false ]. |
761 | 286 |
|
287 |
"Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1016
2b20730b8717
work on ticket #28(illegal access after evaluating expresion in workspace).
hlopkmar
parents:
1014
diff
changeset
|
288 |
"Modified (comment): / 09-10-2011 / 23:12:48 / Marcel Hlopko <hlopik@gmail.com>" |
1831
40e9cfb269d4
magic accessor enabled for fields and methods as well..
hlopkmar
parents:
1830
diff
changeset
|
289 |
"Modified: / 18-11-2012 / 16:24:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 290 |
! ! |
291 |
||
292 |
!JavaResolver methodsFor:'exceptions'! |
|
293 |
||
294 |
throwAbstractMethodError |
|
295 |
exceptionThrower throwAbstractMethodError. |
|
296 |
||
297 |
"Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
298 |
"Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
299 |
! |
|
300 |
||
301 |
throwIllegalAccessError |
|
302 |
exceptionThrower throwIllegalAccessError. |
|
303 |
||
304 |
"Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
305 |
"Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
306 |
! |
|
307 |
||
308 |
throwIncompatibleClassChangeError |
|
309 |
exceptionThrower throwIncompatibleClassChangeError. |
|
310 |
||
311 |
"Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
312 |
"Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
313 |
! |
|
314 |
||
315 |
throwNoSuchFieldException |
|
316 |
exceptionThrower throwNoSuchFieldException. |
|
317 |
||
318 |
"Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
319 |
"Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
320 |
! |
|
321 |
||
322 |
throwNoSuchMethodError |
|
323 |
exceptionThrower throwNoSuchMethodError. |
|
324 |
||
325 |
"Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
326 |
"Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
327 |
! ! |
|
328 |
||
329 |
!JavaResolver methodsFor:'field resolving'! |
|
330 |
||
331 |
resolveFieldIndentifiedByRef: aJavaFieldRef |
|
332 |
| result class | |
|
333 |
self validateFieldRef: aJavaFieldRef. |
|
334 |
result := self lookupFieldIfAlreadyResolved: aJavaFieldRef. |
|
335 |
result ifNotNil: [ ^ result ]. |
|
1392 | 336 |
class := aJavaFieldRef classRef resolve: false. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
337 |
class ifNil: [ self error: 'should not happen - tell mh' ]. |
761 | 338 |
result := class lookupFieldByNameAndType: aJavaFieldRef nameAndType. |
339 |
result ifNil: [ self throwNoSuchFieldException ]. |
|
340 |
(self |
|
341 |
checkPermissionsForField: result |
|
342 |
from: aJavaFieldRef classRef owner |
|
343 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
344 |
^ result. |
|
345 |
||
346 |
" |
|
347 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
348 |
or interface C, the symbolic reference to C given by the field reference |
|
349 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
350 |
thrown as a result of failure of resolution of a class or interface reference |
|
351 |
can be thrown as a result of failure of field resolution. If the reference |
|
352 |
to C can be successfully resolved, an exception relating to the failure of |
|
353 |
resolution of the field reference itself can be thrown. |
|
354 |
When resolving a field reference, field resolution first attempts to look |
|
355 |
up the referenced field in C and its superclasses: |
|
356 |
||
357 |
If C declares a field with the name and descriptor specified by the field |
|
358 |
reference, field lookup succeeds. The declared field is the result of the |
|
359 |
field lookup. |
|
360 |
||
361 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
362 |
of the specified class or interface C. |
|
363 |
||
364 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
365 |
||
366 |
Otherwise, field lookup fails. |
|
367 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
368 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
369 |
to D, field resolution throws an IllegalAccessError. |
|
370 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
371 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
372 |
the name of the type of the referenced field. The Java virtual machine must |
|
373 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
374 |
||
375 |
"Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
376 |
"Modified: / 01-12-2012 / 13:45:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 377 |
! |
378 |
||
379 |
resolveStaticFieldIndentifiedByRef: aJavaFieldRef |
|
380 |
| result class | |
|
381 |
self validateFieldRef: aJavaFieldRef. |
|
382 |
result := self lookupFieldIfAlreadyResolved: aJavaFieldRef. |
|
383 |
result ifNotNil: [ ^ result ]. |
|
1392 | 384 |
class := aJavaFieldRef classRef resolve: false. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
385 |
class ifNil: [ self error: 'should not happen - tell mh' ]. |
761 | 386 |
result := class lookupStaticFieldByNameAndType: aJavaFieldRef nameAndType. |
387 |
result ifNil: [ self throwNoSuchFieldException ]. |
|
388 |
(self |
|
389 |
checkPermissionsForField: result |
|
390 |
from: aJavaFieldRef classRef owner |
|
391 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
392 |
^ result. |
|
393 |
||
394 |
" |
|
395 |
To resolve an unresolved symbolic reference from D to a field in a class |
|
396 |
or interface C, the symbolic reference to C given by the field reference |
|
397 |
must first be resolved (§5.4.3.1). Therefore, any exception that can be |
|
398 |
thrown as a result of failure of resolution of a class or interface reference |
|
399 |
can be thrown as a result of failure of field resolution. If the reference |
|
400 |
to C can be successfully resolved, an exception relating to the failure of |
|
401 |
resolution of the field reference itself can be thrown. |
|
402 |
When resolving a field reference, field resolution first attempts to look |
|
403 |
up the referenced field in C and its superclasses: |
|
404 |
||
405 |
If C declares a field with the name and descriptor specified by the field |
|
406 |
reference, field lookup succeeds. The declared field is the result of the |
|
407 |
field lookup. |
|
408 |
||
409 |
Otherwise, field lookup is applied recursively to the direct superinterfaces |
|
410 |
of the specified class or interface C. |
|
411 |
||
412 |
Otherwise, if C has a superclass S, field lookup is applied recursively to S. |
|
413 |
||
414 |
Otherwise, field lookup fails. |
|
415 |
If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise, |
|
416 |
if field lookup succeeds but the referenced field is not accessible (§5.4.4) |
|
417 |
to D, field resolution throws an IllegalAccessError. |
|
418 |
Otherwise, let <E, L1> be the class or interface in which the referenced |
|
419 |
field is actually declared and let L2 be the defining loader of D. Let T be |
|
420 |
the name of the type of the referenced field. The Java virtual machine must |
|
421 |
impose the loading constraint that TL1=TL2(§5.3.4)." |
|
422 |
||
423 |
"Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
424 |
"Modified: / 01-12-2012 / 13:45:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 425 |
! ! |
426 |
||
427 |
!JavaResolver methodsFor:'field resolving helpers'! |
|
428 |
||
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
429 |
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass |
761 | 430 |
^ self |
1469 | 431 |
checkPermissionsForMethodOrField: aJavaField |
432 |
from: accessingJavaClass |
|
761 | 433 |
to: resolvedJavaClass. |
434 |
||
435 |
"Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
436 |
"Modified: / 01-12-2012 / 13:45:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 437 |
! |
438 |
||
439 |
lookupFieldIfAlreadyResolved: aJavaFieldRef |
|
440 |
^ nil. |
|
441 |
||
442 |
"Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
443 |
"Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
444 |
! |
|
445 |
||
446 |
validateFieldRef: aJavaFieldRef |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
447 |
aJavaFieldRef isJavaRef ifFalse: [ self halt: 'I expected Java Ref' ]. |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
448 |
aJavaFieldRef isJavaFieldRef ifFalse: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
449 |
self error: 'I expected Java Field Ref' |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
450 |
]. |
761 | 451 |
|
452 |
"Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
453 |
"Modified: / 01-12-2012 / 13:46:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 454 |
! ! |
455 |
||
456 |
!JavaResolver methodsFor:'interface method resolving'! |
|
457 |
||
458 |
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef |
|
459 |
| result class | |
|
460 |
self validateInterfaceMethodRef: aJavaInterfaceMethodRef. |
|
461 |
result := self |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
462 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef. |
761 | 463 |
result ifNotNil: [ ^ result ]. |
1392 | 464 |
class := aJavaInterfaceMethodRef classRef resolve: false. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
465 |
class ifNil: [ self error: '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
|
466 |
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
|
467 |
result := class |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
468 |
lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType. |
816
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
469 |
result ifNil: [ self throwNoSuchMethodError ]. |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
470 |
(self |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
471 |
checkPermissionsForMethod: result |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
472 |
from: aJavaInterfaceMethodRef classRef owner |
4e3072021201
all tests fixed.. updated interfaceMethodRef to checkPermissions (which were not checked until now ehm)
hlopkmar
parents:
814
diff
changeset
|
473 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
474 |
^ result. |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
475 |
|
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
476 |
" |
761 | 477 |
To resolve an unresolved symbolic reference from D to an interface method in an |
478 |
interface C, the symbolic reference to C given by the interface method reference is |
|
479 |
first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result |
|
480 |
of failure of resolution of an interface reference can be thrown as a result of |
|
481 |
failure of interface method resolution. If the reference to C can be successfully |
|
482 |
resolved, exceptions relating to the resolution of the interface method reference |
|
483 |
itself can be thrown. |
|
484 |
When resolving an interface method reference: |
|
485 |
||
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
486 |
If C is not an interface, interface method resolution throws an IncompatibleClassChangeError." |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
487 |
"Otherwise, if the referenced method does not have the same name and descriptor as |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
488 |
a method in C or in one of the superinterfaces of C, or in class Object, interface |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
489 |
method resolution throws a NoSuchMethodError. |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
490 |
Otherwise, let <E, L1> be the interface in which the referenced interface method is |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
491 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
492 |
the type returned by the referenced method, and let T1, ..., Tn be the names of the |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
493 |
argument types of the referenced method. The Java virtual machine must impose the |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
494 |
loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)." |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
495 |
|
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
496 |
"Modified: / 01-12-2012 / 13:46:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 497 |
! ! |
498 |
||
499 |
!JavaResolver methodsFor:'interface method resolving helpers'! |
|
500 |
||
501 |
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef |
|
502 |
^ nil. |
|
503 |
||
504 |
"Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
505 |
! |
|
506 |
||
507 |
validateInterfaceMethodRef: aJavaInterfaceMethodRef |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
508 |
aJavaInterfaceMethodRef isJavaRef ifFalse: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
509 |
self error: 'I expected JavaRef instance as an argument' |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
510 |
]. |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
511 |
aJavaInterfaceMethodRef isJavaInterfaceMethodRef ifFalse: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
512 |
self error: 'I expected JavaMethodRef instance as an argument' |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
513 |
]. |
761 | 514 |
|
515 |
"Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
516 |
"Modified: / 01-12-2012 / 13:46:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 517 |
! ! |
518 |
||
519 |
!JavaResolver methodsFor:'method resolving'! |
|
520 |
||
521 |
resolveMethodIndentifiedByRef: aJavaMethodRef |
|
522 |
| result class | |
|
523 |
self validateMethodRef: aJavaMethodRef. |
|
524 |
result := self lookupMethodIfAlreadyResolved: aJavaMethodRef. |
|
525 |
result ifNotNil: [ ^ result ]. |
|
1392 | 526 |
class := aJavaMethodRef classRef resolve: false. |
850 | 527 |
class ifNil: [ self error: 'should not happen - tell mh' ]. |
1033 | 528 |
"Array types responds to all method of class java.lang.Object" |
529 |
class isJavaArrayClass ifTrue: [ |
|
530 |
class := JavaVM classForName: 'java.lang.Object'. |
|
850 | 531 |
]. |
761 | 532 |
" |
533 |
To resolve an unresolved symbolic reference from D to a method in |
|
534 |
a class C, the symbolic reference to C given by the method reference |
|
1033 | 535 |
is first resolved (§5.4.3.1). Therefore, any exceptions that can be |
761 | 536 |
thrown due to resolution of a class reference can be thrown as a result |
537 |
of method resolution. If the reference to C can be successfully resolved, |
|
538 |
exceptions relating to the resolution of the method reference itself |
|
539 |
can be thrown. |
|
540 |
When resolving a method reference: |
|
541 |
||
542 |
Method resolution checks whether C is a class or an interface. |
|
543 |
If C is an interface, method resolution throws an IncompatibleClassChangeError." |
|
544 |
class isInterface ifTrue: [ self throwIncompatibleClassChangeError ]. |
|
545 |
"Method resolution attempts to look up the referenced method in C and its |
|
546 |
superclasses: |
|
547 |
If C declares a method with the name and descriptor specified by the method |
|
548 |
reference, method lookup succeeds. |
|
549 |
Otherwise, if C has a superclass, step 2 of method lookup is recursively |
|
550 |
invoked on the direct superclass of C. |
|
551 |
||
552 |
Otherwise, method lookup attempts to locate the referenced method in any of |
|
553 |
the superinterfaces of the specified class C. |
|
554 |
If any superinterface of C declares a method with the name and descriptor |
|
555 |
specified by the method reference, method lookup succeeds. |
|
556 |
Otherwise, method lookup fails. |
|
557 |
If method lookup fails, method resolution throws a NoSuchMethodError. If method |
|
558 |
lookup succeeds and the method is abstract, but C is not abstract, method resolution |
|
559 |
throws an AbstractMethodError. Otherwise, if the referenced method is not accessible |
|
1033 | 560 |
(§5.4.4) to D, method resolution throws an IllegalAccessError." |
761 | 561 |
result := class lookupMethodByNameAndType: aJavaMethodRef nameAndType. |
562 |
result ifNil: [ self throwNoSuchMethodError ]. |
|
1033 | 563 |
(result isAbstract |
564 |
and: [ result javaClass isInterface not and: [ class isAbstract not ] ]) |
|
565 |
ifTrue: [ self throwAbstractMethodError ]. |
|
761 | 566 |
(self |
567 |
checkPermissionsForMethod: result |
|
568 |
from: aJavaMethodRef classRef owner |
|
569 |
to: class) ifFalse: [ self throwIllegalAccessError ]. |
|
570 |
^ result. |
|
571 |
||
572 |
"Otherwise, let <E, L1> be the class or interface in which the referenced method is |
|
573 |
actually declared and let L2 be the defining loader of D. Let T0 be the name of |
|
574 |
the type returned by the referenced method, and let T1, ..., Tn be the names of |
|
575 |
the argument types of the referenced method. The Java virtual machine must impose |
|
1033 | 576 |
the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)." |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
577 |
|
761 | 578 |
"Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
579 |
"Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
905 | 580 |
"Modified: / 10-08-2011 / 22:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
581 |
"Modified (format): / 01-12-2012 / 13:46:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 582 |
! ! |
583 |
||
584 |
!JavaResolver methodsFor:'method resolving helpers'! |
|
585 |
||
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
586 |
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass |
1469 | 587 |
^ self |
1353 | 588 |
checkPermissionsForMethodOrField: aJavaMethod |
589 |
from: accessingJavaClass |
|
1469 | 590 |
to: resolvedJavaClass. |
761 | 591 |
|
592 |
"Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
819 | 593 |
"Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1353 | 594 |
"Modified: / 09-02-2012 / 23:15:48 / mh <hlopik@gmail.com>" |
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
595 |
"Modified: / 01-12-2012 / 13:46:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 596 |
! |
597 |
||
598 |
lookupMethodIfAlreadyResolved: aJavaMethodRef |
|
599 |
^ nil. |
|
600 |
||
601 |
"Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
602 |
"Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
603 |
! |
|
604 |
||
605 |
validateMethodRef: aJavaMethodRef |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
606 |
aJavaMethodRef isJavaRef ifFalse: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
607 |
self error: 'I expected JavaRef instance as an argument' |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
608 |
]. |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
609 |
aJavaMethodRef isJavaMethodRef ifFalse: [ |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
610 |
self error: 'I expected JavaMethodRef instance as an argument' |
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
611 |
]. |
761 | 612 |
|
613 |
"Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1846
7819e76e5b48
enabling java permission checking for everybody. seriously this time :)
hlopkmar
parents:
1843
diff
changeset
|
614 |
"Modified: / 01-12-2012 / 13:47:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
761 | 615 |
! ! |
616 |
||
758 | 617 |
!JavaResolver class methodsFor:'documentation'! |
618 |
||
1864 | 619 |
version_HG |
620 |
||
621 |
^ '$Changeset: <not expanded> $' |
|
622 |
! |
|
623 |
||
758 | 624 |
version_SVN |
1864 | 625 |
^ '§Id§' |
758 | 626 |
! ! |
627 |
||
628 |
JavaResolver initialize! |