JavaResolver.st
author Claus Gittinger <cg@exept.de>
Thu, 22 Dec 2005 18:00:03 +0100
changeset 2125 cfa7b540ebf1
parent 750 d594c0664435
child 2152 1cbdfbcc685c
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     1
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     3
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     4
                            SWING Research Group, Czech Technical University in Prague
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     5
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     6
 Parts of the code written by Claus Gittinger are under following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     7
 license:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     8
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
     9
 This software is furnished under a license and may be used
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    14
 hereby transferred.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    15
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    16
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    17
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    18
 Permission is hereby granted, free of charge, to any person
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    19
 obtaining a copy of this software and associated documentation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    20
 files (the 'Software'), to deal in the Software without
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    21
 restriction, including without limitation the rights to use,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    22
 copy, modify, merge, publish, distribute, sublicense, and/or sell
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    23
 copies of the Software, and to permit persons to whom the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    24
 Software is furnished to do so, subject to the following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    25
 conditions:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    26
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    27
 The above copyright notice and this permission notice shall be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    28
 included in all copies or substantial portions of the Software.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    29
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    30
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    31
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    32
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    33
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    34
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    35
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    36
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    37
 OTHER DEALINGS IN THE SOFTWARE.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    38
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    39
 [1] Code written at SWING Research Group contain a signature
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    40
     of one of the above copright owners.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    41
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    42
"{ Package: 'stx:libjava' }"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    43
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    44
Object subclass:#JavaResolver
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    45
	instanceVariableNames:'exceptionThrower'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    46
	classVariableNames:'uniqueInstance'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    47
	poolDictionaries:''
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    48
	category:'Languages-Java-Reader-Support-new'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    49
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    50
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    51
!JavaResolver class methodsFor:'documentation'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    52
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    53
copyright
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    54
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    55
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    56
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    57
                            SWING Research Group, Czech Technical University in Prague
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    58
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    59
 Parts of the code written by Claus Gittinger are under following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    60
 license:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    61
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    62
 This software is furnished under a license and may be used
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    63
 only in accordance with the terms of that license and with the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    64
 inclusion of the above copyright notice.   This software may not
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    65
 be provided or otherwise made available to, or used by, any
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    66
 other person.  No title to or ownership of the software is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    67
 hereby transferred.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    68
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    69
 Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    70
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    71
 Permission is hereby granted, free of charge, to any person
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    72
 obtaining a copy of this software and associated documentation
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    73
 files (the 'Software'), to deal in the Software without
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    74
 restriction, including without limitation the rights to use,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    75
 copy, modify, merge, publish, distribute, sublicense, and/or sell
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    76
 copies of the Software, and to permit persons to whom the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    77
 Software is furnished to do so, subject to the following
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    78
 conditions:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    79
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    80
 The above copyright notice and this permission notice shall be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    81
 included in all copies or substantial portions of the Software.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    82
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    83
 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    84
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    85
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    86
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    87
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    88
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    89
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    90
 OTHER DEALINGS IN THE SOFTWARE.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    91
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    92
 [1] Code written at SWING Research Group contain a signature
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    93
     of one of the above copright owners.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    94
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    95
"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    96
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    97
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    98
!JavaResolver class methodsFor:'initialization'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
    99
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   100
initialize
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   101
    uniqueInstance := JavaResolver new.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   102
    uniqueInstance exceptionThrower: JavaVM.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   103
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   104
    "/has methods at: and at: put: 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   105
    "/uniqueInstance resolvedClasses: Java.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   106
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   107
    "Modified: / 10-04-2011 / 10:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   108
    "Modified: / 13-04-2011 / 14:07:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   109
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   110
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   111
!JavaResolver class methodsFor:'instance creation'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   112
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   113
uniqueInstance
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   114
    ^uniqueInstance.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   115
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   116
    "Created: / 08-04-2011 / 17:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   117
    "Modified: / 11-04-2011 / 19:06:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   118
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   119
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   120
!JavaResolver methodsFor:'accessing'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   121
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   122
exceptionThrower
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   123
    ^ exceptionThrower
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   124
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   125
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   126
exceptionThrower:something
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   127
    exceptionThrower := something.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   128
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   129
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   130
!JavaResolver methodsFor:'class resolving'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   131
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   132
checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   133
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   134
    ^ (JavaDescriptor readFromString: aJavaClassRef name) javaClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   135
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   136
    "Created: / 23-05-2011 / 21:12:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   137
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   138
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   139
resolveClassIndentifiedByRef: aJavaClassRef init: doInit 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   140
    | classLoader  result |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   141
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   142
    self validateClassRef: aJavaClassRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   143
    result := self lookupClassIfAlreadyResolved: aJavaClassRef javaClassName.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   144
"/    result notNil ifTrue:[ 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   145
"/        "/wrap result with array(s) if needed and return it
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   146
"/        "/FIXME: Marcel, can you have a look? Is that correct?
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   147
"/        ^self checkIfArrayRef: aJavaClassRef andWrap: result 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   148
"/    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   149
     "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   150
     To resolve an unresolved symbolic reference from D to a class or interface C denoted by N,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   151
     the following steps are performed:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   152
     The defining class loader of D is used to create a class or interface denoted by N.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   153
     This class or interface is C. Any exception that can be thrown as a result of failure
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   154
     of class or interface creation can thus be thrown as a result of failure of class and
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   155
     interface resolution. The details of the process are given in Section 5.3.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   156
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   157
    result isNil ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   158
        classLoader := aJavaClassRef classLoader.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   159
        classLoader isNil ifTrue: [ 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   160
            result := self loadUnresolvedClass: aJavaClassRef
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   161
        ] ifFalse: [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   162
            result := self loadUnresolvedClass: aJavaClassRef
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   163
                           withJavaClassLoader: classLoader. 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   164
        ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   165
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   166
    result ifNil: [ self breakPoint: #mh ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   167
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   168
    result isJavaPrimitiveType ifTrue: [ 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   169
        ^ self checkIfPrimitiveArrayRef: aJavaClassRef andWrap: result 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   170
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   171
    doInit ifTrue:[result classInit].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   172
     "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   173
     If C is an array class and its element type is a reference type, then the symbolic reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   174
     to the class or interface representing the element type is resolved by invoking the algorithm
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   175
     in Section 5.4.3.1 recursively."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   176
    result := self checkIfArrayRef: aJavaClassRef andWrap: result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   177
     "Finally, access permissions to C are checked:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   178
     If C is not accessible (5.4.4) to D, class or interface resolution throws an IllegalAccessError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   179
     This condition can occur, for example, if C is a class that was originally declared to be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   180
     public but was changed to be non-public after D was compiled.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   181
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   182
     If steps 1 and 2 succeed but step 3 fails, C is still valid and usable. Nevertheless, resolution
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   183
     fails, and D is prohibited from accessing C."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   184
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   185
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   186
     "JV@2011-08-10: HACK FOR SAXON DEMO!!!!!!"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   187
    "(self checkPermissionsFrom: aJavaClassRef owner to: result)"true
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   188
        ifTrue: [ ^ result ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   189
        ifFalse: [ self throwIllegalAccessError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   190
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   191
    "Created: / 11-04-2011 / 19:07:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   192
    "Modified: / 23-05-2011 / 21:11:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   193
    "Created: / 12-08-2011 / 22:19:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   194
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   195
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   196
!JavaResolver methodsFor:'class resolving helpers'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   197
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   198
checkIfArrayRef: aJavaClassRef andWrap: result 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   199
 "/wrap result with array(s) if needed and return it
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   200
    ^ aJavaClassRef isJavaArrayClassRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   201
        ifFalse: [ result ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   202
        ifTrue: [ self wrapJavaClass: result withArrayAsSpecifiedIn: aJavaClassRef ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   203
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   204
    "Modified: / 11-04-2011 / 19:31:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   205
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   206
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   207
checkPermissionsFrom: refOwner to: resolvedClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   208
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   209
     A class or interface C is accessible to a class or interface D if and only if either of the following conditions are true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   210
            C is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   211
            C and D are members of the same runtime package (§5.3).
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   212
     Finally, access permissions to C are checked:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   213
     If C is not accessible (§5.4.4) to D, class or interface resolution throws an IllegalAccessError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   214
     This condition can occur, for example, if C is a class that was originally declared to be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   215
     public but was changed to be non-public after D was compiled.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   216
     At run time, a class or interface is determined not by its name alone,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   217
     but by a pair: its fully qualified name and its defining class loader.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   218
     Each such class or interface belongs to a single runtime package. The runtime
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   219
     package of a class or interface is determined by the package name and
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   220
     defining class loader of the class or interface."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   221
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   222
    resolvedClass isPublic ifTrue: [ ^ true ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   223
    resolvedClass classLoader = refOwner classLoader ifFalse: [ ^ false ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   224
    ^ refOwner javaPackage = resolvedClass javaPackage.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   225
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   226
    "Created: / 11-04-2011 / 19:35:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   227
    "Modified: / 13-04-2011 / 23:13:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   228
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   229
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   230
loadUnresolvedClass: aJavaClassRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   231
    | nm |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   232
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   233
    nm := aJavaClassRef javaClassName.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   234
    nm size == 1 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   235
        and: [ JavaDescriptor baseTypes at: nm first ifPresent: [:cls | ^ cls ] ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   236
    ^ Java classForName: aJavaClassRef javaClassName.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   237
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   238
    "Created: / 11-04-2011 / 19:27:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   239
    "Modified: / 22-05-2011 / 17:58:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   240
    "Modified: / 23-05-2011 / 21:06:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   241
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   242
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   243
loadUnresolvedClass: aJavaClassRef withJavaClassLoader: classLoader 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   244
    | jClass clc |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   245
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   246
    "JV@2011-08-12: HACK HACK HACK!!!!!!"        
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   247
    (clc := Java at:'java.lang.ClassLoader') notNil ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   248
        (classLoader == (clc instVarNamed: #scl)) ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   249
            ^self loadUnresolvedClass: aJavaClassRef                        
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   250
        ]
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   251
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   252
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   253
    jClass := classLoader 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   254
                perform: #'loadClass(Ljava/lang/String;)Ljava/lang/Class;'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   255
                with: (Java as_String: (aJavaClassRef name)).
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   256
    ^JavaVM reflection classForJavaClassObject: jClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   257
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   258
    "Modified: / 18-05-2011 / 14:52:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   259
    "Modified: / 12-08-2011 / 09:14:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   260
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   261
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   262
lookupClassIfAlreadyResolved: javaClassName 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   263
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   264
    ^Java at: javaClassName
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   265
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   266
    "Modified: / 13-04-2011 / 14:05:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   267
    "Modified: / 06-08-2011 / 16:44:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   268
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   269
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   270
validateClassRef: aJavaClassRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   271
    self assert: aJavaClassRef isJavaRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   272
    self assert: aJavaClassRef isJavaClassRef .
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   273
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   274
    "Modified: / 23-05-2011 / 21:04:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   275
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   276
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   277
wrapJavaClass:aJavaClass withArrayAsSpecifiedIn:aJavaClassRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   278
    "wraps aJavaClass with as many array dimensions as needed (zero means no array)"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   279
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   280
    |arrayClass|
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   281
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   282
    aJavaClassRef isJavaArrayClassRef ifFalse:[ ^ aJavaClass ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   283
    aJavaClassRef arrayDimensions timesRepeat:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   284
            [ arrayClass := aJavaClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   285
            arrayClass := arrayClass javaArrayClass. ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   286
    ^ arrayClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   287
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   288
    "Created: / 08-04-2011 / 18:40:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   289
    "Modified: / 22-05-2011 / 17:48:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   290
    "Modified: / 23-05-2011 / 21:06:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   291
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   292
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   293
!JavaResolver methodsFor:'common helpers'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   294
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   295
checkPermissionsForMethodOrField: aJavaMethodOrField from: accessingJavaClass to: resolvedJavaClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   296
    "A class or interface C is accessible to a class or interface D if 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   297
     and only if either of the following conditions are true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   298
     C is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   299
     C and D are members of the same runtime package (§5.3).
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   300
     A field or method R is accessible to a class or interface D if and only
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   301
     if any of the following conditions is true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   302
     R is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   303
     R is protected and is declared in a class C, and D is either a subclass
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   304
     of C or C itself.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   305
     R is either protected or package private (that is, neither public nor
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   306
     protected nor private), and is declared by a class in the same runtime
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   307
     package as D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   308
     R is private and is declared in D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   309
     This discussion of access control omits a related restriction on the target
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   310
     of a protected field access or method invocation (the target must be of class
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   311
     D or a subtype of D). That requirement is checked as part of the verification
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   312
     process (§5.4.1); it is not part of link-time access control."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   313
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   314
    (self checkPermissionsFrom: accessingJavaClass to: resolvedJavaClass) ifFalse: [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   315
        ^ false
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   316
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   317
    aJavaMethodOrField isPublic ifTrue: [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   318
        ^ true
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   319
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   320
    ((aJavaMethodOrField isProtected 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   321
        and: [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   322
            resolvedJavaClass javaComponentClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   323
                equalsOrIsSubclassOf: aJavaMethodOrField javaClass
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   324
        ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   325
            and: [
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   326
                accessingJavaClass javaComponentClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   327
                    equalsOrIsSubclassOf: aJavaMethodOrField javaClass
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   328
            ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   329
            ifTrue: [ ^ true ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   330
    ((aJavaMethodOrField isPrivate not 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   331
        and: [ resolvedJavaClass javaPackage = accessingJavaClass javaPackage ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   332
            and: [ resolvedJavaClass classLoader = accessingJavaClass classLoader ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   333
            ifTrue: [ ^ true ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   334
    (aJavaMethodOrField isPrivate 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   335
        and: [ aJavaMethodOrField javaClass name = accessingJavaClass name ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   336
            ifTrue: [ ^ true ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   337
    ^ false.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   338
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   339
    "Created: / 14-04-2011 / 14:19:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   340
    "Modified: / 04-06-2011 / 20:49:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   341
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   342
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   343
!JavaResolver methodsFor:'exceptions'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   344
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   345
throwAbstractMethodError
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   346
    exceptionThrower throwAbstractMethodError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   347
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   348
    "Created: / 11-04-2011 / 20:19:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   349
    "Modified: / 13-04-2011 / 14:07:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   350
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   351
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   352
throwIllegalAccessError
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   353
    exceptionThrower throwIllegalAccessError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   354
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   355
    "Created: / 11-04-2011 / 19:39:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   356
    "Modified: / 13-04-2011 / 23:06:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   357
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   358
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   359
throwIncompatibleClassChangeError
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   360
    exceptionThrower throwIncompatibleClassChangeError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   361
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   362
    "Created: / 11-04-2011 / 20:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   363
    "Modified: / 13-04-2011 / 14:07:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   364
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   365
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   366
throwNoSuchFieldException
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   367
    exceptionThrower throwNoSuchFieldException.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   368
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   369
    "Created: / 11-04-2011 / 21:35:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   370
    "Modified: / 13-04-2011 / 14:07:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   371
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   372
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   373
throwNoSuchMethodError
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   374
    exceptionThrower throwNoSuchMethodError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   375
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   376
    "Created: / 11-04-2011 / 20:19:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   377
    "Modified: / 13-04-2011 / 14:08:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   378
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   379
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   380
!JavaResolver methodsFor:'field resolving'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   381
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   382
resolveFieldIndentifiedByRef: aJavaFieldRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   383
    | result  class |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   384
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   385
    self validateFieldRef: aJavaFieldRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   386
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   387
    result ifNotNil: [ ^ result ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   388
    class := aJavaFieldRef classRef resolve.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   389
    class ifNil: [ self halt: 'should not happen - tell mh' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   390
    result := class lookupFieldByNameAndType: aJavaFieldRef nameAndType.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   391
    result ifNil: [ self throwNoSuchFieldException ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   392
    (self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   393
        checkPermissionsForField: result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   394
        from: aJavaFieldRef classRef owner
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   395
        to: class) ifFalse: [ self throwIllegalAccessError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   396
    ^ result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   397
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   398
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   399
     To resolve an unresolved symbolic reference from D to a field in a class
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   400
     or interface C, the symbolic reference to C given by the field reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   401
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   402
     thrown as a result of failure of resolution of a class or interface reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   403
     can be thrown as a result of failure of field resolution. If the reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   404
     to C can be successfully resolved, an exception relating to the failure of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   405
     resolution of the field reference itself can be thrown.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   406
     When resolving a field reference, field resolution first attempts to look
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   407
     up the referenced field in C and its superclasses:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   408
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   409
     If C declares a field with the name and descriptor specified by the field
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   410
     reference, field lookup succeeds. The declared field is the result of the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   411
     field lookup.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   412
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   413
     Otherwise, field lookup is applied recursively to the direct superinterfaces
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   414
     of the specified class or interface C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   415
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   416
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   417
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   418
     Otherwise, field lookup fails.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   419
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   420
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   421
     to D, field resolution throws an IllegalAccessError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   422
     Otherwise, let <E, L1> be the class or interface in which the referenced
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   423
     field is actually declared and let L2 be the defining loader of D. Let T be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   424
     the name of the type of the referenced field. The Java virtual machine must
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   425
     impose the loading constraint that TL1=TL2(§5.3.4)."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   426
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   427
    "Created: / 11-04-2011 / 21:15:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   428
    "Modified: / 13-04-2011 / 11:57:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   429
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   430
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   431
resolveStaticFieldIndentifiedByRef: aJavaFieldRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   432
    | result  class |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   433
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   434
    self validateFieldRef: aJavaFieldRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   435
    result := self lookupFieldIfAlreadyResolved: aJavaFieldRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   436
    result ifNotNil: [ ^ result ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   437
    class := aJavaFieldRef classRef resolve.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   438
    class ifNil: [ self halt: 'should not happen - tell mh' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   439
    result := class lookupStaticFieldByNameAndType: aJavaFieldRef nameAndType.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   440
    result ifNil: [ self throwNoSuchFieldException ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   441
    (self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   442
        checkPermissionsForField: result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   443
        from: aJavaFieldRef classRef owner
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   444
        to: class) ifFalse: [ self throwIllegalAccessError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   445
    ^ result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   446
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   447
    "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   448
     To resolve an unresolved symbolic reference from D to a field in a class
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   449
     or interface C, the symbolic reference to C given by the field reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   450
     must first be resolved (§5.4.3.1). Therefore, any exception that can be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   451
     thrown as a result of failure of resolution of a class or interface reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   452
     can be thrown as a result of failure of field resolution. If the reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   453
     to C can be successfully resolved, an exception relating to the failure of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   454
     resolution of the field reference itself can be thrown.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   455
     When resolving a field reference, field resolution first attempts to look
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   456
     up the referenced field in C and its superclasses:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   457
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   458
     If C declares a field with the name and descriptor specified by the field
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   459
     reference, field lookup succeeds. The declared field is the result of the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   460
     field lookup.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   461
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   462
     Otherwise, field lookup is applied recursively to the direct superinterfaces
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   463
     of the specified class or interface C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   464
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   465
     Otherwise, if C has a superclass S, field lookup is applied recursively to S.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   466
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   467
     Otherwise, field lookup fails.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   468
     If field lookup fails, field resolution throws a NoSuchFieldError. Otherwise,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   469
     if field lookup succeeds but the referenced field is not accessible (§5.4.4)
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   470
     to D, field resolution throws an IllegalAccessError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   471
     Otherwise, let <E, L1> be the class or interface in which the referenced
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   472
     field is actually declared and let L2 be the defining loader of D. Let T be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   473
     the name of the type of the referenced field. The Java virtual machine must
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   474
     impose the loading constraint that TL1=TL2(§5.3.4)."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   475
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   476
    "Created: / 28-04-2011 / 22:31:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   477
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   478
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   479
!JavaResolver methodsFor:'field resolving helpers'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   480
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   481
checkPermissionsForField: aJavaField from: accessingJavaClass to: resolvedJavaClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   482
    "A class or interface C is accessible to a class or interface D if and only 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   483
     if either of the following conditions are true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   484
     C is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   485
     C and D are members of the same runtime package (5.3).
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   486
     A field or method R is accessible to a class or interface D if and only
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   487
     if any of the following conditions is true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   488
     R is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   489
     R is protected and is declared in a class C, and D is either a subclass of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   490
     C or C itself.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   491
     R is either protected or package private (that is, neither public nor protected
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   492
     nor private), and is declared by a class in the same runtime package as D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   493
     R is private and is declared in D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   494
     This discussion of access control omits a related restriction on the target of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   495
     a protected field access or method invocation (the target must be of class D or
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   496
     a subtype of D). That requirement is checked as part of the verification process
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   497
     (5.4.1); it is not part of link-time access control."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   498
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   499
    ^ self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   500
        checkPermissionsForMethodOrField: aJavaField from: accessingJavaClass
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   501
        to: resolvedJavaClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   502
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   503
    "Created: / 11-04-2011 / 21:46:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   504
    "Modified: / 14-04-2011 / 14:21:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   505
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   506
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   507
lookupFieldIfAlreadyResolved: aJavaFieldRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   508
    ^ nil.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   509
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   510
    "Created: / 11-04-2011 / 21:16:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   511
    "Modified: / 13-04-2011 / 11:57:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   512
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   513
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   514
validateFieldRef: aJavaFieldRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   515
    aJavaFieldRef isJavaRef ifFalse:[self halt:'I expected Java Ref'].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   516
    aJavaFieldRef isJavaFieldRef ifFalse:[self halt:'I expected Java Field Ref'].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   517
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   518
    "Created: / 11-04-2011 / 21:16:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   519
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   520
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   521
!JavaResolver methodsFor:'interface method resolving'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   522
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   523
resolveInterfaceMethodIdentifiedByRef: aJavaInterfaceMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   524
    | result  class |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   525
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   526
    self validateInterfaceMethodRef: aJavaInterfaceMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   527
    result := self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   528
                lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   529
    result ifNotNil: [ ^ result ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   530
    class := aJavaInterfaceMethodRef classRef resolve.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   531
    class ifNil: [ self halt: 'should not happen - tell mh' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   532
    class isInterface ifFalse: [ self throwIncompatibleClassChangeError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   533
    result := class 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   534
                lookupMethodByNameAndType: aJavaInterfaceMethodRef nameAndType.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   535
    result ifNil: [ self throwNoSuchMethodError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   536
    (self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   537
        checkPermissionsForMethod: result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   538
        from: aJavaInterfaceMethodRef classRef owner
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   539
        to: class) ifFalse: [ self throwIllegalAccessError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   540
^ result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   541
     "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   542
     To resolve an unresolved symbolic reference from D to an interface method in an
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   543
     interface C, the symbolic reference to C given by the interface method reference is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   544
     first resolved (§5.4.3.1). Therefore, any exceptions that can be thrown as a result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   545
     of failure of resolution of an interface reference can be thrown as a result of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   546
     failure of interface method resolution. If the reference to C can be successfully
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   547
     resolved, exceptions relating to the resolution of the interface method reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   548
     itself can be thrown.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   549
     When resolving an interface method reference:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   550
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   551
     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
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   552
     a method in C or in one of the superinterfaces of C, or in class Object, interface
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   553
     method resolution throws a NoSuchMethodError.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   554
     Otherwise, let <E, L1> be the interface in which the referenced interface method is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   555
     actually declared and let L2 be the defining loader of D. Let T0 be the name of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   556
     the type returned by the referenced method, and let T1, ..., Tn be the names of the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   557
     argument types of the referenced method. The Java virtual machine must impose the
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   558
     loading constraints TiL1 = TiL2 for i = 0 to n (§5.3.4)."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   559
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   560
    "Modified: / 23-05-2011 / 17:56:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   561
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   562
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   563
!JavaResolver methodsFor:'interface method resolving helpers'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   564
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   565
lookupInterfaceMethodIfAlreadyResolved: aJavaInterfaceMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   566
    ^  nil.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   567
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   568
    "Created: / 13-04-2011 / 11:53:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   569
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   570
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   571
validateInterfaceMethodRef: aJavaInterfaceMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   572
        aJavaInterfaceMethodRef isJavaRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   573
        ifFalse: [ self halt: 'I expected JavaRef instance as an argument' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   574
    aJavaInterfaceMethodRef isJavaInterfaceMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   575
                ifFalse: [ self halt: 'I expected JavaMethodRef instance as an argument' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   576
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   577
    "Created: / 13-04-2011 / 11:53:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   578
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   579
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   580
!JavaResolver methodsFor:'method resolving'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   581
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   582
resolveMethodIndentifiedByRef: aJavaMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   583
    | result  class |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   584
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   585
    self validateMethodRef: aJavaMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   586
    result := self lookupMethodIfAlreadyResolved: aJavaMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   587
    result ifNotNil: [ ^ result ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   588
    class := aJavaMethodRef classRef resolve.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   589
    class ifNil: [ self error: 'should not happen - tell mh' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   590
    "Array types responds to all method of class java.lang.Object"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   591
    class isJavaArrayClass ifTrue:[
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   592
        class := Java classForName:'java.lang.Object'.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   593
    ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   594
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   595
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   596
     "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   597
     To resolve an unresolved symbolic reference from D to a method in
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   598
     a class C, the symbolic reference to C given by the method reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   599
     is first resolved (§5.4.3.1). Therefore, any exceptions that can be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   600
     thrown due to resolution of a class reference can be thrown as a result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   601
     of method resolution. If the reference to C can be successfully resolved,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   602
     exceptions relating to the resolution of the method reference itself
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   603
     can be thrown.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   604
     When resolving a method reference:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   605
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   606
     Method resolution checks whether C is a class or an interface.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   607
     If C is an interface, method resolution throws an IncompatibleClassChangeError."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   608
    class isInterface ifTrue: [ self throwIncompatibleClassChangeError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   609
     "Method resolution attempts to look up the referenced method in C and its
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   610
     superclasses:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   611
     If C declares a method with the name and descriptor specified by the method
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   612
     reference, method lookup succeeds.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   613
     Otherwise, if C has a superclass, step 2 of method lookup is recursively
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   614
     invoked on the direct superclass of C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   615
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   616
     Otherwise, method lookup attempts to locate the referenced method in any of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   617
     the superinterfaces of the specified class C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   618
     If any superinterface of C declares a method with the name and descriptor
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   619
     specified by the method reference, method lookup succeeds.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   620
     Otherwise, method lookup fails.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   621
     If method lookup fails, method resolution throws a NoSuchMethodError. If method
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   622
     lookup succeeds and the method is abstract, but C is not abstract, method resolution
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   623
     throws an AbstractMethodError. Otherwise, if the referenced method is not accessible
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   624
     (§5.4.4) to D, method resolution throws an IllegalAccessError."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   625
    result := class lookupMethodByNameAndType: aJavaMethodRef nameAndType.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   626
    result ifNil: [ self throwNoSuchMethodError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   627
    (result isAbstract and:[result javaClass isInterface not and:[ class isAbstract not ]]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   628
        ifTrue: [ self throwAbstractMethodError ].
750
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   629
    true "FIXME does not work with saxon demo - q&d hack t make esug demo work" "(self 
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   630
        checkPermissionsForMethod: result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   631
        from: aJavaMethodRef classRef owner
750
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   632
        to: class)" ifFalse: [ self throwIllegalAccessError ].
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   633
    ^ result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   634
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   635
    "Otherwise, let <E, L1> be the class or interface in which the referenced method is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   636
     actually declared and let L2 be the defining loader of D. Let T0 be the name of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   637
     the type returned by the referenced method, and let T1, ..., Tn be the names of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   638
     the argument types of the referenced method. The Java virtual machine must impose
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   639
     the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   640
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   641
    "Created: / 11-04-2011 / 19:45:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   642
    "Modified: / 14-04-2011 / 00:01:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   643
    "Modified: / 10-08-2011 / 22:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
750
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   644
    "Modified: / 19-08-2011 / 14:33:56 / cg"
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   645
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   646
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   647
resolveStaticMethodIndentifiedByRef: aJavaMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   648
    | result  class |
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   649
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   650
    self validateMethodRef: aJavaMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   651
    result := self lookupMethodIfAlreadyResolved: aJavaMethodRef.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   652
    result ifNotNil: [ ^ result ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   653
    class := aJavaMethodRef classRef resolve.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   654
    class ifNil: [ self halt: 'should not happen - tell mh' ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   655
     "
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   656
     To resolve an unresolved symbolic reference from D to a method in
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   657
     a class C, the symbolic reference to C given by the method reference
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   658
     is first resolved (§5.4.3.1). Therefore, any exceptions that can be
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   659
     thrown due to resolution of a class reference can be thrown as a result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   660
     of method resolution. If the reference to C can be successfully resolved,
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   661
     exceptions relating to the resolution of the method reference itself
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   662
     can be thrown.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   663
     When resolving a method reference:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   664
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   665
     Method resolution checks whether C is a class or an interface.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   666
     If C is an interface, method resolution throws an IncompatibleClassChangeError."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   667
    class isInterface ifTrue: [ self throwIncompatibleClassChangeError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   668
     "Method resolution attempts to look up the referenced method in C and its
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   669
     superclasses:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   670
     If C declares a method with the name and descriptor specified by the method
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   671
     reference, method lookup succeeds.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   672
     Otherwise, if C has a superclass, step 2 of method lookup is recursively
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   673
     invoked on the direct superclass of C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   674
     
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   675
     Otherwise, method lookup attempts to locate the referenced method in any of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   676
     the superinterfaces of the specified class C.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   677
     If any superinterface of C declares a method with the name and descriptor
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   678
     specified by the method reference, method lookup succeeds.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   679
     Otherwise, method lookup fails.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   680
     If method lookup fails, method resolution throws a NoSuchMethodError. If method
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   681
     lookup succeeds and the method is abstract, but C is not abstract, method resolution
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   682
     throws an AbstractMethodError. Otherwise, if the referenced method is not accessible
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   683
     (§5.4.4) to D, method resolution throws an IllegalAccessError."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   684
    result := class lookupStaticMethodByNameAndType: aJavaMethodRef nameAndType.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   685
    result ifNil: [ self throwNoSuchMethodError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   686
    (result isAbstract and: [ class isAbstract not ]) 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   687
        ifTrue: [ self throwAbstractMethodError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   688
    (self 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   689
        checkPermissionsForMethod: result
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   690
        from: aJavaMethodRef classRef owner
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   691
        to: class) ifFalse: [ self throwIllegalAccessError ].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   692
    ^ result.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   693
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   694
    "Otherwise, let <E, L1> be the class or interface in which the referenced method is
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   695
     actually declared and let L2 be the defining loader of D. Let T0 be the name of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   696
     the type returned by the referenced method, and let T1, ..., Tn be the names of
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   697
     the argument types of the referenced method. The Java virtual machine must impose
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   698
     the loading constraints TiL1=TiL2 for i = 0 to n (§5.3.4)."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   699
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   700
    "Created: / 28-04-2011 / 22:50:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   701
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   702
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   703
!JavaResolver methodsFor:'method resolving helpers'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   704
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   705
checkPermissionsForMethod: aJavaMethod from: accessingJavaClass to: resolvedJavaClass 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   706
    "A class or interface C is accessible to a class or interface D if 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   707
     and only if either of the following conditions are true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   708
     C is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   709
     C and D are members of the same runtime package (§5.3).
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   710
     A field or method R is accessible to a class or interface D if and only
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   711
     if any of the following conditions is true:
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   712
     R is public.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   713
     R is protected and is declared in a class C, and D is either a subclass
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   714
     of C or C itself.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   715
     R is either protected or package private (that is, neither public nor
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   716
     protected nor private), and is declared by a class in the same runtime
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   717
     package as D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   718
     R is private and is declared in D.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   719
     This discussion of access control omits a related restriction on the target
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   720
     of a protected field access or method invocation (the target must be of class
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   721
     D or a subtype of D). That requirement is checked as part of the verification
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   722
     process (§5.4.1); it is not part of link-time access control."
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   723
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   724
    "JV@2011-05-24: Temporary hack, since access checking
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   725
     is somewhat broken. Marcle should fix it :-)"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   726
    OperatingSystem getLoginName = 'jv' ifTrue:[^true].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   727
    
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   728
  ^ self checkPermissionsForMethodOrField: aJavaMethod from: accessingJavaClass to: resolvedJavaClass.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   729
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   730
    "Created: / 11-04-2011 / 20:20:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   731
    "Modified: / 14-04-2011 / 14:20:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   732
    "Modified: / 24-05-2011 / 14:06:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   733
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   734
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   735
lookupMethodIfAlreadyResolved: aJavaMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   736
    ^ nil.
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   737
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   738
    "Created: / 11-04-2011 / 19:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   739
    "Modified: / 13-04-2011 / 11:57:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   740
!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   741
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   742
validateMethodRef: aJavaMethodRef 
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   743
    aJavaMethodRef isJavaRef ifFalse:[self halt: 'I expected JavaRef instance as an argument'].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   744
    aJavaMethodRef isJavaMethodRef ifFalse: [self halt: 'I expected JavaMethodRef instance as an argument'].
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   745
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   746
    "Created: / 11-04-2011 / 19:47:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   747
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   748
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   749
!JavaResolver class methodsFor:'documentation'!
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   750
750
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   751
version
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   752
    ^ '$Id$'
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   753
!
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   754
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   755
version_CVS
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   756
    ^ '§Header: /cvs/stx/stx/libjava/JavaResolver.st,v 1.2 2011/08/19 12:34:39 cg Exp §'
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   757
!
d594c0664435 Synchronized with CVS repository at:
vranyj1
parents: 749
diff changeset
   758
749
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   759
version_SVN
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   760
    ^ '$Id$'
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   761
! !
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   762
e898eaeff091 Synchronized with CVS repository at:
vranyj1
parents:
diff changeset
   763
JavaResolver initialize!