-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
RBGeneratePrintStringRefactoring.class.st
69 lines (58 loc) · 1.81 KB
/
RBGeneratePrintStringRefactoring.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
"
I am a refactoring for generating a printString (printOn: aStream) method.
You can specify which of my instance variables should be used for generating the printString.
For example:
```
RBGeneratePrintStringRefactoring
model: RBNamespace new
className: ClassS
variables: { #inst1 . #inst2 . #inst3 }
```
"
Class {
#name : #RBGeneratePrintStringRefactoring,
#superclass : #RBClassRefactoring,
#instVars : [
'variables'
],
#category : #'Refactoring-Core-Refactorings'
}
{ #category : #'instance creation' }
RBGeneratePrintStringRefactoring class >> className: aClass variables: anArray [
^ (self className: aClass) variables: anArray
]
{ #category : #'instance creation' }
RBGeneratePrintStringRefactoring class >> model: aNamespace className: aClass variables: anArray [
^ (self model: aNamespace className: aClass) variables: anArray
]
{ #category : #preconditions }
RBGeneratePrintStringRefactoring >> preconditions [
^ variables
inject: RBCondition empty
into: [ :condition :variable | condition & (RBCondition definesInstanceVariable: variable in: self theClass) ]
]
{ #category : #accessing }
RBGeneratePrintStringRefactoring >> theClass [
^ (self classObjectFor: className) instanceSide
]
{ #category : #transforming }
RBGeneratePrintStringRefactoring >> transform [
| method |
method := self parserClass
parseMethod:
'printOn: aStream
"Append a sequence of characters to aStream that identify the receiver."
super printOn: aStream'.
variables
do: [ :each |
method body
addNode:
(self parserClass
parseExpression:
('aStream nextPutAll: '' <1s>: ''; print: <1s>' expandMacrosWith: each)) ].
self theClass compile: method formattedCode classified: #(printing)
]
{ #category : #accessing }
RBGeneratePrintStringRefactoring >> variables: anArray [
variables := anArray
]