Skip to content

Commit 1affa2c

Browse files
committed
Refaactoring the appliers. Move the appliying logic to the appliers. Cleaning the api
1 parent ab026b9 commit 1affa2c

11 files changed

+52
-92
lines changed

src/RewriteRuleTools-Tests/MatchToolPresenter.extension.st

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ Extension { #name : #MatchToolPresenter }
33
{ #category : #'*RewriteRuleTools-Tests' }
44
MatchToolPresenter >> astCode [
55

6-
"This accessor should ONLY be called in the tests. This is for not break encapsulation."
6+
"This accessor should ONLY be called in the tests."
77

88
^ astCode
99
]
1010

1111
{ #category : #'*RewriteRuleTools-Tests' }
1212
MatchToolPresenter >> astPattern [
1313

14-
"This accessor should ONLY be called in the tests. This is for not break encapsulation."
14+
"This accessor should ONLY be called in the tests."
1515

1616
^ astPattern
1717
]
1818

1919
{ #category : #'*RewriteRuleTools-Tests' }
2020
MatchToolPresenter >> bindingsTable [
2121

22-
"This accessor should ONLY be called in the tests. This is for not break encapsulation."
22+
"This accessor should ONLY be called in the tests."
2323

2424
^ bindingsTable
2525
]
2626

2727
{ #category : #'*RewriteRuleTools-Tests' }
2828
MatchToolPresenter >> codeEditor [
2929

30-
"This accessor should ONLY be called in the tests. This is for not break encapsulation."
30+
"This accessor should ONLY be called in the tests."
3131

3232
^ codeEditor
3333
]
@@ -51,7 +51,7 @@ MatchToolPresenter >> methodCheckbox [
5151
{ #category : #'*RewriteRuleTools-Tests' }
5252
MatchToolPresenter >> ruleEditor [
5353

54-
"This accessor should ONLY be called in the tests. This is for not break encapsulation."
54+
"This accessor should ONLY be called in the tests."
5555

5656
^ ruleEditor
5757
]

src/RewriteRuleTools-Tests/RTChangesBrowserTest.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ RTChangesBrowserTest >> getChangesArray: aClassName [
1717
`@codeBlock'.
1818

1919
changes := RTAbstractApplier defaultEngineApplier
20-
changesOf: ((self class environment classNamed: aClassName) methods)
21-
forRules: { rule }.
20+
calculateChangesForClasses: ((self class environment classNamed: aClassName) methods)
21+
transformationRules: { rule }.
2222

2323
^ changes
2424
]

src/RewriteRuleTools/ApplyRuleOnAllClassesCommand.class.st

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ ApplyRuleOnAllClassesCommand class >> iconName [
3030
{ #category : #executing }
3131
ApplyRuleOnAllClassesCommand >> execute [
3232

33-
| changes |
33+
| changes ruleHolder |
3434
(UIManager default
3535
confirm: 'This process can take between 1 and 2 minutes.'
3636
label: 'Proceed?')
3737
ifFalse: [ ^ self ].
38+
ruleHolder := RTAbstractApplier
39+
createRuleHolder: self context lhs -> self context rhs
40+
isforMethod: self context isForMethod.
3841

3942
changes := RTAbstractApplier defaultEngineApplier
40-
changesToAllClassesAssociation: self context lhs -> self context rhs
41-
isForMethod: self context isRuleForMethod.
43+
calculateAllChangesForRules: ruleHolder asOrderedCollection.
4244
^ (RTChangesBrowser changes: changes) open
4345
]

src/RewriteRuleTools/ApplyRuleOnSelectedClassesCommand.class.st

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ ApplyRuleOnSelectedClassesCommand class >> iconName [
3131
ApplyRuleOnSelectedClassesCommand >> execute [
3232

3333
| dialogWindow changes |
34+
self flag: 'Need to refactor this. the message scopeSelectorPresenter est specifique à RTRuleEditorPresenter.'.
3435
dialogWindow := self context scopeSelectorPresenter openAsDialog.
3536
dialogWindow
3637
okAction: [
38+
| ruleHolder |
39+
ruleHolder := RTAbstractApplier
40+
createRuleHolder: self context lhs -> self context rhs
41+
isforMethod: self context isForMethod.
42+
3743
changes := RTAbstractApplier defaultEngineApplier
38-
changesToClasses: self context scopeSelectorPresenter selectedClasses
39-
association: self context lhs -> self context rhs
40-
isForMethod: self context isRuleForMethod.
44+
calculateChangesForClasses: self context scopeSelectorPresenter selectedClasses
45+
transformationRules: ruleHolder asOrderedCollection.
4146
(RTChangesBrowser changes: changes) open ]
4247

4348

src/RewriteRuleTools/MatchToolPresenter.class.st

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ MatchToolPresenter >> selectedMatchChanged: selection [
249249
bindingsTable items: #( ).
250250
codeEditor clearSelection ]
251251
ifNotNil: [
252-
bindingsTable items:
253-
(self getBindingsItemsForMatch: selectedMatch value).
252+
bindingsTable items: (self getBindingsItemsForMatch: selectedMatch value).
254253
codeEditor selectionInterval: selectedMatch key sourceInterval ]
255254
]

src/RewriteRuleTools/RTChangesBrowser.class.st

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ RTChangesBrowser class >> changes: aCollection [
2929
{ #category : #actions }
3030
RTChangesBrowser >> accept [
3131

32-
| refactoringJob |
3332
(self okToChange not or: [ selectedChanges isEmptyOrNil ]) ifTrue: [
3433
UIManager default inform: 'No changes to apply.'.
3534
^ self ].
3635

37-
refactoringJob := [ selectedChanges do: [ :change |
38-
RBRefactoryChangeManager instance performChange: change ] ] asJob.
39-
refactoringJob
40-
title: 'Refactoring';
41-
run.
36+
RTAbstractApplier applyTransformationChanges: selectedChanges.
37+
4238
self closeWindow
4339
]
4440

@@ -154,10 +150,10 @@ RTChangesBrowser >> selectedChanges [
154150
RTChangesBrowser >> updateChanges [
155151

156152
| aCompositeChange |
153+
self flag: 'This is weird. Think about refactoring'.
157154
aCompositeChange := RBRefactoryChangeManager changeFactory compositeRefactoryChange.
158155
changes do: [ :each | aCompositeChange addChange: each ].
159156

160157
"Later we could filter the shown changes depending on the selected scope"
161-
162158
changesTree roots: (aCompositeChange whatToDisplayIn: self)
163159
]

src/RewriteRuleTools/RTCodeTransformerPresenter.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ RTCodeTransformerPresenter >> runReplace [
156156
| changes selectedRules |
157157
selectedRules := rulesTablePresenter selectedRules.
158158
changes := RTAbstractApplier defaultEngineApplier
159-
changesOf: methodsSelectorPresenter selectedClasses
160-
forRules: selectedRules.
159+
calculateChangesForClasses: methodsSelectorPresenter selectedClasses
160+
transformationRules: selectedRules.
161161

162162
^ (RTChangesBrowser changes: changes) open
163163
]
@@ -167,7 +167,7 @@ RTCodeTransformerPresenter >> runReplaceOnAllClasses [
167167

168168
| changes |
169169
changes := RTAbstractApplier defaultEngineApplier
170-
changesOfAllMethodsFor: rulesTablePresenter selectedRules.
170+
calculateAllChangesForRules: rulesTablePresenter selectedRules.
171171

172172
(RTChangesBrowser changes: changes) open
173173
]

src/RewriteRuleTools/RTExpressionFinderPresenter.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ RTExpressionFinderPresenter >> patternCode: aString [
122122
RTExpressionFinderPresenter >> searchExpression [
123123

124124
| methods ruleHolder critiques |
125+
self flag: 'Need to refactor this we should get the methods from a class not calculate them our selves.'.
125126
methods := (RPackage organizer packages flatCollect: #classes)
126127
flatCollect: #methods.
127128
ruleHolder := RTRuleHolder
@@ -140,7 +141,7 @@ RTExpressionFinderPresenter >> searchExpressionOnAllClasses [
140141

141142
| dialogWindow methods ruleHolder critiques |
142143
dialogWindow := scopeSelectorPresenter openAsDialog.
143-
144+
self flag: 'This logic should be in the applier class'.
144145
dialogWindow okAction: [
145146
methods := scopeSelectorPresenter selectedClasses
146147
flatCollectAsSet: [ :each | each methods ].

src/RewriteRulesRewriter/RTAbstractApplier.class.st

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@ Class {
88
}
99

1010
{ #category : #api }
11-
RTAbstractApplier class >> changesOf: classes forRules: ruleHolderCollection [
12-
13-
^ self subclassResponsibility
14-
]
15-
16-
{ #category : #api }
17-
RTAbstractApplier class >> changesOfAllMethodsFor: ruleHolderCollection [
18-
19-
^ self subclassResponsibility
11+
RTAbstractApplier class >> applyTransformationChanges: changes [
12+
13+
| refactoringJob |
14+
refactoringJob := [
15+
changes do: [ :change | RBRefactoryChangeManager instance performChange: change ] ] asJob.
16+
refactoringJob
17+
title: 'Refactoring';
18+
run
2019
]
2120

2221
{ #category : #api }
23-
RTAbstractApplier class >> changesToAllClassesAssociation: ruleAsAssociation isForMethod: aBoolean [
22+
RTAbstractApplier class >> calculateAllChangesForRules: ruleHolderCollection [
2423

2524
^ self subclassResponsibility
2625
]
2726

2827
{ #category : #api }
29-
RTAbstractApplier class >> changesToClasses: classes association: ruleAsAssociation isForMethod: aBoolean [
28+
RTAbstractApplier class >> calculateChangesForClasses: classes transformationRules: ruleHolderCollection [
3029

3130
^ self subclassResponsibility
3231
]

src/RewriteRulesRewriter/RTRBApplier.class.st

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,7 @@ Class {
88
}
99

1010
{ #category : #api }
11-
RTRBApplier class >> changesOf: classes forRules: ruleHolderCollection [
12-
13-
| env rewriter |
14-
env := RTEnvironmentCreator scopeEnvironmentForClasses: classes.
15-
rewriter := self rewriter: ruleHolderCollection.
16-
17-
^ self obtainChanges: env rewriter: rewriter
18-
]
19-
20-
{ #category : #api }
21-
RTRBApplier class >> changesOfAllMethodsFor: ruleHolderCollection [
11+
RTRBApplier class >> calculateAllChangesForRules: ruleHolderCollection [
2212

2313
| env rewriter |
2414
env := RTEnvironmentCreator scopeEnvironmentForAllPackages.
@@ -28,23 +18,11 @@ RTRBApplier class >> changesOfAllMethodsFor: ruleHolderCollection [
2818
]
2919

3020
{ #category : #api }
31-
RTRBApplier class >> changesToAllClassesAssociation: ruleAsAssociation isForMethod: aBoolean [
21+
RTRBApplier class >> calculateChangesForClasses: classes transformationRules: ruleHolderCollection [
3222

33-
| ruleHolder env rewriter |
34-
env := RTEnvironmentCreator scopeEnvironmentForAllPackages.
35-
ruleHolder := self createRuleHolder: ruleAsAssociation isforMethod: aBoolean.
36-
rewriter := self rewriter: { ruleHolder }.
37-
38-
^ self obtainChanges: env rewriter: rewriter
39-
]
40-
41-
{ #category : #api }
42-
RTRBApplier class >> changesToClasses: classes association: ruleAsAssociation isForMethod: aBoolean [
43-
44-
| ruleHolder env rewriter |
23+
| env rewriter |
4524
env := RTEnvironmentCreator scopeEnvironmentForClasses: classes.
46-
ruleHolder := self createRuleHolder: ruleAsAssociation isforMethod: aBoolean.
47-
rewriter := self rewriter: { ruleHolder }.
25+
rewriter := self rewriter: ruleHolderCollection.
4826

4927
^ self obtainChanges: env rewriter: rewriter
5028
]
@@ -61,7 +39,6 @@ RTRBApplier class >> obtainChanges: env rewriter: rewriter [
6139
rule: transformationRule;
6240
environment: env.
6341
checker run.
64-
6542
^ transformationRule changes
6643
]
6744

src/RewriteRulesRewriter/RTRenrakuApplier.class.st

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,24 @@ Class {
1010
}
1111

1212
{ #category : #api }
13-
RTRenrakuApplier class >> changesOf: methods forRules: rules [
14-
15-
| critiques changes |
16-
critiques := self obtainCritiquesOf: methods forRules: rules.
17-
"At this point you have a collection of critiques. Each critique can tell you which rule created it, and which target it criticizes.
18-
As the critiques are 'smart', the type you have here (node replace critiques) can give you change compatible with the ChangesBrowser or RewriteChangesBrowser."
19-
changes := critiques collect: [: each | each change].
20-
^ changes
21-
]
22-
23-
{ #category : #api }
24-
RTRenrakuApplier class >> changesOfAllMethodsFor: aRulesCollection [
13+
RTRenrakuApplier class >> calculateAllChangesForRules: aRulesCollection [
2514

2615
| allSystemMethods |
2716
allSystemMethods := (RPackage organizer packages flatCollect: [:each | each classes])
2817
flatCollect: [ :each | each methods].
2918

30-
^ self changesOf: allSystemMethods asSet forRules: aRulesCollection
31-
]
32-
33-
{ #category : #api }
34-
RTRenrakuApplier class >> changesToAllClassesAssociation: ruleAsAssociation isForMethod: aBoolean [
35-
36-
| ruleHolder |
37-
ruleHolder := self createRuleHolder: ruleAsAssociation isforMethod: aBoolean.
38-
39-
^ self changesOfAllMethodsFor: { ruleHolder }
19+
^ self calculateChangesForClasses: allSystemMethods asSet transformationRules: aRulesCollection
4020
]
4121

4222
{ #category : #api }
43-
RTRenrakuApplier class >> changesToClasses: classes association: ruleAsAssociation isForMethod: aBoolean [
44-
45-
| ruleHolder methodsInTheClasses |
46-
ruleHolder := self createRuleHolder: ruleAsAssociation isforMethod: aBoolean.
47-
methodsInTheClasses := (classes collect: [ :each | each methods ]) asSet.
23+
RTRenrakuApplier class >> calculateChangesForClasses: methods transformationRules: rules [
4824

49-
^ self changesOf: methodsInTheClasses forRules: { ruleHolder }
25+
| critiques changes |
26+
critiques := self obtainCritiquesOf: methods forRules: rules.
27+
"At this point you have a collection of critiques. Each critique can tell you which rule created it, and which target it criticizes.
28+
As the critiques are 'smart', the type you have here (node replace critiques) can give you change compatible with the ChangesBrowser or RewriteChangesBrowser."
29+
changes := critiques collect: [: each | each change].
30+
^ changes
5031
]
5132

5233
{ #category : #private }

0 commit comments

Comments
 (0)