Skip to content

Commit f3baf23

Browse files
author
Andrei Chis
committed
Update refactoring tools to use data views
1 parent d00a02e commit f3baf23

24 files changed

+593
-197
lines changed
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
"
2+
Examples for GtLRefactoringDomainObject subclasses.
3+
"
4+
Class {
5+
#name : #GtLRefactoringDomainObjectExamples,
6+
#superclass : #Object,
7+
#category : 'Gt4LlmCore-Examples-Domain Objects'
8+
}
9+
10+
{ #category : #'examples - class domain object' }
11+
GtLRefactoringDomainObjectExamples >> basicClassDomainObject [
12+
<gtExample>
13+
| namespace domainObject targetClass |
14+
namespace := self exampleNamespace.
15+
targetClass := namespace classNamed: 'GtLExampleDomainBase'.
16+
17+
domainObject := GtLRefactoringClassDomainObject new
18+
model: namespace;
19+
targetClass: targetClass.
20+
21+
self assert: domainObject model equals: namespace.
22+
self assert: domainObject targetClass equals: targetClass.
23+
24+
^ domainObject
25+
]
26+
27+
{ #category : #'examples - class references domain object' }
28+
GtLRefactoringDomainObjectExamples >> basicClassReferencesDomainObject [
29+
<gtExample>
30+
| namespace domainObject targetClass references |
31+
namespace := self exampleNamespace.
32+
targetClass := namespace classNamed: 'GtLExampleDomainBase'.
33+
references := Array streamContents: [ :stream |
34+
namespace allReferencesToClass: targetClass do: [ :each | stream << each ] ].
35+
36+
domainObject := GtLRefactoringClassReferencesDomainObject new
37+
model: namespace;
38+
targetClass: targetClass;
39+
references: references.
40+
41+
self assert: domainObject targetClass equals: targetClass.
42+
self assert: domainObject references size >= 1.
43+
44+
^ domainObject
45+
]
46+
47+
{ #category : #'examples - class search domain object' }
48+
GtLRefactoringDomainObjectExamples >> basicClassSearchDomainObject [
49+
<gtExample>
50+
| domainObject |
51+
domainObject := GtLRefactoringClassSearchDomainObject new
52+
model: self exampleNamespace;
53+
query: 'Domain';
54+
allClassNames: #('GtLExampleDomainBase' 'GtLExampleDomainChild');
55+
foundClassNames: #('GtLExampleDomainBase' 'GtLExampleDomainChild').
56+
57+
self assert: domainObject query equals: 'Domain'.
58+
self assert: domainObject foundClassNames size equals: 2.
59+
60+
^ domainObject
61+
]
62+
63+
{ #category : #'examples - class subclasses domain object' }
64+
GtLRefactoringDomainObjectExamples >> basicClassSubclassesDomainObject [
65+
<gtExample>
66+
| namespace domainObject targetClass subclasses |
67+
namespace := self exampleNamespace.
68+
targetClass := namespace classNamed: 'GtLExampleDomainBase'.
69+
subclasses := targetClass subclasses asArray.
70+
71+
domainObject := GtLRefactoringClassSubclassesDomainObject new
72+
model: namespace;
73+
targetClass: targetClass;
74+
subclasses: subclasses.
75+
76+
self assert: domainObject targetClass equals: targetClass.
77+
self assert: domainObject subclasses size equals: 1.
78+
79+
^ domainObject
80+
]
81+
82+
{ #category : #'examples - method implementors domain object' }
83+
GtLRefactoringDomainObjectExamples >> basicMethodImplementorsDomainObject [
84+
<gtExample>
85+
| namespace domainObject implementors |
86+
namespace := self exampleNamespace.
87+
implementors := Array streamContents: [ :stream |
88+
namespace allImplementorsOf: #value do: [ :each | stream nextPut: each ] ].
89+
90+
domainObject := GtLRefactoringMethodImplementorsDomainObject new
91+
model: namespace;
92+
methodName: 'value';
93+
implementors: implementors.
94+
95+
self assert: domainObject methodName equals: 'value'.
96+
self assert: domainObject implementors size >= 2.
97+
98+
^ domainObject
99+
]
100+
101+
{ #category : #'examples - method references domain object' }
102+
GtLRefactoringDomainObjectExamples >> basicMethodReferencesDomainObject [
103+
<gtExample>
104+
| namespace domainObject references |
105+
namespace := self exampleNamespace.
106+
references := Array streamContents: [ :stream |
107+
namespace allReferencesTo: #value do: [ :each | stream << each ] ].
108+
109+
domainObject := GtLRefactoringMethodReferencesDomainObject new
110+
model: namespace;
111+
methodName: 'value';
112+
references: references;
113+
mayHaveMore: false.
114+
115+
self assert: domainObject methodName equals: 'value'.
116+
self assert: domainObject mayHaveMore not.
117+
118+
^ domainObject
119+
]
120+
121+
{ #category : #'examples - method source code domain object' }
122+
GtLRefactoringDomainObjectExamples >> basicMethodSourceCodeDomainObject [
123+
<gtExample>
124+
| namespace domainObject targetClass method |
125+
namespace := self exampleNamespace.
126+
targetClass := namespace classNamed: 'GtLExampleDomainBase'.
127+
method := targetClass methodFor: #value.
128+
129+
domainObject := GtLRefactoringMethodSourceCodeDomainObject new
130+
model: namespace;
131+
method: method.
132+
133+
self assert: domainObject methodName equals: 'value'.
134+
self assert: domainObject methodClassName equals: 'GtLExampleDomainBase'.
135+
136+
^ domainObject
137+
]
138+
139+
{ #category : #'examples - class domain object' }
140+
GtLRefactoringDomainObjectExamples >> classDomainObjectDataViewSerialization [
141+
<gtExample>
142+
| domainObject compositeView dataBlock jsonData |
143+
domainObject := self basicClassDomainObject.
144+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
145+
self assert: compositeView dataViews size equals: 1.
146+
147+
dataBlock := compositeView serializeToLlmPrimiteData.
148+
self assert: dataBlock isNotNil.
149+
self assert: dataBlock dataBlocks size equals: 1.
150+
151+
jsonData := dataBlock llmJsonData.
152+
self assert: (jsonData at: 'class') equals: 'GtLExampleDomainBase'.
153+
self assert: (jsonData at: 'superclass') equals: 'Object'.
154+
self assert: ((jsonData at: 'instanceSlots') includes: 'value').
155+
156+
^ dataBlock
157+
]
158+
159+
{ #category : #'examples - class references domain object' }
160+
GtLRefactoringDomainObjectExamples >> classReferencesDomainObjectDataViewSerialization [
161+
<gtExample>
162+
| domainObject compositeView dataBlock jsonData |
163+
domainObject := self basicClassReferencesDomainObject.
164+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
165+
self assert: compositeView dataViews size equals: 1.
166+
167+
dataBlock := compositeView serializeToLlmPrimiteData.
168+
self assert: dataBlock isNotNil.
169+
170+
jsonData := dataBlock llmJsonData.
171+
self assert: (jsonData at: 'class') equals: 'GtLExampleDomainBase'.
172+
self assert: (jsonData at: 'references') isCollection.
173+
174+
^ dataBlock
175+
]
176+
177+
{ #category : #'examples - class search domain object' }
178+
GtLRefactoringDomainObjectExamples >> classSearchDomainObjectDataViewSerialization [
179+
<gtExample>
180+
| domainObject compositeView dataBlock jsonData expected |
181+
domainObject := self basicClassSearchDomainObject.
182+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
183+
self assert: compositeView dataViews size equals: 1.
184+
185+
dataBlock := compositeView serializeToLlmPrimiteData.
186+
self assert: dataBlock isNotNil.
187+
188+
jsonData := dataBlock llmJsonData.
189+
expected := Dictionary new
190+
at: 'query' put: 'Domain';
191+
at: 'foundClasses' put: #('GtLExampleDomainBase' 'GtLExampleDomainChild');
192+
yourself.
193+
self assert: jsonData equals: expected.
194+
195+
^ dataBlock
196+
]
197+
198+
{ #category : #'examples - class subclasses domain object' }
199+
GtLRefactoringDomainObjectExamples >> classSubclassesDomainObjectDataViewSerialization [
200+
<gtExample>
201+
| domainObject compositeView dataBlock jsonData expected |
202+
domainObject := self basicClassSubclassesDomainObject.
203+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
204+
self assert: compositeView dataViews size equals: 1.
205+
206+
dataBlock := compositeView serializeToLlmPrimiteData.
207+
self assert: dataBlock isNotNil.
208+
209+
jsonData := dataBlock llmJsonData.
210+
expected := Dictionary new
211+
at: 'class' put: 'GtLExampleDomainBase';
212+
at: 'subclasses' put: #('GtLExampleDomainChild');
213+
yourself.
214+
self assert: jsonData equals: expected.
215+
216+
^ dataBlock
217+
]
218+
219+
{ #category : #'examples - namespace' }
220+
GtLRefactoringDomainObjectExamples >> exampleNamespace [
221+
"Create a namespace with example classes and methods for testing"
222+
<gtExample>
223+
| namespace baseClass childClass |
224+
namespace := GtRBNamespace new.
225+
namespace defineClass: 'Object subclass: #GtLExampleDomainBase
226+
instanceVariableNames: ''value''
227+
classVariableNames: ''''
228+
package: ''Gt4LlmCore-Examples-Fixtures'''.
229+
namespace defineClass: 'GtLExampleDomainBase subclass: #GtLExampleDomainChild
230+
instanceVariableNames: ''''
231+
classVariableNames: ''''
232+
package: ''Gt4LlmCore-Examples-Fixtures'''.
233+
baseClass := namespace classNamed: 'GtLExampleDomainBase'.
234+
childClass := namespace classNamed: 'GtLExampleDomainChild'.
235+
baseClass compile: 'value
236+
^ value' classified: 'accessing'.
237+
baseClass compile: 'value: anObject
238+
value := anObject' classified: 'accessing'.
239+
childClass compile: 'value
240+
^ super value + 1' classified: 'accessing'.
241+
childClass compile: 'callsBase
242+
^ GtLExampleDomainBase new' classified: 'examples'.
243+
^ namespace
244+
]
245+
246+
{ #category : #'examples - method implementors domain object' }
247+
GtLRefactoringDomainObjectExamples >> methodImplementorsDomainObjectDataViewSerialization [
248+
<gtExample>
249+
| domainObject compositeView dataBlock jsonData |
250+
domainObject := self basicMethodImplementorsDomainObject.
251+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
252+
self assert: compositeView dataViews size equals: 1.
253+
254+
dataBlock := compositeView serializeToLlmPrimiteData.
255+
self assert: dataBlock isNotNil.
256+
257+
jsonData := dataBlock llmJsonData.
258+
self assert: (jsonData at: 'methodName') equals: 'value'.
259+
self assert: (jsonData at: 'implementors') isCollection.
260+
261+
^ dataBlock
262+
]
263+
264+
{ #category : #'examples - method references domain object' }
265+
GtLRefactoringDomainObjectExamples >> methodReferencesDomainObjectDataViewSerialization [
266+
<gtExample>
267+
| domainObject compositeView dataBlock jsonData |
268+
domainObject := self basicMethodReferencesDomainObject.
269+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
270+
self assert: compositeView dataViews size equals: 1.
271+
272+
dataBlock := compositeView serializeToLlmPrimiteData.
273+
self assert: dataBlock isNotNil.
274+
275+
jsonData := dataBlock llmJsonData.
276+
self assert: (jsonData at: 'methodName') equals: 'value'.
277+
self assert: (jsonData at: 'mayHaveMoreReferences') equals: false.
278+
self assert: (jsonData at: 'references') isCollection.
279+
self assert: ((jsonData at: 'references') includes: 'GtLExampleDomainChild>>#value').
280+
281+
^ dataBlock
282+
]
283+
284+
{ #category : #'examples - method source code domain object' }
285+
GtLRefactoringDomainObjectExamples >> methodSourceCodeDomainObjectDataViewSerialization [
286+
<gtExample>
287+
| domainObject compositeView dataBlock jsonData expected |
288+
domainObject := self basicMethodSourceCodeDomainObject.
289+
compositeView := domainObject llmDataViewsFor: GtLDataView new.
290+
self assert: compositeView dataViews size equals: 1.
291+
292+
dataBlock := compositeView serializeToLlmPrimiteData.
293+
self assert: dataBlock isNotNil.
294+
295+
jsonData := dataBlock llmJsonData.
296+
expected := Dictionary new
297+
at: 'methodName' put: 'value';
298+
at: 'className' put: 'GtLExampleDomainBase';
299+
at: 'sourceCode' put: ('value{1}{2}^ value' format: { Character lf. Character tab });
300+
yourself.
301+
self assert: jsonData equals: expected.
302+
303+
^ dataBlock
304+
]

src/Gt4LlmCore-Examples/GtLRefactoringToolForClassLookupExamples.class.st

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,45 @@ Class {
33
#superclass : #Object,
44
#category : 'Gt4LlmCore-Examples-Tools'
55
}
6+
7+
{ #category : #examples }
8+
GtLRefactoringToolForClassLookupExamples >> classLookupForExistingClass [
9+
<gtExample>
10+
| tool call result |
11+
tool := self toolWithExampleClass.
12+
call := GtLFunctionToolCall new.
13+
call rawArguments: {'className' -> 'GtLRefactoringToolForClassLookupExampleClass'} asDictionary.
14+
result := tool performToolCall: call.
15+
self assert: call tool == tool.
16+
self assert: result isErrorDomainObject not.
17+
self assert: result targetObject targetClass name equals: 'GtLRefactoringToolForClassLookupExampleClass'.
18+
^ call
19+
]
20+
21+
{ #category : #examples }
22+
GtLRefactoringToolForClassLookupExamples >> classLookupForUnknownClass [
23+
<gtExample>
24+
| tool call result |
25+
tool := self toolWithExampleClass.
26+
call := GtLFunctionToolCall new.
27+
call rawArguments: {'className' -> 'NonExistentClass'} asDictionary.
28+
result := tool performToolCall: call.
29+
self assert: call tool == tool.
30+
self assert: result isErrorDomainObject.
31+
^ call
32+
]
33+
34+
{ #category : #'examples - tools' }
35+
GtLRefactoringToolForClassLookupExamples >> toolWithExampleClass [
36+
| namespace tool |
37+
namespace := GtRBNamespace new.
38+
namespace defineClass: 'Object subclass: #GtLRefactoringToolForClassLookupExampleClass
39+
instanceVariableNames: ''slot1''
40+
classVariableNames: ''''
41+
package: ''DemoTest'''.
42+
(namespace classNamed: 'GtLRefactoringToolForClassLookupExampleClass')
43+
compile: 'example ^ 42' classified: 'accessing'.
44+
tool := GtLRefactoringToolForClassLookup new.
45+
tool model: namespace.
46+
^ tool
47+
]

0 commit comments

Comments
 (0)