From dcd3de12049c86438848d0c4de6aa7ca1de47335 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Fri, 22 Nov 2024 08:03:50 -0300 Subject: [PATCH] Add methods for global management in LanguagePlatform (#133) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add to LanguagePlatform globalNamedïfAbsentPut: and removeGlobalNamed:ifAbsent: * Add system icons * Avoid translation rule search in critics --- .../CircularIterator.extension.st | 7 +++ .../Formatter.extension.st | 7 +++ ...ethodsForLocalizationMessagesRule.class.st | 7 +++ .../LanguagePlatform.class.st | 12 ++++ .../GemStone64Platform.class.st | 61 +++++++++++++------ .../PharoPlatform.class.st | 12 ++++ .../LanguagePlatformTest.class.st | 32 ++++++++++ 7 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 source/Buoy-Development-Tools-Pharo-12/CircularIterator.extension.st create mode 100644 source/Buoy-Development-Tools-Pharo-12/Formatter.extension.st diff --git a/source/Buoy-Development-Tools-Pharo-12/CircularIterator.extension.st b/source/Buoy-Development-Tools-Pharo-12/CircularIterator.extension.st new file mode 100644 index 0000000..4ddd529 --- /dev/null +++ b/source/Buoy-Development-Tools-Pharo-12/CircularIterator.extension.st @@ -0,0 +1,7 @@ +Extension { #name : 'CircularIterator' } + +{ #category : '*Buoy-Development-Tools-Pharo-12' } +CircularIterator class >> systemIconName [ + + ^ #collection +] diff --git a/source/Buoy-Development-Tools-Pharo-12/Formatter.extension.st b/source/Buoy-Development-Tools-Pharo-12/Formatter.extension.st new file mode 100644 index 0000000..585994c --- /dev/null +++ b/source/Buoy-Development-Tools-Pharo-12/Formatter.extension.st @@ -0,0 +1,7 @@ +Extension { #name : 'Formatter' } + +{ #category : '*Buoy-Development-Tools-Pharo-12' } +Formatter class >> systemIconName [ + + ^ #string +] diff --git a/source/Buoy-Development-Tools-Pharo-12/SearchMethodsForLocalizationMessagesRule.class.st b/source/Buoy-Development-Tools-Pharo-12/SearchMethodsForLocalizationMessagesRule.class.st index fb13395..d362134 100644 --- a/source/Buoy-Development-Tools-Pharo-12/SearchMethodsForLocalizationMessagesRule.class.st +++ b/source/Buoy-Development-Tools-Pharo-12/SearchMethodsForLocalizationMessagesRule.class.st @@ -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 ]; diff --git a/source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st b/source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st index 35d52cc..a1655ff 100644 --- a/source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st +++ b/source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st @@ -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 [ @@ -75,3 +81,9 @@ LanguagePlatform >> os [ ^ self subclassResponsibility ] + +{ #category : 'reflection' } +LanguagePlatform >> removeGlobalNamed: aSymbol ifAbsent: absentBlock [ + + ^ self subclassResponsibility +] diff --git a/source/Buoy-Metaprogramming-GS64-Extensions/GemStone64Platform.class.st b/source/Buoy-Metaprogramming-GS64-Extensions/GemStone64Platform.class.st index d81f656..0c89a71 100644 --- a/source/Buoy-Metaprogramming-GS64-Extensions/GemStone64Platform.class.st +++ b/source/Buoy-Metaprogramming-GS64-Extensions/GemStone64Platform.class.st @@ -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' } @@ -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' } @@ -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 ] diff --git a/source/Buoy-Metaprogramming-Pharo-Extensions/PharoPlatform.class.st b/source/Buoy-Metaprogramming-Pharo-Extensions/PharoPlatform.class.st index 4edc434..c62542f 100644 --- a/source/Buoy-Metaprogramming-Pharo-Extensions/PharoPlatform.class.st +++ b/source/Buoy-Metaprogramming-Pharo-Extensions/PharoPlatform.class.st @@ -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 [ @@ -56,3 +62,9 @@ PharoPlatform >> os [ ^ OSPlatform current ] + +{ #category : 'reflection' } +PharoPlatform >> removeGlobalNamed: aSymbol ifAbsent: absentBlock [ + + ^ Smalltalk globals removeKey: aSymbol ifAbsent: absentBlock +] diff --git a/source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st b/source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st index fc92edb..54712c3 100644 --- a/source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st +++ b/source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st @@ -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 [ @@ -161,3 +182,14 @@ LanguagePlatformTest >> testOSLineEnding [ assert: LanguagePlatform current os lineEnding equals: '' expandMacros ] + +{ #category : 'tests' } +LanguagePlatformTest >> testRemoveGlobalNamedIfAbsent [ + + | wasFound | + wasFound := true. + LanguagePlatform current + removeGlobalNamed: #AnImplausibleGlobalName + ifAbsent: [ wasFound := false ]. + self deny: wasFound +]