Skip to content

Commit aee676f

Browse files
authored
Merge pull request #75 from DurieuxPol/feat/newOps
Subclass replacement operator
2 parents 7b19d75 + 7b3307a commit aee676f

File tree

107 files changed

+1426
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1426
-670
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
Class {
2+
#name : 'MTAbstractMutantOperator',
3+
#superclass : 'Object',
4+
#category : 'MuTalk-Model-Operators',
5+
#package : 'MuTalk-Model',
6+
#tag : 'Operators'
7+
}
8+
9+
{ #category : 'accessing' }
10+
MTAbstractMutantOperator class >> allConcreteSubclasses [
11+
12+
^ self allSubclasses reject: [ :ea |
13+
ea isAbstract | ea isOriginalOperator not ]
14+
]
15+
16+
{ #category : 'accessing' }
17+
MTAbstractMutantOperator class >> contents [
18+
"This returns only the traditional operators "
19+
20+
^ ((self allConcreteSubclasses reject: #isDeprecated) collect: [
21+
:class | class new ]) asSortedCollection: [ :elem1 :elem2 |
22+
elem1 description <= elem2 description ]
23+
]
24+
25+
{ #category : 'accessing' }
26+
MTAbstractMutantOperator class >> contentsAll [
27+
"This returns all operators (block based and traditional) "
28+
29+
^ ((self allSubclasses reject: [ :ea |
30+
ea isAbstract or: [ ea isDeprecated ] ]) collect: [ :class |
31+
class new ]) asSortedCollection: [ :elem1 :elem2 |
32+
elem1 description <= elem2 description ]
33+
]
34+
35+
{ #category : 'testing' }
36+
MTAbstractMutantOperator class >> isAbstract [
37+
38+
^ self == MTAbstractMutantOperator
39+
]
40+
41+
{ #category : 'testing' }
42+
MTAbstractMutantOperator class >> isOriginalOperator [
43+
44+
^ true
45+
]
46+
47+
{ #category : 'as yet unclassified' }
48+
MTAbstractMutantOperator class >> recursionsDetectionStatement [
49+
50+
^ RBParser parseExpression:
51+
('MuTalkInfiniteRecursionError onCount: {1}' format: { self recursionsDetectionThreshold } )
52+
]
53+
54+
{ #category : 'as yet unclassified' }
55+
MTAbstractMutantOperator class >> recursionsDetectionThreshold [
56+
57+
"We need a big enough number"
58+
59+
^ 1024
60+
]
61+
62+
{ #category : 'printing' }
63+
MTAbstractMutantOperator >> description [
64+
self subclassResponsibility
65+
]
66+
67+
{ #category : 'private' }
68+
MTAbstractMutantOperator >> is: originalRBMethodNode equalTo: nodeThatMatches [
69+
^ nodeThatMatches formattedCode = originalRBMethodNode formattedCode
70+
]
71+
72+
{ #category : 'private' }
73+
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod number: aNumber [
74+
75+
^ self
76+
modifiedSourceFor: aCompiledMethod
77+
with: aCompiledMethod parseTree
78+
number: aNumber
79+
newExpression: self newExpression
80+
]
81+
82+
{ #category : 'private' }
83+
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod number: aNumber newExpression: anExpression [
84+
85+
^ self
86+
modifiedSourceFor: aCompiledMethod
87+
with: aCompiledMethod parseTree
88+
number: aNumber
89+
newExpression: anExpression
90+
]
91+
92+
{ #category : 'private' }
93+
MTAbstractMutantOperator >> modifiedSourceFor: aCompiledMethod with: aParseTree number: aNumber newExpression: anExpression [
94+
95+
self subclassResponsibility
96+
]
97+
98+
{ #category : 'mutant generation' }
99+
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod [
100+
101+
(aCompiledMethod ignoredMutationOperators includes: self class) ifTrue: [ ^ Array new ].
102+
103+
^self mutationsFor: aCompiledMethod with: aCompiledMethod parseTree.
104+
105+
]
106+
107+
{ #category : 'mutant generation' }
108+
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod with: aParseTree [
109+
110+
| numberOfAffectedNodes |
111+
((aCompiledMethod hasPragmaNamed: #ignoreForMutations) or: [
112+
aCompiledMethod hasPragmaNamed: #ignoreForCoverage ]) ifTrue: [
113+
^ #( ) ].
114+
115+
numberOfAffectedNodes := self
116+
timesToApplyIn: aCompiledMethod
117+
with: aParseTree.
118+
^ (1 to: numberOfAffectedNodes)
119+
inject: OrderedCollection new
120+
into: [ :accumulator :nodeIndex |
121+
self
122+
mutationsFor: aCompiledMethod
123+
with: aParseTree
124+
number: nodeIndex
125+
storeIn: accumulator ]
126+
]
127+
128+
{ #category : 'private' }
129+
MTAbstractMutantOperator >> mutationsFor: aCompiledMethod with: aParseTree number: nodeIndex storeIn: accumulator [
130+
131+
self subclassResponsibility
132+
]
133+
134+
{ #category : 'suggestions' }
135+
MTAbstractMutantOperator >> suggestionFor: aMutation using: aMutantKillingSuggestionGenerator [
136+
^'No Suggestion'
137+
]
138+
139+
{ #category : 'applying' }
140+
MTAbstractMutantOperator >> timesToApplyIn: aCompiledMethod [
141+
^self timesToApplyIn: aCompiledMethod with: aCompiledMethod parseTree.
142+
143+
]
144+
145+
{ #category : 'applying' }
146+
MTAbstractMutantOperator >> timesToApplyIn: aCompiledMethod with: aParseTree [
147+
148+
self subclassResponsibility
149+
]

src/MuTalk-Model/MTAnalysis.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ MTAnalysis >> defaultMutantSelectionStrategy [
483483
{ #category : 'accessing - defaults' }
484484
MTAnalysis >> defaultOperators [
485485

486-
^ MTMutantOperator contents
486+
^ MTAbstractMutantOperator contents
487487
]
488488

489489
{ #category : 'accessing - defaults' }
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
Class {
22
#name : 'MTAssignmentNullifierOperator',
3-
#superclass : 'MTBlockBasedMutantOperator',
3+
#superclass : 'MTPredicateBasedMutantOperator',
44
#category : 'MuTalk-Model-Operators',
55
#package : 'MuTalk-Model',
66
#tag : 'Operators'
77
}
88

9+
{ #category : 'applying' }
10+
MTAssignmentNullifierOperator >> appliesToNode: aNode [
11+
12+
^ aNode isAssignment & aNode value isNotNil
13+
]
14+
915
{ #category : 'printing' }
1016
MTAssignmentNullifierOperator >> description [
1117

1218
^ 'Nullify the value assigned'
1319
]
1420

1521
{ #category : 'applying' }
16-
MTAssignmentNullifierOperator >> expressionToReplace [
17-
18-
^ [ :aNode | aNode isAssignment & aNode value isNotNil ]
19-
]
20-
21-
{ #category : 'applying' }
22-
MTAssignmentNullifierOperator >> newExpression [
22+
MTAssignmentNullifierOperator >> newNodeFrom: anOldNode [
2323

24-
^ [ :anOldNode |
25-
| nodeCopy |
26-
nodeCopy := anOldNode copy.
27-
nodeCopy value: (RBLiteralValueNode value: nil).
28-
nodeCopy ]
24+
| nodeCopy |
25+
nodeCopy := anOldNode copy.
26+
nodeCopy value: (RBLiteralValueNode value: nil).
27+
^ nodeCopy
2928
]

src/MuTalk-Model/MTBlockBasedMutantOperator.class.st

-61
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
Class {
22
#name : 'MTEmptyMethodOperator',
3-
#superclass : 'MTBlockBasedMutantOperator',
3+
#superclass : 'MTPredicateBasedMutantOperator',
44
#category : 'MuTalk-Model-Operators',
55
#package : 'MuTalk-Model',
66
#tag : 'Operators'
77
}
88

9-
{ #category : 'printing' }
10-
MTEmptyMethodOperator >> description [
9+
{ #category : 'applying' }
10+
MTEmptyMethodOperator >> appliesToNode: aNode [
1111

12-
^ 'Removing all lines in a method'
12+
^ aNode isSequence and: [ aNode parent isMethod ]
1313
]
1414

15-
{ #category : 'applying' }
16-
MTEmptyMethodOperator >> expressionToReplace [
15+
{ #category : 'printing' }
16+
MTEmptyMethodOperator >> description [
1717

18-
^ [ :aNode |
19-
aNode isSequence and: [ aNode parent isMethod] ]
18+
^ 'Removing all lines in a method'
2019
]
2120

2221
{ #category : 'applying' }
23-
MTEmptyMethodOperator >> newExpression [
22+
MTEmptyMethodOperator >> newNodeFrom: anOldNode [
2423

25-
^ [ :anOldNode | RBSequenceNode statements: #() ]
24+
^ RBSequenceNode statements: #( )
2625
]
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
Class {
22
#name : 'MTLiteralBooleanNegateOperator',
3-
#superclass : 'MTBlockBasedMutantOperator',
3+
#superclass : 'MTPredicateBasedMutantOperator',
44
#category : 'MuTalk-Model-Operators',
55
#package : 'MuTalk-Model',
66
#tag : 'Operators'
77
}
88

9-
{ #category : 'printing' }
10-
MTLiteralBooleanNegateOperator >> description [
9+
{ #category : 'applying' }
10+
MTLiteralBooleanNegateOperator >> appliesToNode: aNode [
1111

12-
^ 'Negate a literal boolean'
12+
^ aNode isLiteralNode & aNode isLiteralArray not and: [
13+
{ true. false } includes: aNode value ]
1314
]
1415

15-
{ #category : 'applying' }
16-
MTLiteralBooleanNegateOperator >> expressionToReplace [
16+
{ #category : 'printing' }
17+
MTLiteralBooleanNegateOperator >> description [
1718

18-
^ [ :aNode |
19-
aNode isLiteralNode & aNode isLiteralArray not and: [
20-
{ true. false } includes: aNode value ] ]
19+
^ 'Negate a literal boolean'
2120
]
2221

2322
{ #category : 'applying' }
24-
MTLiteralBooleanNegateOperator >> newExpression [
23+
MTLiteralBooleanNegateOperator >> newNodeFrom: anOldNode [
2524

26-
^ [ :anOldNode | RBLiteralValueNode value: anOldNode value not ]
25+
^ RBLiteralValueNode value: anOldNode value not
2726
]
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
Class {
22
#name : 'MTLiteralIntegersDecreaseOperator',
3-
#superclass : 'MTBlockBasedMutantOperator',
3+
#superclass : 'MTPredicateBasedMutantOperator',
44
#category : 'MuTalk-Model-Operators',
55
#package : 'MuTalk-Model',
66
#tag : 'Operators'
77
}
88

9-
{ #category : 'printing' }
10-
MTLiteralIntegersDecreaseOperator >> description [
9+
{ #category : 'applying' }
10+
MTLiteralIntegersDecreaseOperator >> appliesToNode: aNode [
1111

12-
^ 'Decrease a literal integer'
12+
^ aNode isLiteralNode & aNode isLiteralArray not and: [
13+
aNode value isInteger ]
1314
]
1415

15-
{ #category : 'applying' }
16-
MTLiteralIntegersDecreaseOperator >> expressionToReplace [
16+
{ #category : 'printing' }
17+
MTLiteralIntegersDecreaseOperator >> description [
1718

18-
^ [ :aNode | aNode isLiteralNode & aNode isLiteralArray not and: [ aNode value isInteger ] ]
19+
^ 'Decrease a literal integer'
1920
]
2021

2122
{ #category : 'applying' }
22-
MTLiteralIntegersDecreaseOperator >> newExpression [
23+
MTLiteralIntegersDecreaseOperator >> newNodeFrom: anOldNode [
2324

24-
^ [ :anOldNode | RBLiteralValueNode value: anOldNode value - 1 ]
25+
^ RBLiteralValueNode value: anOldNode value - 1
2526
]

0 commit comments

Comments
 (0)