-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subclass replacement operator #75
Merged
Merged
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1bf1ecf
initial commit subclass replacement operator
5acaa22
refactoring
d82d983
Merge e712ac5068deee2f02f8510c5a4555bcfe30aa61
d61f1fa
finished subclass replacement operator, added tests
2e01b4c
refactorings
3b555d1
add more tests
0c1efa9
fix typo
b73cad7
refactoring modifiedSource methods
99dbb03
refactoring tests
5657e4e
added methods to avoid duplication
85401b8
refactoring mutant operator hierarchy
45420cc
rename expressionToReplace
e20557f
inlined method & fixed tests
4b2e2ea
start refactoring predicates, mutations are not applied
96b26b2
problem fixed, tests are ok now
cdc5b52
rename variable
3168693
rename and refactor newExpression method
0f37ac6
use unused method & remove block
52ae82f
remove block logic, and refactor subclass replacement op
35a4ebd
refactor
35ed327
refactoring mutant operator tests
1e92f77
refactoring again
7cfd90c
move tests in superclass
7b3307a
rename attribute and methods
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,41 @@ | ||
Class { | ||
#name : 'MTParametricMethodMutation', | ||
guillep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#superclass : 'MTMethodMutation', | ||
#instVars : [ | ||
'newExpression' | ||
], | ||
#category : 'MuTalk-Model', | ||
#package : 'MuTalk-Model' | ||
} | ||
|
||
{ #category : 'instance creation' } | ||
MTParametricMethodMutation class >> for: aMethod using: anOperatorApplied nodeNumber: aNodeNumber ofClass: aClass replacingWith: anObject [ | ||
|
||
^ self new | ||
initializeFor: aMethod | ||
using: anOperatorApplied | ||
nodeNumber: aNodeNumber | ||
ofClass: aClass | ||
replacingWith: anObject; | ||
yourself | ||
] | ||
|
||
{ #category : 'initialization' } | ||
MTParametricMethodMutation >> initializeFor: aMethod using: anOperatorApplied nodeNumber: aNodeNumber ofClass: aClass replacingWith: anObject [ | ||
|
||
super | ||
initializeFor: aMethod | ||
using: anOperatorApplied | ||
nodeNumber: aNodeNumber | ||
ofClass: aClass. | ||
newExpression := anObject | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTParametricMethodMutation >> modifiedSource [ | ||
|
||
^ operator | ||
modifiedSourceFor: originalMethod | ||
number: nodeNumber | ||
newExpression: newExpression | ||
] |
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,93 @@ | ||
Class { | ||
#name : 'MTSubclassReplacementOperator', | ||
#superclass : 'MTBlockBasedMutantOperator', | ||
#instVars : [ | ||
'classesToReplace' | ||
], | ||
#category : 'MuTalk-Model-Operators', | ||
#package : 'MuTalk-Model', | ||
#tag : 'Operators' | ||
} | ||
|
||
{ #category : 'printing' } | ||
MTSubclassReplacementOperator >> description [ | ||
|
||
^ 'Replace a class reference by a reference to one of its subclasses' | ||
] | ||
|
||
{ #category : 'applying' } | ||
MTSubclassReplacementOperator >> expressionToReplace [ | ||
|
||
^ [ :aNode | | ||
aNode isVariable and: [ | ||
(self class environment includesKey: aNode name) and: [ | ||
| referencedClass shouldReplace | | ||
referencedClass := self class environment at: aNode name. | ||
shouldReplace := referencedClass isClass and: [ | ||
referencedClass subclasses notEmpty ]. | ||
shouldReplace ifTrue: [ classesToReplace add: referencedClass ]. | ||
shouldReplace ] ] ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want that we discuss how to fix this. I know you just followed how others were done, but I don't like blocks used like this! |
||
] | ||
|
||
{ #category : 'initialization' } | ||
MTSubclassReplacementOperator >> initialize [ | ||
|
||
super initialize. | ||
classesToReplace := OrderedCollection new | ||
] | ||
|
||
{ #category : 'private' } | ||
MTSubclassReplacementOperator >> modifiedSourceFor: aCompiledMethod number: aNumber newExpression: anExpression [ | ||
|
||
^ self | ||
modifiedSourceFor: aCompiledMethod | ||
with: aCompiledMethod parseTree | ||
number: aNumber | ||
newExpression: anExpression | ||
] | ||
|
||
{ #category : 'private' } | ||
MTSubclassReplacementOperator >> modifiedSourceFor: aCompiledMethod with: aParseTree number: aNumber newExpression: anExpression [ | ||
|
||
| parser allNodes | | ||
parser := aParseTree copy. | ||
allNodes := parser allChildren select: self expressionToReplace. | ||
allNodes size >= aNumber ifTrue: [ | ||
| oldNode newNode | | ||
oldNode := allNodes at: aNumber. | ||
newNode := anExpression value: oldNode. | ||
oldNode replaceWith: newNode ]. | ||
^ parser formattedCode | ||
guillep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
|
||
{ #category : 'private' } | ||
MTSubclassReplacementOperator >> mutationFor: aCompiledMethod with: aParseTree number: aNumberOfSelector storeIn: aCollection [ | ||
|
||
| classToReplace | | ||
classToReplace := classesToReplace at: aNumberOfSelector. | ||
aCollection addAll: | ||
((1 to: classToReplace subclasses size) collect: [ :index | | ||
| newExpression | | ||
newExpression := self | ||
newExpressionForClass: aNumberOfSelector | ||
andSubclass: index. | ||
MTParametricMethodMutation | ||
for: aCompiledMethod | ||
using: self | ||
nodeNumber: aNumberOfSelector | ||
ofClass: aCompiledMethod methodClass | ||
replacingWith: newExpression ]). | ||
^ aCollection | ||
] | ||
|
||
{ #category : 'applying' } | ||
MTSubclassReplacementOperator >> newExpressionForClass: classIndex andSubclass: subclassIndex [ | ||
|
||
^ [ :anOldNode | | ||
| nodeCopy | | ||
nodeCopy := anOldNode copy. | ||
nodeCopy name: | ||
((classesToReplace at: classIndex) subclasses at: subclassIndex) | ||
name. | ||
nodeCopy ] | ||
] |
6 changes: 6 additions & 0 deletions
6
src/MuTalk-TestResources/MTAuxiliarClassForSubclassReplacementOperator.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarClassForSubclassReplacementOperator', | ||
#superclass : 'Object', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
6 changes: 6 additions & 0 deletions
6
src/MuTalk-TestResources/MTAuxiliarClassForSubclassReplacementWithManySubclasses.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarClassForSubclassReplacementWithManySubclasses', | ||
#superclass : 'Object', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
6 changes: 6 additions & 0 deletions
6
...MuTalk-TestResources/MTAuxiliarSubclass1ForSubclassReplacementWithManySubclasses.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarSubclass1ForSubclassReplacementWithManySubclasses', | ||
#superclass : 'MTAuxiliarClassForSubclassReplacementWithManySubclasses', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
6 changes: 6 additions & 0 deletions
6
...MuTalk-TestResources/MTAuxiliarSubclass2ForSubclassReplacementWithManySubclasses.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarSubclass2ForSubclassReplacementWithManySubclasses', | ||
#superclass : 'MTAuxiliarClassForSubclassReplacementWithManySubclasses', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
6 changes: 6 additions & 0 deletions
6
...MuTalk-TestResources/MTAuxiliarSubclass3ForSubclassReplacementWithManySubclasses.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarSubclass3ForSubclassReplacementWithManySubclasses', | ||
#superclass : 'MTAuxiliarClassForSubclassReplacementWithManySubclasses', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
6 changes: 6 additions & 0 deletions
6
src/MuTalk-TestResources/MTAuxiliarSubclassForSubclassReplacementOperator.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,6 @@ | ||
Class { | ||
#name : 'MTAuxiliarSubclassForSubclassReplacementOperator', | ||
#superclass : 'MTAuxiliarClassForSubclassReplacementOperator', | ||
#category : 'MuTalk-TestResources', | ||
#package : 'MuTalk-TestResources' | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh we are going to simplify this in our next pair programming session! ;)