Skip to content
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

Inline ClassOrganization>>classify:under: #13843

Merged
merged 6 commits into from May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/Fuel-Platform-Core/FLExtensionWrapper.class.st
Expand Up @@ -20,14 +20,12 @@ FLExtensionWrapper class >> fromPragma: aPragma [

{ #category : #private }
FLExtensionWrapper >> compileInTarget [

| source |
source := self method methodClass instanceSide
perform: self method selector
withArguments: (1 to: self method selector numArgs) asArray.
self targetClass compile: source.
self targetClass organization
classify: self selector
under: self extensionProtocolName
source := self method methodClass instanceSide perform: self method selector withArguments: (1 to: self method selector numArgs) asArray.
self targetClass
compile: source;
classify: self selector under: self extensionProtocolName
]

{ #category : #private }
Expand Down
9 changes: 3 additions & 6 deletions src/Fuel-Platform-Pharo-12/FLPharo12Platform.class.st
Expand Up @@ -86,12 +86,9 @@ FLPharo12Platform >> readStreamForFilePath: aString [

{ #category : #'accessing-compiler' }
FLPharo12Platform >> silentlyAddAndClassifySelector: aSymbol inClass: aClass withMethod: aCompiledMethod inProtocol: aString [
aClass
addSelector: aSymbol
withMethod: aCompiledMethod.
aClass organization
classify: aSymbol
under: aString

aClass addSelector: aSymbol withMethod: aCompiledMethod.
aClass classify: aSymbol under: aString
]

{ #category : #'accessing-kernel' }
Expand Down
Expand Up @@ -75,19 +75,19 @@ InitializePackagesCommandLineHandler >> initializePackagesFrom: aFileName [
{ #category : #activation }
InitializePackagesCommandLineHandler >> initializeProtocolsFrom: aFileName [

(File named: aFileName) readStreamDo: [:binaryStream | | stream |
(File named: aFileName) readStreamDo: [ :binaryStream |
| stream |
stream := ZnCharacterReadStream on: binaryStream encoding: 'utf8'.
[stream atEnd] whileFalse: [ | line items selector class |
[ stream atEnd ] whileFalse: [
| line items selector class |
line := stream upTo: Character cr.
items := line findTokens: String tab.
class := (items second = 'true')
ifTrue: [(Smalltalk classOrTraitNamed: items first) classSide]
ifFalse: [Smalltalk classOrTraitNamed: items first].
class := items second = 'true'
ifTrue: [ (Smalltalk classOrTraitNamed: items first) classSide ]
Copy link
Member

Choose a reason for hiding this comment

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

Cyril I know that this is not you but could we try self class environment instead of Smalltalk?

ifFalse: [ Smalltalk classOrTraitNamed: items first ].
selector := items third asSymbol.

class ifNil: [
self error: ('Could not found class: ', items first printString , ' for selector: ', selector printString) ].
class ifNil: [ self error: 'Could not found class: ' , items first printString , ' for selector: ' , selector printString ].

(class selectors includes: selector)
ifTrue: [class organization classify: selector under: items fourth]]]
(class selectors includes: selector) ifTrue: [ class classify: selector under: items fourth ] ] ]
]
98 changes: 96 additions & 2 deletions src/Kernel-Tests/ClassDescriptionProtocolsTest.class.st
Expand Up @@ -33,6 +33,100 @@ ClassDescriptionProtocolsTest >> tearDown [
super tearDown
]

{ #category : #tests }
ClassDescriptionProtocolsTest >> testClassifyUnder [

"Lets create a new protocol via classification"
class classify: #edalyn under: #which.
class classify: #luz under: #which.

self assertCollection: class protocolNames hasSameElements: #( #which ).
self assertCollection: (class selectorsInProtocol: #which) hasSameElements: #( #edalyn #luz ).

"Move a method"
class classify: #luz under: #human.
self assertCollection: class protocolNames hasSameElements: #( #human #which ).
self assertCollection: (class selectorsInProtocol: #which) hasSameElements: #( #edalyn ).
self assertCollection: (class selectorsInProtocol: #human) hasSameElements: #( #luz ).

"Move last method"
class classify: #edalyn under: #beast.
self assertCollection: class protocolNames hasSameElements: #( #human #beast ).
self assertCollection: (class selectorsInProtocol: #human) hasSameElements: #( #luz ).
self assertCollection: (class selectorsInProtocol: #beast) hasSameElements: #( #edalyn ).

"Nothing should change if the new protocol is the same than the old one"
class classify: #edalyn under: #beast.
self assertCollection: class protocolNames hasSameElements: #( #human #beast ).
self assertCollection: (class selectorsInProtocol: #human) hasSameElements: #( #luz ).
self assertCollection: (class selectorsInProtocol: #beast) hasSameElements: #( #edalyn )
]

{ #category : #tests }
ClassDescriptionProtocolsTest >> testClassifyUnderUnclassified [
"Ensure unclassified is acting as any other protocol because that was not the case in the past."

"Lets create a new protocol via classification"
class classify: #king under: Protocol unclassified.
class classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz ).

"This should do nothing."
class classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz ).

"Now we move a method from unclassified to another protocol."
class classify: #luz under: #human.

self assertCollection: class protocolNames hasSameElements: { #human. Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king ).

"Now we move back to unclassified."
class classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz )
]

{ #category : #tests }
ClassDescriptionProtocolsTest >> testClassifyUnderWithNil [
"Set the base for the test"
| unclassified|
unclassified := Protocol unclassified.

class classify: #king under: nil.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king ).

class classify: #luz under: #human.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified . #human }.
self assertCollection: (class selectorsInProtocol: #human) hasSameElements: #( #luz ).

"Now let's test the behavior if we already have a protocol.
The behavior should change to not change the protocol but this test will ensure that the change is intentional and not a regression."
class classify: #luz under: nil.

self assertCollection: class protocolNames hasSameElements: { Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz ).
]

{ #category : #tests }
ClassDescriptionProtocolsTest >> testClassifyUnderWithProtocol [

"Lets create a new protocol via classification"
class classify: #edalyn under: #which.
class classify: #luz under: (class protocolNamed: #which).

self assertCollection: class protocolNames hasSameElements: #( #which ).
self assertCollection: (class selectorsInProtocol: #which) hasSameElements: #( #edalyn #luz )
]

{ #category : #tests }
ClassDescriptionProtocolsTest >> testExtensionProtocols [

Expand Down Expand Up @@ -125,8 +219,8 @@ ClassDescriptionProtocolsTest >> testProtocolOfSelector [
{ #category : #tests }
ClassDescriptionProtocolsTest >> testRemoveFromProtocols [

class organization classify: #amity under: #witch.
class organization classify: #edalyn under: #witch.
class classify: #amity under: #witch.
class classify: #edalyn under: #witch.
self assert: (class hasProtocol: #witch).
self assertCollection: (class selectorsInProtocol: #witch) hasSameElements: #( #amity #edalyn ).

Expand Down
144 changes: 3 additions & 141 deletions src/Kernel-Tests/ClassOrganizationTest.class.st
Expand Up @@ -20,7 +20,7 @@ ClassOrganizationTest >> setUp [

organization addProtocol: 'empty'.
organization addProtocol: 'one'.
organization classify: #one under: 'one'
class classify: #one under: 'one'
]

{ #category : #tests }
Expand All @@ -31,144 +31,6 @@ ClassOrganizationTest >> testAddProtocol [
self assert: (class hasProtocol: 'test-protocol')
]

{ #category : #tests }
ClassOrganizationTest >> testClassifyUnder [
"Set the base for the test"

self assertCollection: class protocolNames hasSameElements: #( #empty #one ).

"Lets create a new protocol via classification"
organization classify: #king under: #owl.
organization classify: #luz under: #owl.

self assertCollection: class protocolNames hasSameElements: #( #empty #one #owl ).
self assertCollection: (class selectorsInProtocol: #owl) hasSameElements: #( #king #luz ).

"Move a method"
organization classify: #luz under: #one.
self assertCollection: class protocolNames hasSameElements: #( #empty #one #owl ).
self assertCollection: (class selectorsInProtocol: #owl) hasSameElements: #( #king ).
self assertCollection: (class selectorsInProtocol: #one) hasSameElements: #( #one #luz ).

"Move last method"
organization classify: #king under: #two.
self assertCollection: class protocolNames hasSameElements: #( #empty #one #two ).
self assertCollection: (class selectorsInProtocol: #one) hasSameElements: #( #one #luz ).
self assertCollection: (class selectorsInProtocol: #two) hasSameElements: #( #king ).

"Nothing should change if the new protocol is the same than the old one"
organization classify: #king under: #two.
self assertCollection: class protocolNames hasSameElements: #( #empty #one #two ).
self assertCollection: (class selectorsInProtocol: #one) hasSameElements: #( #one #luz ).
self assertCollection: (class selectorsInProtocol: #two) hasSameElements: #( #king )
]

{ #category : #tests }
ClassOrganizationTest >> testClassifyUnderUnclassified [
"Ensure unclassified is acting as any other protocol because that was not the case in the past."

"Set the base for the test"
self assertCollection: class protocolNames hasSameElements: #( #empty #one ).

"Lets create a new protocol via classification"
organization classify: #king under: Protocol unclassified.
organization classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: {#empty. #one. Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz ).

"This should do nothing."
organization classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: {#empty. #one. Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz ).

"Now we move a method from unclassified to another protocol."
organization classify: #luz under: #one.

self assertCollection: class protocolNames hasSameElements: {#empty. #one. Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king ).

"Now we move back to unclassified."
organization classify: #luz under: Protocol unclassified.

self assertCollection: class protocolNames hasSameElements: {#empty. #one. Protocol unclassified }.
self assertCollection: class uncategorizedSelectors hasSameElements: #( #king #luz )
]

{ #category : #tests }
ClassOrganizationTest >> testClassifyUnderWithNil [
"Set the base for the test"
| unclassified|
unclassified := Protocol unclassified.
self assertCollection: class protocolNames hasSameElements: #( #empty #one ).

organization classify: #king under: nil.

self assertCollection: class protocolNames hasSameElements: { #empty. #one. unclassified }.
self assertCollection: (class selectorsInProtocol: unclassified) hasSameElements: #( #king ).

organization classify: #luz under: #owl.

self assertCollection: class protocolNames hasSameElements: { #empty. #one. unclassified . #owl }.
self assertCollection: (class selectorsInProtocol: #owl) hasSameElements: #( #luz ).

"Now let's test the behavior if we already have a protocol.
The behavior should change to not change the protocol but this test will ensure that the change is intentional and not a regression."
organization classify: #luz under: nil.

self assertCollection: class protocolNames hasSameElements: { #empty. #one. unclassified }.
self assertCollection: (class selectorsInProtocol: unclassified) hasSameElements: #( #king #luz ).
]

{ #category : #tests }
ClassOrganizationTest >> testClassifyUnderWithProtocol [
"Set the base for the test"

self assertCollection: class protocolNames hasSameElements: #( #empty #one ).

"Lets create a new protocol via classification"
organization classify: #king under: #owl.
organization classify: #luz under: (class protocolNamed: #owl).

self assertCollection: class protocolNames hasSameElements: #( #empty #one #owl ).
self assertCollection: (class selectorsInProtocol: #owl) hasSameElements: #( #king #luz )
]

{ #category : #tests }
ClassOrganizationTest >> testCopyFrom [

| newOrganization |
"First lets check the current state of the org."
self assertCollection: class protocolNames hasSameElements: #( 'empty' 'one' ).
self assertCollection: (class selectorsInProtocol: #one) hasSameElements: #( 'one' ).
self assertEmpty: (class selectorsInProtocol: #empty).

"Now lets check that the new org has the same"
newOrganization := ClassOrganization new
setSubject: organization organizedClass;
copyFrom: organization;
yourself.

self assertCollection: newOrganization organizedClass protocolNames hasSameElements: #( 'empty' 'one' ).
self assertCollection: (newOrganization protocols detect: [ :protocol | protocol name = #one ]) methodSelectors hasSameElements: #( 'one' ).
self assertEmpty: (newOrganization protocols detect: [ :protocol | protocol name = #empty ]) methodSelectors.

"And now lets check that updating one does not update the other."
organization addProtocol: 'two'.
newOrganization classify: 'new' under: 'init'.

self assertCollection: class protocolNames hasSameElements: #( 'empty' 'one' 'two' ).
self assertCollection: (class selectorsInProtocol: #one) hasSameElements: #( 'one' ).
self assertEmpty: (class selectorsInProtocol: #empty).
self assertEmpty: (class selectorsInProtocol: #two).

self assertCollection: (newOrganization protocols collect: #name) hasSameElements: #( 'empty' 'one' 'init' ).
self assertCollection: (newOrganization protocols detect: [ :protocol | protocol name = #one ]) methodSelectors hasSameElements: #( 'one' ).
self assertEmpty: (newOrganization protocols detect: [ :protocol | protocol name = #empty ]) methodSelectors.
self assertCollection: (newOrganization protocols detect: [ :protocol | protocol name = #init ]) methodSelectors hasSameElements: #( 'new' )
]

{ #category : #tests }
ClassOrganizationTest >> testRenameProtocolAs [

Expand All @@ -185,7 +47,7 @@ ClassOrganizationTest >> testRenameProtocolAs [
{ #category : #tests }
ClassOrganizationTest >> testRenameProtocolAsWithExistingProtocol [

organization classify: 'king' under: 'two'.
class classify: 'king' under: 'two'.

self assert: (class hasProtocol: #one).
self assert: (class hasProtocol: #two).
Expand All @@ -202,7 +64,7 @@ ClassOrganizationTest >> testRenameProtocolAsWithExistingProtocol [
ClassOrganizationTest >> testRenameProtocolAsWithExistingProtocolWithProtocol [

| one two |
organization classify: 'king' under: 'two'.
class classify: 'king' under: 'two'.

one := class protocolNamed: #one.
two := class protocolNamed: #two.
Expand Down
6 changes: 3 additions & 3 deletions src/Kernel-Tests/ProtocolAnnouncementsTest.class.st
Expand Up @@ -59,7 +59,7 @@ ProtocolAnnouncementsTest >> testClassifyUnderAnnounceNewProtocol [

self when: ClassReorganized do: [ :ann | self assert: ann classReorganized name equals: self classNameForTests ].

organization classify: #king under: #titan.
class classify: #king under: #titan.
self assert: numberOfAnnouncements equals: 2
]

Expand Down Expand Up @@ -175,7 +175,7 @@ ProtocolAnnouncementsTest >> testRemoveProtocolIfEmptyWithNonExistingProtocolDoe
ProtocolAnnouncementsTest >> testRenameProtocolAsAnnounceClassReorganizedOnce [
"This is a regerssion test because at some point the class reorganized announcement got duplicated."

organization classify: #king under: #demon.
class classify: #king under: #demon.

self when: ClassReorganized do: [ :ann | self assert: ann classReorganized name equals: self classNameForTests ].

Expand All @@ -190,7 +190,7 @@ ProtocolAnnouncementsTest >> testRenameProtocolAsAnnounceNewProtocol [
self skip. "This hihglight the problem of https://github.com/pharo-project/pharo/pull/13494
But we still need to work on this to fix this test."

organization classify: #king under: #demon.
class classify: #king under: #demon.

self when: ProtocolAdded do: [ :ann |
self assert: ann protocol name equals: #titan.
Expand Down