1
|
1 |
"{ Package: 'stx:goodies/cypress' }"
|
|
2 |
|
|
3 |
CypressStructure subclass:#CypressClassStructure
|
|
4 |
instanceVariableNames:'instanceMethods classMethods comment isClassExtension'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Cypress-Structure'
|
|
8 |
!
|
|
9 |
|
|
10 |
CypressClassStructure 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 |
!CypressClassStructure class methodsFor:'instance creation'!
|
|
15 |
|
|
16 |
fromClassDefinition: classDefinition
|
|
17 |
|
|
18 |
^self new
|
|
19 |
fromClassDefinition: classDefinition;
|
|
20 |
yourself
|
|
21 |
! !
|
|
22 |
|
|
23 |
!CypressClassStructure methodsFor:'accessing'!
|
|
24 |
|
|
25 |
category
|
|
26 |
|
|
27 |
^self packageStructure packageName
|
|
28 |
!
|
|
29 |
|
|
30 |
classInstanceVariableNames
|
|
31 |
^self properties at: 'classinstvars' ifAbsent: ['']
|
|
32 |
!
|
|
33 |
|
|
34 |
classInstanceVariableNames: aString
|
|
35 |
^self properties at: 'classinstvars' put: aString
|
|
36 |
!
|
|
37 |
|
|
38 |
classMethods
|
|
39 |
|
|
40 |
classMethods ifNil: [ classMethods := Dictionary new ].
|
|
41 |
^classMethods
|
|
42 |
!
|
|
43 |
|
|
44 |
className
|
|
45 |
|
|
46 |
^self name
|
|
47 |
!
|
|
48 |
|
|
49 |
comment
|
|
50 |
|
|
51 |
comment ifNil: [ comment := '' ].
|
|
52 |
^comment
|
|
53 |
!
|
|
54 |
|
|
55 |
comment: aString
|
|
56 |
|
|
57 |
comment := aString
|
|
58 |
!
|
|
59 |
|
|
60 |
instanceMethods
|
|
61 |
|
|
62 |
instanceMethods ifNil: [ instanceMethods := Dictionary new ].
|
|
63 |
^instanceMethods
|
|
64 |
!
|
|
65 |
|
|
66 |
instanceVariableNames
|
|
67 |
|
|
68 |
^self properties at: 'instvars' ifAbsent: ['']
|
|
69 |
!
|
|
70 |
|
|
71 |
instanceVariableNames: aString
|
|
72 |
|
|
73 |
^self properties at: 'instvars' put: aString
|
|
74 |
!
|
|
75 |
|
|
76 |
isClassExtension
|
|
77 |
|
|
78 |
isClassExtension ifNil: [ isClassExtension := true ].
|
|
79 |
^isClassExtension
|
|
80 |
!
|
|
81 |
|
|
82 |
isClassExtension: aBoolean
|
|
83 |
|
|
84 |
isClassExtension := aBoolean
|
|
85 |
!
|
|
86 |
|
|
87 |
name
|
|
88 |
|
|
89 |
^self properties at: 'name'
|
|
90 |
!
|
|
91 |
|
|
92 |
name: aString
|
|
93 |
|
|
94 |
self properties at: 'name' put: aString
|
|
95 |
!
|
|
96 |
|
|
97 |
properties: classPropertiesDict
|
|
98 |
properties _ classPropertiesDict
|
|
99 |
!
|
|
100 |
|
|
101 |
superclassName
|
|
102 |
|
|
103 |
^self properties at: 'super'
|
|
104 |
!
|
|
105 |
|
|
106 |
superclassName: aString
|
|
107 |
|
|
108 |
^self properties at: 'super' put: aString
|
|
109 |
! !
|
|
110 |
|
|
111 |
!CypressClassStructure methodsFor:'converting'!
|
|
112 |
|
|
113 |
asCypressClassDefinition
|
|
114 |
self isClassExtension ifTrue: [ ^nil ].
|
|
115 |
^CypressClassDefinition
|
|
116 |
name: self className
|
|
117 |
superclassName: self superclassName
|
|
118 |
category: self category
|
|
119 |
instVarNames: self instanceVariableNames
|
|
120 |
classInstVarNames: self classInstanceVariableNames
|
|
121 |
comment: self comment
|
6
|
122 |
!
|
|
123 |
|
|
124 |
changesOn:aStream
|
|
125 |
| def |
|
|
126 |
|
|
127 |
isClassExtension ifFalse:[
|
|
128 |
def := ClassDefinitionChange new.
|
|
129 |
def superClassName: (properties at: #super).
|
|
130 |
def className: (properties at: #name).
|
|
131 |
def instanceVariableNames: (String streamContents:[:s|((properties at: #instvars ifAbsent:[#()])) do:[:i|s nextPutAll:i; space]]).
|
|
132 |
def classInstanceVariableNames: (String streamContents:[:s|((properties at: #classinstvars ifAbsent:[#()]) ) do:[:i|s nextPutAll:i; space]]).
|
|
133 |
def classVariableNames: (String streamContents:[:s|((properties at: #classvars ifAbsent:[#()] ) ) do:[:i|s nextPutAll:i; space]]).
|
8
|
134 |
def package: packageStructure name asSymbol.
|
|
135 |
def category: (properties at: #category).
|
6
|
136 |
aStream nextPut: def.
|
|
137 |
].
|
|
138 |
|
|
139 |
instanceMethods ? #() do:[:each|each changesOn: aStream].
|
|
140 |
classMethods ? #() do:[:each|each changesOn: aStream].
|
|
141 |
|
8
|
142 |
"Modified: / 03-09-2012 / 11:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1
|
143 |
! !
|
|
144 |
|
|
145 |
!CypressClassStructure methodsFor:'initialization'!
|
|
146 |
|
|
147 |
fromClassDefinition: classDefinition
|
|
148 |
|
|
149 |
self isClassExtension: false.
|
|
150 |
self name: classDefinition name.
|
|
151 |
self comment: classDefinition comment.
|
|
152 |
self superclassName: classDefinition superclassName.
|
|
153 |
self instanceVariableNames: classDefinition instVarNames.
|
|
154 |
self classInstanceVariableNames: classDefinition classInstVarNames.
|
|
155 |
!
|
|
156 |
|
|
157 |
fromJs: jsObject
|
|
158 |
|
|
159 |
properties := jsObject at: 'properties.json'.
|
|
160 |
(jsObject at: 'class' ifAbsent: [#()]) do: [:jsMethodObject | | methodNameParts |
|
|
161 |
methodNameParts := self splitMethodNameFor: jsMethodObject.
|
|
162 |
(self classMethodNamed: (methodNameParts at: 1))
|
|
163 |
packageStructure: self packageStructure;
|
|
164 |
classStructure: self;
|
|
165 |
isMetaclass: true;
|
|
166 |
fromJs: jsMethodObject named: methodNameParts ].
|
|
167 |
(jsObject at: 'instance' ifAbsent: [#()]) do: [:jsMethodObject | | methodNameParts |
|
|
168 |
methodNameParts := self splitMethodNameFor: jsMethodObject.
|
|
169 |
(self instanceMethodNamed: (methodNameParts at: 1))
|
|
170 |
packageStructure: self packageStructure;
|
|
171 |
classStructure: self;
|
|
172 |
fromJs: jsMethodObject named: methodNameParts ].
|
|
173 |
comment := jsObject at: 'README.md' ifAbsent: ['']
|
|
174 |
! !
|
|
175 |
|
|
176 |
!CypressClassStructure methodsFor:'private'!
|
|
177 |
|
|
178 |
splitMethodName: methodName
|
|
179 |
|
|
180 |
| ext |
|
|
181 |
ext := '.json'.
|
|
182 |
( '*' , ext match: methodName)
|
|
183 |
ifFalse: [
|
|
184 |
ext := '.st'.
|
|
185 |
('*' , ext match: methodName)
|
|
186 |
ifFalse: [ self error: 'invalid structure element: ', methodName ] ].
|
|
187 |
^{methodName copyFrom: 1 to: (methodName size - ext size). ext}
|
|
188 |
!
|
|
189 |
|
|
190 |
splitMethodNameFor: jsMethodObject
|
|
191 |
|
|
192 |
^self splitMethodName: (jsMethodObject at: 'name')
|
|
193 |
! !
|
|
194 |
|
|
195 |
!CypressClassStructure methodsFor:'querying'!
|
|
196 |
|
|
197 |
classMethodNamed: methodName
|
|
198 |
|
|
199 |
^self classMethods
|
|
200 |
at: methodName
|
|
201 |
ifAbsent: [ self classMethods at: methodName put: (CypressMethodStructure new name: methodName) ]
|
|
202 |
!
|
|
203 |
|
|
204 |
instanceMethodNamed: methodName
|
|
205 |
|
|
206 |
^self instanceMethods
|
|
207 |
at: methodName
|
|
208 |
ifAbsent: [ self instanceMethods at: methodName put: (CypressMethodStructure new name: methodName) ]
|
|
209 |
! !
|
|
210 |
|
|
211 |
!CypressClassStructure methodsFor:'writing'!
|
|
212 |
|
|
213 |
writeJsonOn: aStream indent: startIndent
|
|
214 |
|
|
215 |
| indent methods |
|
|
216 |
indent := startIndent.
|
|
217 |
aStream
|
|
218 |
tab: indent;
|
|
219 |
nextPutAll: '{';
|
4
|
220 |
cr.
|
1
|
221 |
indent := indent + 1.
|
|
222 |
aStream
|
|
223 |
tab: indent;
|
|
224 |
nextPutAll: '"name"';
|
|
225 |
nextPutAll: ' : ';
|
|
226 |
nextPutAll: '"', self name, (self isClassExtension ifTrue: [ '.extension' ] ifFalse: [ '.class' ]), '",';
|
4
|
227 |
cr.
|
1
|
228 |
aStream
|
|
229 |
tab: indent;
|
|
230 |
nextPutAll: '"instance" : [';
|
4
|
231 |
cr;
|
1
|
232 |
yourself.
|
|
233 |
methods := self instanceMethods values asArray asSortedCollection: [:a :b | a selector <= b selector].
|
|
234 |
1 to: methods size do: [:index | | methodStructure |
|
|
235 |
methodStructure := methods at: index.
|
|
236 |
methodStructure writeJsonOn: aStream indent: indent + 1.
|
4
|
237 |
index < methods size ifTrue: [ aStream nextPutAll: ','; cr ]].
|
1
|
238 |
aStream
|
|
239 |
tab: indent;
|
|
240 |
nextPutAll: '],';
|
4
|
241 |
cr;
|
1
|
242 |
yourself.
|
|
243 |
aStream
|
|
244 |
tab: indent;
|
|
245 |
nextPutAll: '"class" : [';
|
4
|
246 |
cr;
|
1
|
247 |
yourself.
|
|
248 |
methods := self classMethods values asArray asSortedCollection: [:a :b | a selector <= b selector].
|
|
249 |
1 to: methods size do: [:index | | methodStructure |
|
|
250 |
methodStructure := methods at: index.
|
|
251 |
methodStructure writeJsonOn: aStream indent: indent + 1.
|
4
|
252 |
index < methods size ifTrue: [ aStream nextPutAll: ','; cr ]].
|
1
|
253 |
aStream
|
|
254 |
tab: indent;
|
|
255 |
nextPutAll: ']'.
|
|
256 |
self isClassExtension
|
|
257 |
ifFalse: [
|
|
258 |
aStream
|
|
259 |
nextPutAll: ',';
|
4
|
260 |
cr;
|
1
|
261 |
tab: indent;
|
|
262 |
nextPutAll: '"README.md" : ';
|
|
263 |
yourself.
|
|
264 |
self comment writeCypressJsonOn: aStream forHtml: true indent: indent ].
|
|
265 |
aStream
|
|
266 |
nextPutAll: ',';
|
4
|
267 |
cr;
|
1
|
268 |
tab: indent;
|
|
269 |
nextPutAll: '"properties.json" : ';
|
|
270 |
yourself.
|
|
271 |
self properties writeCypressJsonOn: aStream forHtml: true indent: indent.
|
|
272 |
indent := indent - 1.
|
|
273 |
aStream
|
4
|
274 |
cr;
|
1
|
275 |
tab: indent;
|
|
276 |
nextPutAll: ' }'
|
|
277 |
|
4
|
278 |
"Modified: / 30-08-2012 / 14:50:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1
|
279 |
! !
|
|
280 |
|
|
281 |
!CypressClassStructure class methodsFor:'documentation'!
|
|
282 |
|
|
283 |
version_SVN
|
|
284 |
^ '$Id:: $'
|
|
285 |
! !
|