Skip to content
17 changes: 17 additions & 0 deletions src/Refactoring-Core-Tests/RBConditionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,20 @@ RBConditionTest >> testTrue [
self assert: RBCondition true check.
self deny: RBCondition true not check.
]

{ #category : 'tests' }
RBConditionTest >> testViolatorsForNegatedConditionAreCorrect [

| abstract concrete condition negation doubleNegation |
abstract := { TestCase . Number }.
concrete := { Object . Point }.

condition := ReClassesAreAbstractCondition new classes: abstract, concrete.
negation := condition not.
doubleNegation := negation not.

self assert: condition violators asSet equals: concrete asSet.
self assert: negation violators asSet equals: abstract asSet.
self assert: doubleNegation violators asSet equals: condition violators asSet

]
10 changes: 10 additions & 0 deletions src/Refactoring-Core/RBNewAbstractCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ RBNewAbstractCondition >> isTrue [
^ self check
]

{ #category : 'accessing' }
RBNewAbstractCondition >> nonViolators [
self subclassResponsibility
]

{ #category : 'logical operations' }
RBNewAbstractCondition >> not [
^ReNewNegationCondition on: self
Expand All @@ -53,6 +58,11 @@ RBNewAbstractCondition >> violationMessageOn: aStream [
self subclassResponsibility
]

{ #category : 'accessing' }
RBNewAbstractCondition >> violators [
self subclassResponsibility
]

{ #category : 'logical operations' }
RBNewAbstractCondition >> | aCondition [
"(A | B) = (A not & B not) not"
Expand Down
6 changes: 6 additions & 0 deletions src/Refactoring-Core/ReClassesCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ ReClassesCondition >> classes: aRBClassCollection [
classes := aRBClassCollection.
subjects := classes.
]

{ #category : 'accessing' }
ReClassesCondition >> nonViolators [

^ classes reject: [ :aClass | violators anySatisfy: [:each | each == aClass] ]
]
31 changes: 27 additions & 4 deletions src/Refactoring-Core/ReNewNegationCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ ReNewNegationCondition >> condition: aCondition [
{ #category : 'accessing' }
ReNewNegationCondition >> errorString [

^ condition errorString
^ String streamContents: [ :aStream |
self violationMessageOn: aStream ]
]

{ #category : 'accessing' }
ReNewNegationCondition >> nonViolators [
^ condition violators
]

{ #category : 'logical operations' }
ReNewNegationCondition >> not [
^ condition
]

{ #category : 'accessing' }
Expand All @@ -40,10 +51,22 @@ ReNewNegationCondition >> nonViolators [

{ #category : 'displaying' }
ReNewNegationCondition >> violationMessageOn: aWriteStream [
| method re message message2 |
"If my condition is a negation, return its condition violation message"
condition class == self class
ifTrue: [ ^ condition condition violationMessageOn: aWriteStream ].

"Otherwise, send the method defined in the condition to self.
In this way, violators return nonViolators"
method := condition class lookupSelector: #violationMessageOn:.
message := String streamContents: [:s |
method valueWithReceiver: self arguments: { s }].

aWriteStream
nextPutAll: 'NOT ';
nextPutAll: condition errorString
"Remove 'not' apparitions from the message"
re := '[ ]+not[ ]*' asRegex.
message2 := re copy: message contents replacingMatchesWith: ' '.
message2 == message ifTrue: [ message2 := 'NOT ' + message ].
aWriteStream nextPutAll: message2
]
Comment on lines 52 to 70
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks better, we should discuss it today


{ #category : 'accessing' }
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-Core/ReReifiedCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : 'ReReifiedCondition',
#superclass : 'RBCondition',
#instVars : [
'subjects'
'wrapper'
],
Comment on lines +4 to +6
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this got left over, should be removed right?

#category : 'Refactoring-Core-Conditions',
#package : 'Refactoring-Core',
Expand Down