/
TestMatchedNodeProducer.class.st
148 lines (121 loc) · 4.66 KB
/
TestMatchedNodeProducer.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
"
I'm a little visitor. I take the specific node of the string that has to be completed and based on that node I give the list of completion results.
"
Class {
#name : #TestMatchedNodeProducer,
#superclass : #Object,
#instVars : [
'currentClass'
],
#category : #'NECompletion-New'
}
{ #category : #accessing }
TestMatchedNodeProducer >> completionContext: aClass [
currentClass := aClass.
]
{ #category : #completion }
TestMatchedNodeProducer >> completionListForNode: aRBNode [
^ aRBNode acceptVisitor: self
]
{ #category : #visiting }
TestMatchedNodeProducer >> methodNames [
^ Symbol selectorTable
]
{ #category : #utilities }
TestMatchedNodeProducer >> select: aCollection beginningWith: aString [
"Set withAll: is needed to convert potential IdentitySets to regular Sets"
^ Set withAll: (aCollection select: [ :each | each beginsWith: aString asString ])
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitArgumentNode: anArgumentNode [
"Sent *each time* an argument node is found"
^ self visitVariableNode: anArgumentNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitBlockNode: aRBBlockNode [
^ #()
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitGlobalNode: aRBGlobalNode [
^ self visitVariableNode: aRBGlobalNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitLiteralNode: aRBLiteralValueNode [
| results |
(aRBLiteralValueNode value isKindOf: Symbol) ifFalse: [ ^#() ].
"return all symbols that start with value"
results := OrderedCollection new.
Symbol allSymbolTablesDo: [ :symbol |
(symbol beginsWith: aRBLiteralValueNode value)
ifTrue: [ results add: symbol ].
results size >= 10 ifTrue: [ ^ results ]
].
^ results
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitLiteralValueNode: aRBLiteralValueNode [
^ self visitLiteralNode: aRBLiteralValueNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitMessageNode: aRBMessageNode [
"uses the TypingVisitor and the idea of double dispatch to avoid multiple if statements"
| receiver |
receiver := aRBMessageNode receiver.
(receiver hasProperty: #type)
ifTrue: [ ^ self select: (receiver propertyAt: #type) allSelectors beginningWith: aRBMessageNode selector ] .
^ self select: Symbol selectorTable beginningWith: aRBMessageNode selector
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitMethodNode: aRBMethodNode [
"there is a bug that we end up here when in temp definition, workaround turn it off for now"
"this turns off completion of methods and temp defitions, see issue tracker"
^#().
"(self select: self methodNames beginningWith: aRBMethodNode selector)"
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitNode: aNode [
^aNode acceptVisitor: self
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitParseErrorNode: aRBLiteralValueNode [
^ #()
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitPragmaNode: aPragmaNode [
^ self select: Symbol allSymbols beginningWith: aPragmaNode selector
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitReturnNode: aNode [
^ #()
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitSelfNode: aRBSelfNode [
^ self visitVariableNode: aRBSelfNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitSequenceNode: aRBSequenceNode [
^ #()
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitSuperNode: aSuperNode [
^ self visitVariableNode: aSuperNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitTemporaryNode: aNode [
"Sent *each time* a temporary node is found"
^ self visitVariableNode: aNode
]
{ #category : #visiting }
TestMatchedNodeProducer >> visitVariableNode: aRBVariableNode [
aRBVariableNode isDefinition ifTrue: [ ^ (self select: Symbol allSymbols beginningWith: aRBVariableNode name) ].
(aRBVariableNode isArgument ifTrue: [ ^ (self select: Symbol allSymbols beginningWith: aRBVariableNode name) select: [ :each | each numArgs = 0 ] ]).
"using a stream to store results should be better"
^ (self select: Smalltalk globals keys beginningWith: aRBVariableNode name) ,
(self select: (currentClass allSlots collect: [ :each | each name ]) beginningWith: aRBVariableNode name) ,
(self select: aRBVariableNode methodNode temporaryNames beginningWith: aRBVariableNode name),
(self select: aRBVariableNode methodNode argumentNames beginningWith: aRBVariableNode name),
(self select: currentClass allClassVarNames beginningWith: aRBVariableNode name),
(self select: (currentClass allSharedPools flatCollect: [ :each | each classVarNames]) beginningWith: aRBVariableNode name)
",(self select: self methodNames beginningWith: aRBVariableNode name)"
"this is a bit too much, we limit to variables"
]