src/JavaClassRef2.st
author hlopkmar
Fri, 13 May 2011 16:15:45 +0000
branchjk_new_structure
changeset 786 e3de6a198e63
parent 785 7811d2e77ca6
child 809 0fd3dbe06abb
permissions -rw-r--r--
simple methods are the worst :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     1
"{ Package: 'stx:libjava' }"
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     2
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     3
JavaRef2 subclass:#JavaClassRef2
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
     4
	instanceVariableNames:'nameIndex'
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     5
	classVariableNames:''
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     6
	poolDictionaries:''
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     7
	category:'Languages-Java-Reader-Support-new'
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     8
!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
     9
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    10
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    11
!JavaClassRef2 class methodsFor:'instance creation'!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    12
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    13
in: aJavaConstantPool withNameAt: nameIndex
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    14
   
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    15
    
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    16
    ^ self basicNew initializeIn: aJavaConstantPool withNameAt: nameIndex.
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    17
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    18
    "Created: / 10-05-2011 / 14:56:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    19
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    20
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    21
!JavaClassRef2 methodsFor:'accessing'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    22
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    23
classLoader
777
e6e61412ae43 refactoring tests.. and more needed
hlopkmar
parents: 772
diff changeset
    24
    self owner ifNil: [ ^ nil ] ifNotNil: [ ^ self owner classLoader ].
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    25
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    26
    "Created: / 11-04-2011 / 21:52:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
777
e6e61412ae43 refactoring tests.. and more needed
hlopkmar
parents: 772
diff changeset
    27
    "Modified: / 12-05-2011 / 18:32:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    28
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    29
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    30
javaClassName
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    31
    "return java class name as written in java programs e.g. java.util.String
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    32
     in case of array, return class name without square brackets"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    33
    
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    34
    | tmp |
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
    35
786
e3de6a198e63 simple methods are the worst :)
hlopkmar
parents: 785
diff changeset
    36
    tmp := self name.
e3de6a198e63 simple methods are the worst :)
hlopkmar
parents: 785
diff changeset
    37
    [tmp startsWith: '['] whileTrue: [tmp := tmp copyFrom: 2].
e3de6a198e63 simple methods are the worst :)
hlopkmar
parents: 785
diff changeset
    38
    tmp := tmp replaceAll: $/ with: $..
785
7811d2e77ca6 aaaargh forgot to delete old code after fixing it.. and wondering why it's not working :)
hlopkmar
parents: 783
diff changeset
    39
    (tmp startsWith: 'L') ifTrue: [ tmp := tmp copyFrom: 2 to: tmp size ].
7811d2e77ca6 aaaargh forgot to delete old code after fixing it.. and wondering why it's not working :)
hlopkmar
parents: 783
diff changeset
    40
    (tmp endsWith: ';') ifTrue: [ tmp := tmp copyFrom: 1 to: tmp size - 1 ].
7811d2e77ca6 aaaargh forgot to delete old code after fixing it.. and wondering why it's not working :)
hlopkmar
parents: 783
diff changeset
    41
    ^ tmp.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    42
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    43
    "Created: / 08-04-2011 / 18:30:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
786
e3de6a198e63 simple methods are the worst :)
hlopkmar
parents: 785
diff changeset
    44
    "Modified: / 13-05-2011 / 18:14:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    45
!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    46
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    47
name
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    48
    ^constantPool at: nameIndex.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    49
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    50
    "Created: / 08-04-2011 / 13:48:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    51
    "Modified: / 13-05-2011 / 09:59:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    52
! !
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    53
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    54
!JavaClassRef2 methodsFor:'array support'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    55
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    56
arrayDimensions
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    57
    ^ self name occurrencesOf: $[.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    58
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    59
    "Created: / 08-04-2011 / 18:42:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    60
    "Modified: / 13-05-2011 / 10:00:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    61
!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    62
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    63
isJavaArrayClassRef
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    64
    ^ self name startsWith: '['.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    65
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    66
    "Created: / 08-04-2011 / 18:40:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    67
    "Modified: / 13-05-2011 / 10:00:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    68
! !
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    69
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    70
!JavaClassRef2 methodsFor:'comparing'!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    71
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    72
= anotherJavaClassRef 
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    73
    "superclass JavaRef2 says that I am responsible to implement this method"
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    74
    
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    75
    anotherJavaClassRef isJavaClassRef ifFalse: [ ^ false ].
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    76
    ^ self name = anotherJavaClassRef name.
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    77
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
    78
    "Modified: / 08-04-2011 / 13:48:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    79
!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    80
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    81
hash
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    82
    ^ self name hash.
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    83
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
    84
    "Modified: / 13-05-2011 / 10:00:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    85
! !
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    86
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    87
!JavaClassRef2 methodsFor:'initialization'!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    88
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    89
initializeIn: aJavaConstantPool withNameAt: nameCPIndex
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    90
    nameIndex := nameCPIndex.
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    91
    constantPool := aJavaConstantPool.
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    92
    super initialize.
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
    93
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    94
    "Modified: / 10-05-2011 / 14:57:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    95
! !
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    96
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    97
!JavaClassRef2 methodsFor:'printing'!
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    98
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
    99
fullName
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   100
    ^ self name.
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   101
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   102
    "Created: / 10-05-2011 / 14:19:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   103
!
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   104
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   105
printString
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   106
    ^ 'JavaClassRef for: ' , self name printString.
771
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   107
fb8026dda011 Merged with /trunk
vranyj1
parents: 761
diff changeset
   108
    "Created: / 10-05-2011 / 14:16:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   109
    "Modified: / 13-05-2011 / 10:00:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   110
! !
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   111
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   112
!JavaClassRef2 methodsFor:'private - resolving'!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   113
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   114
findResolvedStaticValue
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   115
    "Resolving static inner classes is not different from resolving any other class, it's only done in different circumstances"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   116
    
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   117
    ^ self findResolvedValue.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   118
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   119
    "Created: / 28-04-2011 / 21:57:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   120
!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   121
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   122
findResolvedValue
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   123
    "Resolve reference and set valueCache."
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   124
    
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   125
    valueCache := JavaResolver uniqueInstance 
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   126
                resolveClassIndentifiedByRef: self.
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   127
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   128
    "Modified: / 08-04-2011 / 17:39:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   129
! !
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   130
761
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   131
!JavaClassRef2 methodsFor:'queries'!
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   132
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   133
isJavaClassRef
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   134
^true.
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   135
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   136
    "Created: / 11-04-2011 / 19:10:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   137
! !
43e017ec7958 Merged with /branches/jk
vranyj1
parents: 758
diff changeset
   138
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   139
!JavaClassRef2 methodsFor:'resolving'!
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   140
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   141
invalidateForClass: internalJavaClassName 
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   142
    "Invalidate (means call invalidate) reference if it has something to do with given class (e.g Class named internalJavaClassName was unloaded).
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   143
     Return true, if reference was invalidated."    
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   144
    self name = internalJavaClassName 
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   145
        ifTrue: 
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   146
            [ self invalidate.
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   147
            ^ true ].
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   148
    ^ false.
758
be8e84381ce0 Merged with /branches/jk
vranyj1
parents: 752
diff changeset
   149
778
caa3a009f617 refactoring tests and fixing related bugs, added functionality to constantPool
hlopkmar
parents: 777
diff changeset
   150
    "Modified: / 13-05-2011 / 09:59:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
752
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   151
! !
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   152
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   153
!JavaClassRef2 class methodsFor:'documentation'!
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   154
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   155
version_SVN
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   156
    ^ '$Id$'
ff7bc6428c9c branch jk_new_structure resurrected
vranyj1
parents:
diff changeset
   157
! !