Skip to content

Commit

Permalink
Refactoring and efficiency problem solved
Browse files Browse the repository at this point in the history
  • Loading branch information
carolahp committed Oct 23, 2023
1 parent b8320c5 commit 4adf107
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 62 deletions.
61 changes: 32 additions & 29 deletions src/NewTools-Scopes-Browser/ScopeScopeNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ Class {
ScopeScopeNode >> children [

| className class package orphanClasses fullPackages envPackages envClasses chldrn packageEnvironments classesEnvironments |


children ifNotNil: [ ^ children ].

self value isCompositeEnvironment ifTrue: [
chldrn := Set new.
envPackages := self value packages.
envClasses := self value classes.
"classes whose package hasn't all of its classes selected"
orphanClasses := envClasses select: [ :each |
| siblings |
siblings := each package definedClasses.
siblings anySatisfy: [ :sibling |
envClasses noneSatisfy: [ :selectedClass |
selectedClass = sibling ] ] ].
envClasses := self value classes reject: [:c | c isMeta ].

"packages whose classes were all selected"
fullPackages := envPackages select: [ :each |
each definedClasses noneSatisfy: [ :each1 |
orphanClasses anySatisfy: [ :orphan |
orphan = each1 ] ] ].
fullPackages := ScopesManager
fullPackagesIn: envPackages
having: envClasses.
"classes whose package hasn't all of its classes selected"

orphanClasses := ScopesManager
orphanClassesIn: envClasses
havingPackages: envPackages
fullPackages: fullPackages.

packageEnvironments := fullPackages collect: [ :thePackage |
ScopePackageNode on: thePackage ].
Expand All @@ -40,23 +40,26 @@ ScopeScopeNode >> children [
ifFalse: [ ScopeClassNode on: theClass ] ].
packageEnvironments do: [ :env | chldrn add: env ].
classesEnvironments do: [ :env | chldrn add: env ].
^ chldrn ].
^ children := chldrn ].

^ children := self value basisObjects collect: [ :stringOrPackage |
stringOrPackage isString
ifTrue: [
className := stringOrPackage.
class := self systemDictionary
at: className
ifAbsent: [ nil ].
class isTrait
ifTrue: [ ScopeTraitNode on: class ]
ifFalse: [ ScopeClassNode on: class ] ]
ifFalse: [
stringOrPackage isClassOrTrait
ifTrue: [ ScopeClassNode on: stringOrPackage ]
ifFalse: [
self assert: (stringOrPackage isKindOf: RPackage).
package := stringOrPackage.
ScopePackageNode on: package ] ] ].

^ self value basisObjects collect: [ :stringOrPackage |
stringOrPackage isString
ifTrue: [
className := stringOrPackage.
class := self systemDictionary at: className ifAbsent: [ nil ].
class isTrait
ifTrue: [ ScopeTraitNode on: class ]
ifFalse: [ ScopeClassNode on: class ] ]
ifFalse: [
stringOrPackage isClassOrTrait
ifTrue: [ ScopeClassNode on: stringOrPackage ]
ifFalse: [
self assert: (stringOrPackage isKindOf: RPackage).
package := stringOrPackage.
ScopePackageNode on: package ] ] ]
]

{ #category : 'testing' }
Expand Down
33 changes: 22 additions & 11 deletions src/NewTools-Scopes-Browser/ScopesPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ ScopesPresenter >> browseSelectedItem [
ScopesPresenter >> deleteSelectedScope [

| item selectedPath |
selectedPath := scopesTree selection selectedPath at: 1.
selectedPath == 1 ifTrue: [
self inform: 'You can''t delete this scope'.
^ self ].
item := scopesTree selectedItem.
(item isNil or: [ item isScopeNode not ]) ifTrue: [
self inform: 'select a scope'.
(item isNil or: [
item isScopeNode not or: [
(selectedPath := scopesTree selection selectedPath) isEmpty ] ])
ifTrue: [
self inform: 'select a scope'.
^ self ].

(selectedPath at: 1) == 1 ifTrue: [
self inform: 'You can''t delete this scope'.
^ self ].

model removeScope: item value.
Expand All @@ -159,10 +162,19 @@ ScopesPresenter >> deleteSelectedScope [
{ #category : 'menu commands' }
ScopesPresenter >> editSelectedScope [

| selectedPath |
(scopesTree selectedItem isNil or: [
scopesTree selectedItem isScopeNode not ])
ifTrue: [ self inform: 'select a scope' ]
ifFalse: [ self newScopeEditor open ]
scopesTree selectedItem isScopeNode not or: [
(selectedPath := scopesTree selection selectedPath) isEmpty ] ])
ifTrue: [
self inform: 'select a scope'.
^ self ].

(selectedPath at: 1) == 1 ifTrue: [
self inform: 'You can''t edit this scope'.
^ self ].

self newScopeEditor open
]

{ #category : 'initialization' }
Expand All @@ -188,7 +200,7 @@ ScopesPresenter >> initializeScopesTree [
^ scopesTree
hideColumnHeaders;
addColumn: self nodesListColumn;
children: [ :each | each children sorted ];
children: [ :each | each children asOrderedCollection ];
roots: self scopeNodes;
expandRoots;
collapsePath: #( 1 );
Expand Down Expand Up @@ -342,7 +354,6 @@ ScopesPresenter >> scopeListColumn [

{ #category : 'initialization' }
ScopesPresenter >> scopeNodes [

^ { (ScopeScopeNode on: model defaultScope) } asOrderedCollection
addAll: (model scopes collect: [ :s | ScopeScopeNode on: s ])
asOrderedCollection sorted;
Expand Down
68 changes: 46 additions & 22 deletions src/NewTools-Scopes/ScopesManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Class {
#instVars : [
'scopes',
'environment',
'announcer'
'announcer',
'defaultScope'
],
#classVars : [
'singleInstance'
Expand All @@ -28,11 +29,31 @@ ScopesManager class >> availableScopes [
^ self scopes
]

{ #category : 'private' }
ScopesManager class >> fullPackagesIn: packages having: classes [
"packages whose classes were all selected"

^ packages select: [ :package |
| packCheckedClasses |
packCheckedClasses := classes select: [ :class |
class package == package ].
package definedClasses size == packCheckedClasses size ]
]

{ #category : 'accessing' }
ScopesManager class >> invalidNames [
^ self scopes collect: [ :e | e label ]
]

{ #category : 'private' }
ScopesManager class >> orphanClassesIn: classes havingPackages: packages fullPackages: fullPackages [

| classesInFullPackages |
classesInFullPackages := fullPackages flatCollect: [ :package |
package definedClasses ].
^ classes reject: [ :class | classesInFullPackages includes: class ]
]

{ #category : 'accessing' }
ScopesManager class >> removeScope: aScope [
self singleInstance removeScope: aScope
Expand Down Expand Up @@ -80,8 +101,10 @@ ScopesManager >> announcer [
{ #category : 'api' }
ScopesManager >> defaultScope [

^ (self scopeClass packages: self allPackagesInEnvironment) label:
self defaultScopeLabel
^ defaultScope ifNil: [
defaultScope := (self scopeClass packages:
self allPackagesInEnvironment) label:
self defaultScopeLabel ]
]

{ #category : 'accessing' }
Expand All @@ -102,6 +125,11 @@ ScopesManager >> environment: aSmalltalkImage [
environment := aSmalltalkImage
]

{ #category : 'private' }
ScopesManager >> fullPackagesIn: packages having: classes [
^ self class fullPackagesIn: packages having: classes
]

{ #category : 'initialization' }
ScopesManager >> initialize [

Expand All @@ -113,37 +141,32 @@ ScopesManager >> initialize [
ScopesManager >> newScopeFrom: aSet [

| packageScope classScope classes packages orphanClasses fullPackages compositeScope |

classes := aSet select: [ :each | each isClassOrTrait ].
packages := aSet select: [ :each | each isKindOf: RPackage ].

"classes whose package hasn't all of its classes selected"
orphanClasses := classes select: [ :class |
| siblings |
siblings := class package definedClasses.
siblings anySatisfy: [ :sibling |
classes noneSatisfy: [ :selectedClass |
selectedClass = sibling ] ] ].

"packages whose classes were all selected"
fullPackages := packages select: [ :each |
each definedClasses noneSatisfy: [ :class |
orphanClasses anySatisfy: [ :orphan |
orphan = class ] ] ].

fullPackages := self class fullPackagesIn: packages having: classes.
"classes whose package hasn't all of its classes selected"
orphanClasses := self class
orphanClassesIn: classes
havingPackages: packages
fullPackages: fullPackages.

classScope := RBClassEnvironment classes: orphanClasses.
packageScope := RBPackageEnvironment packages: fullPackages.

self flag: 'hacer recursiva la construccion del composite scope'.
(classScope isNotEmpty and: [ packageScope isNotEmpty ]) ifTrue: [

(classScope isNotEmpty and: [ packageScope isNotEmpty ]) ifTrue: [
compositeScope := packageScope | classScope ].

compositeScope ifNotNil: [ ^ compositeScope ].
packageScope isEmpty ifFalse: [ ^ packageScope ].
classScope isEmpty ifFalse: [ ^ classScope ].
self error: 'Impossible to create scope from nodes'.
self error: 'Impossible to create scope from nodes'
]

{ #category : 'private' }
ScopesManager >> orphanClassesIn: classes havingPackages: packages fullPackages: fullPackages [
^ self class orphanClassesIn: classes havingPackages: packages fullPackages: fullPackages
]

{ #category : 'removing' }
Expand All @@ -158,6 +181,7 @@ ScopesManager >> reset [

environment := nil.
self announcer subscriptions reset.
defaultScope := nil.
scopes := #( )
]

Expand Down

0 comments on commit 4adf107

Please sign in to comment.