/
RBPragmaEnvironment.class.st
112 lines (96 loc) · 2.9 KB
/
RBPragmaEnvironment.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
"
I am a RBBrowserEnvironment on a set of Pragmas.
I containt all entities that define methods using this pragmas.
Example:
(RBBrowserEnvironment new) forPragmas:{ #primitive:}.
"
Class {
#name : #RBPragmaEnvironment,
#superclass : #RBBrowserEnvironmentWrapper,
#instVars : [
'keywords',
'condition'
],
#category : #'Refactoring-Environment'
}
{ #category : #'instance creation' }
RBPragmaEnvironment class >> keywords: aKeywordCollection [
^ self
onEnvironment: self default
keywords: aKeywordCollection
]
{ #category : #'instance creation' }
RBPragmaEnvironment class >> onEnvironment: anEnvironment keywords: aKeywordCollection [
^ (self onEnvironment: anEnvironment)
keywords: aKeywordCollection;
yourself
]
{ #category : #adding }
RBPragmaEnvironment >> addKeyword: aSymbol [
keywords add: aSymbol
]
{ #category : #initialization }
RBPragmaEnvironment >> condition: aBlock [
condition := aBlock
]
{ #category : #private }
RBPragmaEnvironment >> defaultLabel [
| stream |
stream := String new writeStream.
keywords do: [ :each | stream nextPut: $<; nextPutAll: each; nextPut: $>; nextPut: $ ].
^ stream contents
]
{ #category : #testing }
RBPragmaEnvironment >> definesClass: aClass [
^ environment definesClass: aClass
]
{ #category : #testing }
RBPragmaEnvironment >> includesCategory: aCategory [
^ (environment includesCategory: aCategory) and: [ (self classNamesFor: aCategory) notEmpty ]
]
{ #category : #testing }
RBPragmaEnvironment >> includesClass: aClass [
^ (environment includesClass: aClass) and: [ aClass selectors anySatisfy: [ :each | self includesSelector: each in: aClass ] ]
]
{ #category : #testing }
RBPragmaEnvironment >> includesPragma: aPragma [
^ (keywords includes: aPragma selector) and: [ condition value: aPragma ]
]
{ #category : #testing }
RBPragmaEnvironment >> includesProtocol: aProtocol in: aClass [
^ (environment includesProtocol: aProtocol in: aClass) and: [ (self selectorsFor: aProtocol in: aClass) notEmpty ]
]
{ #category : #testing }
RBPragmaEnvironment >> includesSelector: aSelector in: aClass [
(environment includesSelector: aSelector in: aClass)
ifFalse: [ ^ false ].
^ (aClass compiledMethodAt: aSelector) pragmas
anySatisfy: [ :each | self includesPragma: each ]
]
{ #category : #initialization }
RBPragmaEnvironment >> initialize [
super initialize.
keywords := IdentitySet new.
condition := [ :pragma | true ]
]
{ #category : #initialization }
RBPragmaEnvironment >> keywords: aCollection [
keywords addAll: aCollection
]
{ #category : #testing }
RBPragmaEnvironment >> packages [
^ (self methods collect: [:each | each package]) asSet
]
{ #category : #copying }
RBPragmaEnvironment >> postCopy [
super postCopy.
keywords := keywords copy
]
{ #category : #printing }
RBPragmaEnvironment >> storeOn: aStream [
aStream nextPut: $(.
super storeOn: aStream.
aStream nextPutAll: ' keywords: '.
keywords asArray storeOn: aStream.
aStream nextPut: $)
]