-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
SystemOrganizer.class.st
168 lines (133 loc) · 4.99 KB
/
SystemOrganizer.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"
My instances provide an organization for the classes in the system, just as a ClassOrganizer organizes the messages within a class. The only difference is the methods for fileIn/Out.
"
Class {
#name : #SystemOrganizer,
#superclass : #Categorizer,
#instVars : [
'environment'
],
#category : #'System-Support-Image'
}
{ #category : #cleanup }
SystemOrganizer class >> cleanUp: agressive [
"Remove empty categories when cleaning aggressively"
agressive ifTrue: [SystemOrganization removeEmptyCategories].
]
{ #category : #'instance creation' }
SystemOrganizer class >> default [
"look in the environment that the receiver organizes for the associated organization"
^ self environment organization.
]
{ #category : #accessing }
SystemOrganizer >> addCategory: newCategory [
(self includesCategory: newCategory) ifTrue: [ ^ self ].
super addCategory: newCategory.
SystemAnnouncer uniqueInstance classCategoryAdded: newCategory.
]
{ #category : #queries }
SystemOrganizer >> categoriesMatching: matchString [
"Return all matching categories"
self categories ifNil: [ ^#() ].
^ self categories select: [:c | matchString match: c]
]
{ #category : #queries }
SystemOrganizer >> classesInCategory: category [
^ (self listAtCategoryNamed: category) collect: [ :className | self environment at: className ]
]
{ #category : #accessing }
SystemOrganizer >> environment [
^ environment ifNil: [ environment := Smalltalk globals]
]
{ #category : #accessing }
SystemOrganizer >> environment: aSystemDictionary [
environment := aSystemDictionary.
]
{ #category : #testing }
SystemOrganizer >> includesCategory: aString [
"Tests if a category is already included."
^ self categories
ifNil: [ false ]
ifNotNil: [ :categories | categories includes: aString ]
]
{ #category : #initialization }
SystemOrganizer >> initialize [
super initialize.
categoryArray := Array new.
categoryStops := Array new.
elementArray := Array new
]
{ #category : #queries }
SystemOrganizer >> orderedTraitsIn: category [
"Answer an OrderedCollection containing references to the traits in the
category whose name is the argument, category (a string). The traits
are ordered so they can be filed in."
| behaviors traits |
behaviors := (self listAtCategoryNamed: category asSymbol) collect: [ :title | self environment at: title ].
traits := behaviors select: [ :each | each isTrait ].
traits := traits
asSortedCollection: [ :t1 :t2 | (t2 traitComposition allTraits includes: t1) or: [ (t1 traitComposition allTraits includes: t2) not ] ].
^ traits asArray
]
{ #category : #remove }
SystemOrganizer >> removeCategoriesMatching: matchString [
"Remove all matching categories with their classes"
(self categoriesMatching: matchString) do:
[:c | self removeSystemCategory: c]
]
{ #category : #accessing }
SystemOrganizer >> removeCategory: category [
| r |
r := super removeCategory: category.
"If the category we try to remove is the default one, due to cleansing, we don't have to announce it since it is not a valid category for a Class"
category = Default ifFalse: [
SystemAnnouncer uniqueInstance classCategoryRemoved: category.
].
^ r
]
{ #category : #queries }
SystemOrganizer >> removeMissingClasses [
"Remove any class names that are no longer in the Smalltalk dictionary. Used for cleaning up after garbage collecting user-generated classes."
"SystemOrganization removeMissingClasses"
elementArray copy
do: [ :el |
(self environment includesKey: el)
ifFalse: [ self removeElement: el ] ]
]
{ #category : #remove }
SystemOrganizer >> removeSystemCategory: category [
"remove all the classes and traits associated with the category"
(self orderedTraitsIn: category) , (self superclassOrder: category)
reverseDo: [:each | each removeFromSystem].
self removeCategory: category.
]
{ #category : #accessing }
SystemOrganizer >> renameCategory: oldCatString toBe: newCatString [
| r |
r := super renameCategory: oldCatString toBe: newCatString.
SystemAnnouncer uniqueInstance
classCategoryRenamedFrom: oldCatString to: newCatString.
^ r
]
{ #category : #queries }
SystemOrganizer >> superclassOrder: category [
"Answer an OrderedCollection containing references to the classes in the
category whose name is the argument, category (a string). The classes
are ordered with superclasses first so they can be filed in."
| behaviors classes |
behaviors := (self listAtCategoryNamed: category asSymbol) collect: [ :title | self environment at: title ].
classes := behaviors select: [ :each | each isBehavior ].
^ Class superclassOrder: classes
]
{ #category : #queries }
SystemOrganizer >> uncommentedClassesIn: categoryName [
"SystemOrganization uncommentedClassesIn: 'Morphic*'"
| classes |
classes := OrderedCollection new.
self categories
withIndexCollect: [ :cat :idx |
(categoryName match: cat)
ifTrue: [ classes addAll: (self listAtCategoryNumber: idx) ]
ifFalse: [ nil ] ].
^ (classes collect: [ :clsName | self environment at: clsName ] thenSelect: [ :cls | cls hasComment not ]) asArray
]