Skip to content

Commit

Permalink
Use #includesBehavior: instead of testing manually for class identity…
Browse files Browse the repository at this point in the history
… or inheritance
  • Loading branch information
gcotelli committed Jul 15, 2019
1 parent 70b47c5 commit 4653143
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 60 deletions.
3 changes: 1 addition & 2 deletions src/Announcements-Core/Announcement.class.st
Expand Up @@ -37,8 +37,7 @@ Announcement class >> asAnnouncement [
Announcement class >> handlesAnnouncement: anAnnouncement [
"The receiver acts as a filter to determine whether subscribers who used the receiver as signaling tag (event identifier class or symbol) should receive incoming announcement. In particular, registering to a superclass will receive the announcements from all subclasses."


^ anAnnouncement class == self or: [ anAnnouncement class inheritsFrom: self ]
^ anAnnouncement class includesBehavior: self
]

{ #category : #converting }
Expand Down
Expand Up @@ -11,14 +11,11 @@ Class {

{ #category : #testing }
ClyInheritanceAnalysisMethodQuery >> isFromScopeWithClassKindOf: aClass [

scope classesDo: [ :each |
(each == aClass or: [each inheritsFrom: aClass])
ifTrue: [^true]].

^false


scope
classesDo: [ :each |
(each includesBehavior: aClass)
ifTrue: [ ^ true ] ].
^ false
]

{ #category : #testing }
Expand Down
2 changes: 1 addition & 1 deletion src/Epicea/EpEvent.class.st
Expand Up @@ -11,7 +11,7 @@ Class {
EpEvent class >> handlesAnnouncement: anAnnouncement [
"The receiver acts as a filter to determine whether subscribers who used the receiver as signaling tag (event identifier class or symbol) should receive incoming announcement. In particular, registering to a superclass will receive the announcements from all subclasses."

^ anAnnouncement class == self or: [ anAnnouncement class inheritsFrom: self ]
^ anAnnouncement class includesBehavior: self
]

{ #category : #visitor }
Expand Down
17 changes: 8 additions & 9 deletions src/Kernel/Context.class.st
Expand Up @@ -1187,15 +1187,14 @@ Context >> object: anObject perform: selector withArguments: argArray inClass: l
Primitive. Essential for the debugger."

<primitive: 100 error: error>
(selector isSymbol) ifFalse:
[^self error: 'selector argument must be a Symbol'].
(argArray isMemberOf: Array) ifFalse:
[^self error: 'argArray must be an Array'].
(selector numArgs = argArray size)
ifFalse: [^self error: 'incorrect number of arguments'].
((self objectClass: anObject) == lookupClass
or: [(self objectClass: anObject) inheritsFrom: lookupClass]) ifFalse:
[^self error: 'lookupClass is not in anObject''s inheritance chain'].
selector isSymbol
ifFalse: [ ^ self error: 'selector argument must be a Symbol' ].
(argArray isMemberOf: Array)
ifFalse: [ ^ self error: 'argArray must be an Array' ].
selector numArgs = argArray size
ifFalse: [ ^ self error: 'incorrect number of arguments' ].
((self objectClass: anObject) includesBehavior: lookupClass)
ifFalse: [ ^ self error: 'lookupClass is not in anObject''s inheritance chain' ].
self primitiveFailed
]

Expand Down
14 changes: 7 additions & 7 deletions src/Kernel/Object.class.st
Expand Up @@ -1676,15 +1676,15 @@ Object >> perform: selector withArguments: argArray inSuperclass: lookupClass [
but with the supplied superclass instead. It will fail if lookupClass
cannot be found among the receiver's superclasses.
Primitive. Essential. See Object documentation whatIsAPrimitive."

<reflective: #object:performMessageInSuperclass:>
<primitive: 100>
(selector isSymbol)
ifFalse: [^ self error: 'selector argument must be a Symbol'].
(selector numArgs = argArray size)
ifFalse: [^ self error: 'incorrect number of arguments'].
(self class == lookupClass or: [self class inheritsFrom: lookupClass])
ifFalse: [^ self error: 'lookupClass is not in my inheritance chain'].
selector isSymbol
ifFalse: [ ^ self error: 'selector argument must be a Symbol' ].
selector numArgs = argArray size
ifFalse: [ ^ self error: 'incorrect number of arguments' ].
(self class includesBehavior: lookupClass)
ifFalse: [ ^ self error: 'lookupClass is not in my inheritance chain' ].
self primitiveFailed
]

Expand Down
38 changes: 19 additions & 19 deletions src/Metacello-Core/MetacelloProjectRegistration.class.st
Expand Up @@ -47,25 +47,25 @@ MetacelloProjectRegistration class >> classRemoved: aClassRemovalAnnouncement [

{ #category : #accessing }
MetacelloProjectRegistration class >> configurationClasses [
"Return a set of the Metacello configuration classes that have been loaded into the image."

"self configurationClasses"

| answer |
answer := IdentitySet new.
ConfigurationOf allSubclasses
do: [ :cl |
(cl == BaselineOf or: [ cl inheritsFrom: BaselineOf ])
ifFalse: [ answer add: cl ] ].
Object allSubclasses
do: [ :cl |
(answer includes: cl)
ifFalse: [
(([ cl isMetacelloConfig ]
on: Error
do: [ :ex | ex return: false ]) and: [ cl name asString beginsWith: 'ConfigurationOf' ])
ifTrue: [ answer add: cl ] ] ].
^ answer
"Return a set of the Metacello configuration classes that have been loaded into the image."

"self configurationClasses"

| answer |
answer := IdentitySet new.
ConfigurationOf allSubclasses
do: [ :cl |
(cl includesBehavior: BaselineOf)
ifFalse: [ answer add: cl ] ].
Object allSubclasses
do: [ :cl |
(answer includes: cl)
ifFalse: [ (([ cl isMetacelloConfig ]
on: Error
do: [ :ex | ex return: false ])
and: [ cl name asString beginsWith: 'ConfigurationOf' ])
ifTrue: [ answer add: cl ] ] ].
^ answer
]

{ #category : #accessing }
Expand Down
15 changes: 8 additions & 7 deletions src/ReflectionMirrors-Primitives/MirrorPrimitives.class.st
Expand Up @@ -260,15 +260,16 @@ MirrorPrimitives class >> withReceiver: receiver perform: selector withArguments
the message lookup process begins, not with the receivers's class,
but with the supplied superclass instead. It will fail if lookupClass
cannot be found among the receiver's superclasses"

<primitive: 100 error: error>
(selector isSymbol)
ifFalse: [^ self error: 'selector argument must be a Symbol'].
((self classOf: argArray) == Array) ifFalse:
[^self error: 'argArray must be an Array'].
selector isSymbol
ifFalse: [ ^ self error: 'selector argument must be a Symbol' ].
(self classOf: argArray) == Array
ifFalse: [ ^ self error: 'argArray must be an Array' ].
(selector numArgs = self indexableSizeOf: argArray)
ifFalse: [^ self error: 'incorrect number of arguments'].
((self classOf: receiver) == lookupClass or: [(self classOf: receiver) inheritsFrom: lookupClass])
ifFalse: [^ self error: 'lookupClass is not in my inheritance chain'].
ifFalse: [ ^ self error: 'incorrect number of arguments' ].
((self classOf: receiver) includesBehavior: lookupClass)
ifFalse: [ ^ self error: 'lookupClass is not in my inheritance chain' ].
self primitiveFailed
]

Expand Down
7 changes: 5 additions & 2 deletions src/SmartSuggestions/SugsSuggestion.class.st
Expand Up @@ -35,8 +35,11 @@ SugsSuggestion class >> nodes [
SugsSuggestion class >> subclassesForNode: aClass [
"all menu defitions define in which ast nodes they are interested by defining #nodes.
Subclass relationship is taken into account"
^self allSubclasses select: [:suggestionClass |
suggestionClass nodes anySatisfy: [:class | aClass == class or: [aClass inheritsFrom: class]]]

^ self allSubclasses
select: [ :suggestionClass |
suggestionClass nodes
anySatisfy: [ :class | aClass includesBehavior: class ] ]
]

{ #category : #comparing }
Expand Down
8 changes: 3 additions & 5 deletions src/UnifiedFFI/FFICallout.class.st
Expand Up @@ -386,18 +386,16 @@ FFICallout >> resolveType: aTypeName [
{ #category : #'spec parsing' }
FFICallout >> returnType: aType [
aType first = 'receiver'
ifTrue: [
| rcvr rqstr |
ifTrue: [ | rcvr rqstr |
"check that:
1. method belongs to class side
2. method class is subclass of NBExternalObject
3. receiver is the same or subclass of the requestor -- since the requestor is the implementor"
rcvr := self receiver.
rqstr := self requestor soleInstance.
(rcvr isBehavior
and: [ (rcvr == rqstr or: [ rcvr inheritsFrom: rqstr ]) ])
(rcvr isBehavior and: [ rcvr includesBehavior: rqstr ])
ifTrue: [ ^ self typeName: rcvr name pointerArity: aType second ] ].
self receiver: nil. "if the type is not 'receiver' then we don't need the receiver of the message so set it to nil"
self receiver: nil. "if the type is not 'receiver' then we don't need the receiver of the message so set it to nil"
^ self typeName: aType first pointerArity: aType second
]

Expand Down

0 comments on commit 4653143

Please sign in to comment.