Skip to content

Commit

Permalink
Add methods for global management in LanguagePlatform (#133)
Browse files Browse the repository at this point in the history
* Add to LanguagePlatform globalNamedïfAbsentPut: and removeGlobalNamed:ifAbsent:
* Add system icons
* Avoid translation rule search in critics
  • Loading branch information
gcotelli authored Nov 22, 2024
1 parent b9998a7 commit dcd3de1
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : 'CircularIterator' }

{ #category : '*Buoy-Development-Tools-Pharo-12' }
CircularIterator class >> systemIconName [

^ #collection
]
7 changes: 7 additions & 0 deletions source/Buoy-Development-Tools-Pharo-12/Formatter.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : 'Formatter' }

{ #category : '*Buoy-Development-Tools-Pharo-12' }
Formatter class >> systemIconName [

^ #string
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ SearchMethodsForLocalizationMessagesRule class >> collectingTranslationsIn: aCol
^ self new initializeCollectingTranslationsIn: aCollection
]

{ #category : 'testing' }
SearchMethodsForLocalizationMessagesRule class >> isVisible [

^ false
]

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

super initialize.
stringsToTranslate := OrderedCollection new.
matcher
matches: '`#string localized'
do: [ :node :answer | stringsToTranslate add: node receiver value ];
Expand Down
12 changes: 12 additions & 0 deletions source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ LanguagePlatform >> globalNamed: aSymbol ifAbsent: absentBlock [
^ self subclassResponsibility
]

{ #category : 'reflection' }
LanguagePlatform >> globalNamed: symbol ifAbsentPut: block [

^ self subclassResponsibility
]

{ #category : 'reflection' }
LanguagePlatform >> globalNamed: aSymbol ifPresent: presentBlock ifAbsent: absentBlock [

Expand Down Expand Up @@ -75,3 +81,9 @@ LanguagePlatform >> os [

^ self subclassResponsibility
]

{ #category : 'reflection' }
LanguagePlatform >> removeGlobalNamed: aSymbol ifAbsent: absentBlock [

^ self subclassResponsibility
]
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
Class {
#name : 'GemStone64Platform',
#superclass : 'LanguagePlatform',
#category : 'Buoy-Metaprogramming-GS64-Extensions',
#package : 'Buoy-Metaprogramming-GS64-Extensions'
#name : 'GemStone64Platform',
#superclass : 'LanguagePlatform',
#category : 'Buoy-Metaprogramming-GS64-Extensions',
#package : 'Buoy-Metaprogramming-GS64-Extensions'
}

{ #category : 'class initialization' }
GemStone64Platform class >> initialize [

LanguagePlatform setCurrentTo: self new
LanguagePlatform setCurrentTo: self new
]

{ #category : 'reflection' }
GemStone64Platform >> atInstanceVariableNamed: name on: object put: value [

| index |
index := (object class allInstVarNames collect: #asSymbol)
indexOf: name asSymbol
ifAbsent: [ self error: ('<1s> not found in <2p>' expandMacrosWith: name asString with: object) ].
object instVarAt: index put: value
| index |
index := (object class allInstVarNames collect: #asSymbol)
indexOf: name asSymbol
ifAbsent: [ self error: ('<1s> not found in <2p>' expandMacrosWith: name asString with: object) ].
object instVarAt: index put: value

]

{ #category : 'process scheduling' }
GemStone64Platform >> fork: block named: processName at: priority [

| process |
process := self newProcessNamed: processName evaluating: block at: priority.
process resume.
Processor yield.
^process
| process |
process := self newProcessNamed: processName evaluating: block at: priority.
process resume.
Processor yield.
^process
]

{ #category : 'process scheduling' }
Expand All @@ -45,15 +45,28 @@ GemStone64Platform >> newProcessNamed: processName evaluating: block at: priorit
{ #category : 'reflection' }
GemStone64Platform >> globalNamed: aSymbol ifAbsent: absentBlock [

^ (GsCurrentSession currentSession symbolList objectNamed: aSymbol)
ifNil: absentBlock
^ (GsCurrentSession currentSession objectNamed: aSymbol)
ifNil: absentBlock
]

{ #category : 'reflection' }
GemStone64Platform >> globalNamed: symbol ifAbsentPut: block [

^ (GsCurrentSession currentSession objectNamed: symbol)
ifNil: [
| object |
object := block value.
(GsCurrentSession currentSession objectNamed: #Globals)
at: symbol put: object.
object
]
]

{ #category : 'reflection' }
GemStone64Platform >> includesGlobalNamed: aSymbol [

^ (GsCurrentSession currentSession symbolList objectNamed: aSymbol)
notNil
^ (GsCurrentSession currentSession objectNamed: aSymbol)
notNil
]

{ #category : 'message digest' }
Expand All @@ -65,5 +78,13 @@ GemStone64Platform >> messageDigest: string [
{ #category : 'accessing' }
GemStone64Platform >> os [

^ GemStone64UnixPlatform current
^ GemStone64UnixPlatform current
]

{ #category : 'reflection' }
GemStone64Platform >> removeGlobalNamed: aSymbol ifAbsent: absentBlock [

| globals |
globals := GsCurrentSession currentSession objectNamed: #Globals.
^ globals removeKey: aSymbol ifAbsent: absentBlock
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ PharoPlatform >> globalNamed: aSymbol ifAbsent: absentBlock [
^ Smalltalk globals at: aSymbol ifAbsent: absentBlock
]

{ #category : 'reflection' }
PharoPlatform >> globalNamed: symbol ifAbsentPut: block [

^ Smalltalk globals at: symbol ifAbsentPut: block
]

{ #category : 'reflection' }
PharoPlatform >> includesGlobalNamed: aSymbol [

Expand All @@ -56,3 +62,9 @@ PharoPlatform >> os [

^ OSPlatform current
]

{ #category : 'reflection' }
PharoPlatform >> removeGlobalNamed: aSymbol ifAbsent: absentBlock [

^ Smalltalk globals removeKey: aSymbol ifAbsent: absentBlock
]
32 changes: 32 additions & 0 deletions source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ LanguagePlatformTest >> testGlobalNamedIfAbsent [
identicalTo: sentinel
]

{ #category : 'tests' }
LanguagePlatformTest >> testGlobalNamedIfAbsentPut [

| globalName globalValue sentinel |
globalName := #TestGlobalNamedIfAbsentPut.
globalValue := Object new.

LanguagePlatform current globalNamed: globalName ifAbsentPut: globalValue.

self
assert: ( LanguagePlatform current globalNamed: globalName ifAbsent: [ self fail ] )
identicalTo: globalValue.

LanguagePlatform current removeGlobalNamed: globalName ifAbsent: [ self fail ].

sentinel := Object new.
self
assert: ( LanguagePlatform current globalNamed: globalName ifAbsent: [ sentinel ] )
identicalTo: sentinel
]

{ #category : 'tests' }
LanguagePlatformTest >> testGlobalNamedIfPresentIfAbsent [

Expand Down Expand Up @@ -161,3 +182,14 @@ LanguagePlatformTest >> testOSLineEnding [
assert: LanguagePlatform current os lineEnding
equals: '<n>' expandMacros
]

{ #category : 'tests' }
LanguagePlatformTest >> testRemoveGlobalNamedIfAbsent [

| wasFound |
wasFound := true.
LanguagePlatform current
removeGlobalNamed: #AnImplausibleGlobalName
ifAbsent: [ wasFound := false ].
self deny: wasFound
]

0 comments on commit dcd3de1

Please sign in to comment.