--- a/CodeGeneratorTool.st Thu Jul 07 16:13:39 2011 +0200
+++ b/CodeGeneratorTool.st Thu Jul 07 16:13:52 2011 +0200
@@ -833,6 +833,9 @@
!
executeCollectedChangesNamed:name
+
+ | changes |
+
compositeChangeCollector notNil ifTrue:[
compositeChangeNesting := compositeChangeNesting - 1.
compositeChangeNesting == 0 ifTrue:[
@@ -840,7 +843,14 @@
compositeChangeCollector changesSize == 0 ifTrue:[
self information:'Nothing generated.'.
] ifFalse:[
- RefactoryChangeManager performChange:compositeChangeCollector.
+ compositeChangeCollector changesSize == 1
+ ifTrue: [
+ RefactoryChangeManager instance performChange: compositeChangeCollector
+ ] ifFalse: [
+ changes := Tools::ChangeSetBrowser confirmChanges:
+ (ChangeSet with:compositeChangeCollector).
+ changes do:[:chg|RefactoryChangeManager instance performChange: chg].
+ ].
].
compositeChangeCollector := nil.
]
@@ -1079,6 +1089,130 @@
self subclassResponsibility
!
+createVisitorMethodsIn:visitedClass andCompilerClass:visitorClass
+ "
+ This is much like createVisitorMethodsIn:andVisitorClass:,
+ but generates
+ acceptVisitor:forEffect:
+ and
+ visit<NODE>:forEffect:
+ in visit* methods.
+ "
+
+ |sel superSel |
+
+ self assert:( visitedClass isMeta not ).
+ self assert:( visitorClass isMeta not ).
+
+ self startCollectChanges.
+
+ sel := ('visit' , visitedClass nameWithoutPrefix , ':').
+ superSel := ('visit' , visitedClass superclass nameWithoutPrefix , ':').
+
+ (visitedClass includesSelector:#acceptVisitor:forEffect:) ifFalse:
+ [self addChange:
+ (CodeGenerator new
+ class: visitedClass;
+ protocol: 'visiting';
+ source: ('acceptVisitor: visitor forEffect: effect
+ "Double dispatch back to the visitor, passing my type encoded in
+ the selector (visitor pattern) and given effect"
+
+ "stub code automatically generated - please change if required"
+
+ ^visitor `@sel: self forEffect: effect');
+ replace: '`@sel:' with: sel asSymbol;
+ change)
+ ].
+
+
+
+
+ (visitorClass includesSelector:(sel, 'forEffect:') asSymbol) ifFalse:[
+ self addChange:
+ (CodeGenerator new
+ class: visitorClass;
+ protocol: 'visiting';
+ source: ('`@sel: anObject forEffect: effect
+ "dispatched back from the visited object (visitor pattern)"
+
+ ^ self `@superSel: anObject forEffect: effect');
+ replace: '`@sel:' with: sel asSymbol;
+ replace: '`@superSel:' with: superSel asSymbol;
+ change)
+ ].
+
+
+ (visitorClass includesSelector:#'visit:') ifFalse:[
+ self
+ compile:
+('visit:anObject
+ "visit anObject (visitor pattern).
+ The object should call back one of my visitXXXX methods."
+
+ ^ anObject acceptVisitor:self
+')
+ forClass:visitorClass
+ inCategory:'visiting'.
+ ].
+
+ self executeCollectedChangesNamed:('Create Compiler Visiting Methods').
+
+ "Created: / 20-03-2010 / 10:49:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+createVisitorMethodsIn:visitedClass andVisitorClass2:visitorClass
+ "
+ This is much like createVisitorMethodsIn:andVisitorClass:,
+ but generates
+ self visitSuperclass: anObject
+ in visit* methods.
+ "
+
+ |sel superSel |
+
+ self assert:( visitedClass isMeta not ).
+ self assert:( visitorClass isMeta not ).
+
+ self startCollectChanges.
+
+ sel := ('visit' , visitedClass nameWithoutPrefix , ':').
+ superSel := ('visit' , visitedClass superclass nameWithoutPrefix , ':').
+ self createAcceptVisitorMethod:sel in:visitedClass.
+
+ (visitorClass includesSelector:sel) ifFalse:[
+ self addChange:
+ (CodeGenerator new
+ class: visitorClass;
+ protocol: 'visiting';
+ source: ('`@sel: anObject
+ "dispatched back from the visited %2-object (visitor pattern)"
+
+ ^ self `@superSel: anObject');
+ replace: '`@sel:' with: sel asSymbol;
+ replace: '`@superSel:' with: superSel asSymbol;
+ change)
+ ].
+
+
+ (visitorClass includesSelector:#'visit:') ifFalse:[
+ self
+ compile:
+('visit:anObject
+ "visit anObject (visitor pattern).
+ The object should call back one of my visitXXXX methods."
+
+ ^ anObject acceptVisitor:self
+')
+ forClass:visitorClass
+ inCategory:'visiting'.
+ ].
+
+ self executeCollectedChangesNamed:('Add Visitor Pattern').
+
+ "Created: / 07-07-2009 / 19:53:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)"
@@ -1421,10 +1555,6 @@
!CodeGeneratorTool class methodsFor:'documentation'!
-version
- ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.88 2011-02-10 15:58:16 cg Exp $'
-!
-
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.88 2011-02-10 15:58:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.89 2011-07-07 14:13:52 vrany Exp $'
! !