-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from jecisc/53-Cleaner-to-remove-method-with-e…
…quivalent-defined-in-super-class- 53-Cleaner-to-remove-method-with-equivalent-defined-in-super-class-
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/Chanel-Tests/ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
" | ||
A ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest is a test class for testing the behavior of ChanelRemoveMethodsWithEquivalentInSuperClassCleaner | ||
" | ||
Class { | ||
#name : #ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest, | ||
#superclass : #ChanelAbstractCleanerTest, | ||
#instVars : [ | ||
'superClass' | ||
], | ||
#category : #'Chanel-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> setUp [ | ||
super setUp. | ||
superClass := self createDefaultClass. | ||
class := self createSubclassOf: superClass named: #ChanelRemoveMethodssWithSuperEquavalentSubClassFake. | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testClassRemoveMethodWithEquivalentInSuperClass [ | ||
superClass class compile: 'methodTest | ||
^2'. | ||
|
||
class class compile: 'methodTest | ||
^2'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass class localSelectors includes: #methodTest). | ||
self deny: (class class localSelectors includes: #methodTest) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testDoesNotRemoveMethodIfNotPresentInSuperClass [ | ||
class compile: 'method | ||
^3'. | ||
|
||
self runCleaner. | ||
|
||
self deny: (superClass localSelectors includes: #method). | ||
self assert: (class localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testDoesNotRemoveMethodsFromTrait [ | ||
| trait | | ||
trait := self createDefaultTrait. | ||
|
||
class setTraitComposition: trait. | ||
|
||
superClass compile: 'method | ||
^2'. | ||
|
||
trait compile: 'method | ||
^3'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self deny: (class localSelectors includes: #method). | ||
self assert: (trait localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testDoesNotRemoveNotEquivalentMethod [ | ||
superClass compile: 'method | ||
^2'. | ||
|
||
class compile: 'method | ||
^3'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self assert: (class localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testDoesNotRemoveNotEquivalentMethodWithPragma [ | ||
superClass compile: 'method | ||
^2'. | ||
|
||
class compile: 'method | ||
<pragma> | ||
^2'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self assert: (class localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testRemoveMethodWithEquivalentInSuperClass [ | ||
superClass compile: 'method | ||
^2'. | ||
|
||
class compile: 'method | ||
^2'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self deny: (class localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testRemoveMethodWithEquivalentInSuperClassWithComment [ | ||
superClass compile: 'method | ||
^2'. | ||
|
||
class compile: 'method | ||
"I don''t care about comments." | ||
^2'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self deny: (class localSelectors includes: #method) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleanerTest >> testRemoveMethodWithEquivalentInSuperClassWithJustCommentDifference [ | ||
superClass compile: 'method | ||
^2'. | ||
|
||
class compile: 'method | ||
"I don''t care about comments." | ||
^2'. | ||
|
||
self runCleaner. | ||
|
||
self assert: (superClass localSelectors includes: #method). | ||
self deny: (class localSelectors includes: #method) | ||
] |
28 changes: 28 additions & 0 deletions
28
src/Chanel/ChanelRemoveMethodsWithEquivalentInSuperClassCleaner.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
" | ||
Description | ||
-------------------- | ||
I am a cleaner removing methods overriding another method with exactly the same AST. | ||
" | ||
Class { | ||
#name : #ChanelRemoveMethodsWithEquivalentInSuperClassCleaner, | ||
#superclass : #ChanelAbstractCleaner, | ||
#category : #Chanel | ||
} | ||
|
||
{ #category : #accessing } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleaner class >> priority [ | ||
^ 1500 | ||
] | ||
|
||
{ #category : #cleaning } | ||
ChanelRemoveMethodsWithEquivalentInSuperClassCleaner >> clean [ | ||
| overridenMethod | | ||
self configuration definedClasses iterator | ||
| #isTrait rejectIt | ||
| [ :class | class localMethods, class class localMethods ] flatCollectIt | ||
| [ :method | method methodClass superclass isNil ] rejectIt | ||
| [ :method | (overridenMethod := (method methodClass superclass lookupSelector: method selector)) isNil ] rejectIt | ||
| [ :method | method ast = overridenMethod ast ] selectIt | ||
> #removeMethod doIt | ||
] |