forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ReOverridingExtentsionMethod rule
- Loading branch information
1 parent
4ca1de3
commit 32b1dd6
Showing
1 changed file
with
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
" | ||
A rule that checks whether a method is an extension and whether it overrides an existing method. Such a method is usually a bug or wrongly classified. | ||
" | ||
Class { | ||
#name : 'ReOverridingExtentsionMethod', | ||
#superclass : 'ReAbstractRule', | ||
#category : 'General-Rules-Migrated', | ||
#package : 'General-Rules', | ||
#tag : 'Migrated' | ||
} | ||
|
||
{ #category : 'running' } | ||
ReOverridingExtentsionMethod >> basicCheck: aMethod [ | ||
^ aMethod isExtension and: [ | ||
| superMethod | | ||
superMethod := aMethod origin superclass ifNotNil: [ :class | | ||
class lookupSelector: aMethod selector ]. | ||
superMethod notNil and: [ | ||
"Ignore overrides of extension methods in special classes. | ||
These may be name clashes or intended overrides of framework | ||
methods." | ||
(self specialClasses includes: superMethod methodClass) not and: [ | ||
"We allow extensions from the same package to override, so that | ||
hierarchies can be extended with overriding functionality." | ||
superMethod package ~= aMethod package ] ] ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReOverridingExtentsionMethod >> group [ | ||
^ 'Potential Bugs' | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReOverridingExtentsionMethod >> name [ | ||
|
||
^ 'An extension method overrides another method' | ||
] | ||
|
||
{ #category : 'private' } | ||
ReOverridingExtentsionMethod >> specialClasses [ | ||
^ {ProtoObject. Object. Behavior. Class. ClassDescription} | ||
] |