Refactoring Transformation Problems

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Refactoring Transformation Problems

Scott D
I have used Rewrite tool in other smalltalk dialects and the rewrite I
am attempting should work (I believe). But the result is empty.

I have the following test case below that demonstrats the problem.  
    pass - testEnvironment
    pass - testFindReplace
    fail - testTransformationRule

Any help would be very helpful.

Thanks,
Scott


"Filed out from Dolphin Smalltalk XP"!

TestCase subclass: #RewriteTestCase
        instanceVariableNames: 'env'
        classVariableNames: ''
        poolDictionaries: ''
        classInstanceVariableNames: ''!
RewriteTestCase guid: (GUID fromString:
'{6A77C1E6-2F15-4ABC-9442-261F617E5BA1}')!
RewriteTestCase comment: ''!
!RewriteTestCase categoriesForClass!Unclassified! !
!RewriteTestCase methodsFor!

setUp
        env := BrowserEnvironment new.
        env := env forClasses: (Array with: Animal).
        env := env referencesTo: #notify:caption:!

testEnvironment
        self
                assert: (env includesSelector: #ask in: Animal);
                assert: (env includesSelector: #playGame in: Animal class);
                deny: env isEmpty!

testFindReplace
        | find replace rule |
        find := '``@receiver notify: ``@arg caption: ``@arg1 '.
        replace := 'self notify: ``arg caption: ``@arg1'.
        rule := ParseTreeLintRule
                                createParseTreeRule: (Array with: find with: replace)
                                method: false
                                name: 'Find'.
        SmalllintChecker runRule: rule onEnvironment: env.
        self deny: rule isEmpty!

testTransformationRule
        | find replace rule |
        find := '``@receiver notify: ``@arg caption: ``@arg1 '.
        replace := 'self notify: ``arg caption: ``@arg1'.
        rule := TransformationRule
                                rewrite: (Array with: find with: replace)
                                methods: false
                                name: 'Transform'.
        SmalllintChecker runRule: rule onEnvironment: env.
        self deny: rule changes changes isEmpty! !
!RewriteTestCase categoriesFor: #setUp!public! !
!RewriteTestCase categoriesFor: #testEnvironment!public! !
!RewriteTestCase categoriesFor: #testFindReplace!public! !
!RewriteTestCase categoriesFor: #testTransformationRule!public! !


Reply | Threaded
Open this post in threaded view
|

Re: Refactoring Transformation Problems

Blair McGlashan
"Scott D" <[hidden email]> wrote in message
news:[hidden email]...
> I have used Rewrite tool in other smalltalk dialects and the rewrite I
> am attempting should work (I believe). But the result is empty.

That's because there is a typo in your replace rule, and TransformationRule
class>>rewrite:methods:name: expects an Array of Arrays as its first
argument. A corrected test is below.

Regards

Blair

---------------
!RewriteTestCase methodsFor!

testTransformationRule
 | find replace rule |
 find := '``@receiver notify: ``@arg caption: ``@arg1 '.
 replace := 'self notify: ``@arg caption: ``@arg1'.
 rule := TransformationRule
    rewrite: (Array with: (Array with: find with: replace))
    methods: false
    name: 'Transform'.
 SmalllintChecker runRule: rule onEnvironment: env.
 self deny: rule changes changes isEmpty! !
!RewriteTestCase categoriesFor: #testTransformationRule!public! !


Reply | Threaded
Open this post in threaded view
|

Re: Refactoring Transformation Problems

Scott D
Doh!

Thanks very much,
Scott

"Blair McGlashan" <[hidden email]> wrote in message news:<c07kmr$13gq6g$[hidden email]>...

> "Scott D" <[hidden email]> wrote in message
> news:[hidden email]...
> > I have used Rewrite tool in other smalltalk dialects and the rewrite I
> > am attempting should work (I believe). But the result is empty.
>
> That's because there is a typo in your replace rule, and TransformationRule
> class>>rewrite:methods:name: expects an Array of Arrays as its first
> argument. A corrected test is below.
>
> Regards
>
> Blair
>
> ---------------
> !RewriteTestCase methodsFor!
>
> testTransformationRule
>  | find replace rule |
>  find := '``@receiver notify: ``@arg caption: ``@arg1 '.
>  replace := 'self notify: ``@arg caption: ``@arg1'.
>  rule := TransformationRule
>     rewrite: (Array with: (Array with: find with: replace))
>     methods: false
>     name: 'Transform'.
>  SmalllintChecker runRule: rule onEnvironment: env.
>  self deny: rule changes changes isEmpty! !
> !RewriteTestCase categoriesFor: #testTransformationRule!public! !