1
|
1 |
"{ Package: 'stx:goodies/cypress' }"
|
|
2 |
|
|
3 |
CypressStructure subclass:#CypressPackageStructure
|
|
4 |
instanceVariableNames:'classes extensions'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Cypress-Structure'
|
|
8 |
!
|
|
9 |
|
|
10 |
CypressPackageStructure comment:'Main comment stating the purpose of this class and relevant relationship to other classes.
Possible useful expressions for doIt or printIt.
Structure:
instVar1 type -- comment about the purpose of instVar1
instVar2 type -- comment about the purpose of instVar2
Any further useful comments about the general approach of this implementation.'
|
|
11 |
!
|
|
12 |
|
|
13 |
|
|
14 |
!CypressPackageStructure class methodsFor:'instance creation'!
|
|
15 |
|
|
16 |
fromJson: aJsonString
|
|
17 |
|
|
18 |
^self fromJs: (CypressJsonParser parse: aJsonString)
|
|
19 |
!
|
|
20 |
|
|
21 |
fromPackage: aCypressPackageDefinition
|
|
22 |
|
|
23 |
^(self new)
|
|
24 |
fromPackage: aCypressPackageDefinition;
|
|
25 |
yourself
|
|
26 |
! !
|
|
27 |
|
|
28 |
!CypressPackageStructure methodsFor:'accessing'!
|
|
29 |
|
|
30 |
classes
|
|
31 |
|
|
32 |
classes ifNil: [ classes := OrderedCollection new ].
|
|
33 |
^classes
|
|
34 |
!
|
|
35 |
|
|
36 |
extensions
|
|
37 |
|
|
38 |
extensions ifNil: [ extensions := OrderedCollection new ].
|
|
39 |
^extensions
|
|
40 |
!
|
|
41 |
|
|
42 |
packageExtension
|
|
43 |
|
|
44 |
^self properties at: 'extension' ifAbsent: ['.package' ]
|
|
45 |
!
|
|
46 |
|
|
47 |
packageName
|
|
48 |
|
|
49 |
^self name copyFrom: 1 to: (self name size - self packageExtension size)
|
|
50 |
!
|
|
51 |
|
|
52 |
packageStructure
|
|
53 |
^self
|
|
54 |
! !
|
|
55 |
|
6
|
56 |
!CypressPackageStructure methodsFor:'converting'!
|
|
57 |
|
8
|
58 |
asChangeSet
|
|
59 |
| changeset |
|
|
60 |
|
|
61 |
changeset := super asChangeSet.
|
|
62 |
changeset name: (self name , ' (loaded from Cypress)').
|
|
63 |
^changeset
|
|
64 |
|
|
65 |
"Created: / 03-09-2012 / 11:52:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
66 |
!
|
|
67 |
|
6
|
68 |
changesOn:aStream
|
|
69 |
"superclass CypressStructure says that I am responsible to implement this method"
|
|
70 |
|
7
|
71 |
classes ? #() do:[:cls | cls changesOn: aStream ].
|
|
72 |
extensions ? #() do:[:ext | ext changesOn: aStream ].
|
6
|
73 |
|
7
|
74 |
"Modified: / 03-09-2012 / 10:57:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
6
|
75 |
! !
|
|
76 |
|
1
|
77 |
!CypressPackageStructure methodsFor:'initialization'!
|
|
78 |
|
|
79 |
fromJs: jsObject
|
|
80 |
|
|
81 |
name := jsObject at: 'name'.
|
|
82 |
(jsObject at: 'contents') do: [:jsClassObject| | classStructure objectName |
|
|
83 |
classStructure := (CypressClassStructure new)
|
|
84 |
packageStructure: self;
|
|
85 |
yourself.
|
|
86 |
( '*.extension' match:(objectName := jsClassObject at: 'name') )
|
|
87 |
ifTrue: [
|
|
88 |
classStructure isClassExtension: true.
|
|
89 |
self extensions add: classStructure ]
|
|
90 |
ifFalse: [
|
|
91 |
( '*.class' match: objectName)
|
|
92 |
ifTrue: [
|
|
93 |
classStructure isClassExtension: false.
|
|
94 |
self classes add: classStructure ]].
|
|
95 |
classStructure fromJs: jsClassObject].
|
|
96 |
properties := jsObject at: 'properties.json'
|
|
97 |
!
|
|
98 |
|
|
99 |
fromPackage: aCypressPackageDefinition
|
|
100 |
|
4
|
101 |
| snapshot classMap classDefinitions classStructure |
|
|
102 |
snapshot := aCypressPackageDefinition snapshot.
|
|
103 |
name := (aCypressPackageDefinition name copy
|
|
104 |
replaceAll: $: with:$_;
|
|
105 |
replaceAll: $/ with:$_;
|
|
106 |
yourself)
|
|
107 |
, '.package'.
|
|
108 |
properties := Dictionary new.
|
6
|
109 |
properties at: '_stx_name' put: aCypressPackageDefinition name.
|
4
|
110 |
classDefinitions := Set new.
|
|
111 |
classMap := Dictionary new.
|
|
112 |
snapshot definitions do: [:definition |
|
|
113 |
definition
|
|
114 |
classDefinition: [:classDefinition | classDefinitions add: classDefinition ]
|
|
115 |
methodDefinition: [:methodDefinition |
|
|
116 |
(classMap
|
|
117 |
at: methodDefinition className
|
|
118 |
ifAbsent: [classMap at: methodDefinition className put: Set new])
|
|
119 |
add: methodDefinition. ]].
|
|
120 |
classDefinitions do: [:classDefinition |
|
|
121 |
classStructure := (CypressClassStructure fromClassDefinition: classDefinition)
|
|
122 |
packageStructure: self.
|
|
123 |
(classMap removeKey: classDefinition className ifAbsent: [#()]) do: [:methodDefinition | | methodStructure |
|
|
124 |
methodStructure := (CypressMethodStructure fromMethodDefinition: methodDefinition)
|
|
125 |
packageStructure: self;
|
|
126 |
classStructure: classStructure.
|
|
127 |
(methodDefinition
|
|
128 |
instanceMethod: [:instanceMethod | classStructure instanceMethods ]
|
|
129 |
classMethod: [:classMethod | classStructure classMethods ])
|
|
130 |
at: methodDefinition selector
|
|
131 |
put: methodStructure ].
|
|
132 |
self classes add: classStructure ].
|
|
133 |
classMap keysAndValuesDo: [:className :methods |
|
|
134 |
classStructure := (CypressClassStructure new name: className)
|
|
135 |
packageStructure: self.
|
|
136 |
methods do: [:methodDefinition | | methodStructure |
|
|
137 |
methodStructure := (CypressMethodStructure fromMethodDefinition: methodDefinition)
|
|
138 |
packageStructure: self;
|
|
139 |
classStructure: classStructure.
|
|
140 |
(methodDefinition
|
|
141 |
instanceMethod: [:instanceMethod | classStructure instanceMethods ]
|
|
142 |
classMethod: [:classMethod | classStructure classMethods ])
|
|
143 |
at: methodDefinition selector
|
|
144 |
put: methodStructure ].
|
|
145 |
self extensions add: classStructure ].
|
|
146 |
|
6
|
147 |
"Modified: / 31-08-2012 / 19:56:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1
|
148 |
! !
|
|
149 |
|
|
150 |
!CypressPackageStructure methodsFor:'snapshotting'!
|
|
151 |
|
|
152 |
snapshot
|
|
153 |
| definitions |
|
|
154 |
definitions := OrderedCollection new.
|
|
155 |
self classes do: [:classStructure |
|
|
156 |
definitions add: classStructure asCypressClassDefinition.
|
|
157 |
(classStructure instanceMethods values asArray asSortedCollection: [:a :b | a selector <= b selector]) do: [:methodStructure |
|
|
158 |
definitions add: methodStructure asCypressMethodDefinition ].
|
|
159 |
(classStructure classMethods values asArray asSortedCollection: [:a :b | a selector <= b selector]) do: [:methodStructure |
|
|
160 |
definitions add: methodStructure asCypressMethodDefinition ]].
|
|
161 |
self extensions do: [:classStructure |
|
|
162 |
(classStructure instanceMethods values asArray asSortedCollection: [:a :b | a selector <= b selector]) do: [:methodStructure |
|
|
163 |
definitions add: methodStructure asCypressMethodDefinition ].
|
|
164 |
(classStructure classMethods values asArray asSortedCollection: [:a :b | a selector <= b selector]) do: [:methodStructure |
|
|
165 |
definitions add: methodStructure asCypressMethodDefinition ]].
|
|
166 |
^ CypressSnapshot definitions: definitions
|
|
167 |
|
|
168 |
"Modified: / 30-08-2012 / 13:31:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
169 |
! !
|
|
170 |
|
|
171 |
!CypressPackageStructure methodsFor:'writing'!
|
|
172 |
|
|
173 |
writeJsonOn: aStream indent: startIndent
|
|
174 |
|
4
|
175 |
| indent |
|
|
176 |
indent := startIndent.
|
|
177 |
aStream
|
|
178 |
tab: indent;
|
|
179 |
nextPutAll: '{';
|
|
180 |
cr.
|
|
181 |
indent := indent + 1.
|
|
182 |
aStream
|
|
183 |
tab: indent;
|
|
184 |
nextPutAll: '"name"';
|
|
185 |
nextPutAll: ' : ';
|
|
186 |
nextPutAll: '"', self name, '",'.
|
|
187 |
aStream
|
|
188 |
cr;
|
|
189 |
tab: indent;
|
|
190 |
nextPutAll: '"contents" : [';
|
|
191 |
cr;
|
|
192 |
yourself.
|
|
193 |
1 to: self classes size do: [:index | | classStructure |
|
|
194 |
classStructure := self classes at: index.
|
|
195 |
classStructure writeJsonOn: aStream indent: indent + 1.
|
|
196 |
(self extensions size > 0 or: [ index < self classes size]) ifTrue: [ aStream nextPutAll: ','; newLine. ]].
|
|
197 |
1 to: self extensions size do: [:index | | classStructure |
|
|
198 |
classStructure := self extensions at: index.
|
|
199 |
classStructure writeJsonOn: aStream indent: indent + 1.
|
|
200 |
index < self extensions size ifTrue: [ aStream nextPutAll: ','; newLine.] ].
|
|
201 |
aStream
|
|
202 |
cr;
|
|
203 |
tab: indent;
|
|
204 |
nextPutAll: '],';
|
|
205 |
cr;
|
|
206 |
tab: indent;
|
|
207 |
nextPutAll: '"properties.json" : '.
|
|
208 |
self properties writeCypressJsonOn: aStream forHtml: true indent: indent.
|
|
209 |
indent := indent - 1.
|
|
210 |
aStream
|
|
211 |
cr;
|
|
212 |
tab: indent;
|
|
213 |
nextPutAll: '}'
|
|
214 |
|
|
215 |
"Modified: / 30-08-2012 / 14:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1
|
216 |
! !
|
|
217 |
|
|
218 |
!CypressPackageStructure class methodsFor:'documentation'!
|
|
219 |
|
|
220 |
version_SVN
|
|
221 |
^ '$Id:: $'
|
|
222 |
! !
|