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