Skip to content

Commit

Permalink
Merge pull request #9 from pharo-project/Pharo9.0
Browse files Browse the repository at this point in the history
Update to master
  • Loading branch information
Lin777 committed Jan 20, 2021
2 parents 93220a5 + 0d986d1 commit 5a65bb8
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 50 deletions.
Expand Up @@ -217,6 +217,7 @@ ClySystemBrowserContext >> requestSingleMethodTag: queryTitle suggesting: sugges
acceptNewEntry: true;
title: queryTitle;
yourself.
ui defaultFocusMorph contentMorph selectAll.
selectedTag := ui chooseFromOwner: tool.
selectedTag isEmptyOrNil ifTrue: [ CmdCommandAborted signal].
(selectedTag beginsWith: '*') ifTrue: [
Expand Down
4 changes: 2 additions & 2 deletions src/Polymorph-Widgets/EditableDropListMorph.class.st
Expand Up @@ -19,7 +19,7 @@ Class {
#category : #'Polymorph-Widgets-Base'
}

{ #category : #'as yet unclassified' }
{ #category : #'instance creation' }
EditableDropListMorph class >> on: anObject list: getListSel selected: getSelectionSel changeSelected: setSelectionSel useIndex: useIndex addToList: addToListSel class: aClass getEnabled: getEnabledSel [
^ self
on: anObject
Expand All @@ -33,7 +33,7 @@ EditableDropListMorph class >> on: anObject list: getListSel selected: getSelect
default: ''
]

{ #category : #'as yet unclassified' }
{ #category : #'instance creation' }
EditableDropListMorph class >> on: anObject list: getListSel selected: getSelectionSel changeSelected: setSelectionSel useIndex: useIndex addToList: addToListSel class: aClass getEnabled: getEnabledSel default: aDefaultValue [
^ (super
on: anObject
Expand Down
53 changes: 29 additions & 24 deletions src/Refactoring-Core/RBAddParameterRefactoring.class.st
Expand Up @@ -22,31 +22,33 @@ Class {
}

{ #category : #'instance creation' }
RBAddParameterRefactoring class >> addParameterToMethod: aSelector in: aClass newSelector: newSelector initializer: init [
RBAddParameterRefactoring class >> addParameterToMethod: aSelector in: aClass newSelector: newSelector permutation: aColl initializer: init [
^self new addParameterToMethod: aSelector
in: aClass
newSelector: newSelector
permutation: aColl
initializer: init
]

{ #category : #'instance creation' }
RBAddParameterRefactoring class >> model: aRBSmalltalk addParameterToMethod: aSelector in: aClass newSelector: newSelector initializer: init [
^(self new)
RBAddParameterRefactoring class >> model: aRBSmalltalk addParameterToMethod: aSelector in: aClass newSelector: newSelector permutation: aColl initializer: init [
^ self new
model: aRBSmalltalk;
addParameterToMethod: aSelector
in: aClass
newSelector: newSelector
initializer: init;
in: aClass
newSelector: newSelector
permutation: aColl
initializer: init;
yourself
]

{ #category : #initialization }
RBAddParameterRefactoring >> addParameterToMethod: aSelector in: aClass newSelector: newSel initializer: init [
RBAddParameterRefactoring >> addParameterToMethod: aSelector in: aClass newSelector: newSel permutation: aColl initializer: init [
self
renameMethod: aSelector
in: aClass
to: newSel
permutation: (1 to: newSel numArgs).
permutation: aColl.
initializer := init
]

Expand Down Expand Up @@ -82,14 +84,15 @@ RBAddParameterRefactoring >> checkVariableReferencesIn: aParseTree [
]

{ #category : #private }
RBAddParameterRefactoring >> modifyImplementorParseTree: parseTree in: aClass [
| name newArg allTempVars |
allTempVars := parseTree allDefinedVariables.
name := self safeVariableNameFor: aClass temporaries: allTempVars.
newArg := RBVariableNode named: name.
RBAddParameterRefactoring >> modifyImplementorParseTree: parseTree in: aClass [
|argName|
argName := self safeVariableNameFor: aClass
temporaries: (parseTree temporaryNames, parseTree argumentNames).
parseTree
renameSelector: newSelector
andArguments: parseTree arguments , (Array with: newArg)
andArguments: ((permutation
collect: [ :e | parseTree argumentNames at: e ifAbsent: [ argName asString ] ])
collect: [:e | RBVariableNode named: e ])
]

{ #category : #preconditions }
Expand All @@ -108,11 +111,11 @@ RBAddParameterRefactoring >> newSelectorString [
| stream keywords |
stream := WriteStream on: String new.
keywords := newSelector keywords.
1 to: keywords size
do:
[:i |
stream nextPutAll: (keywords at: i).
i == keywords size
permutation
doWithIndex:
[:each :index |
stream nextPutAll: (keywords at: index).
each == 0
ifTrue:
[stream
nextPut: $(;
Expand All @@ -121,7 +124,7 @@ RBAddParameterRefactoring >> newSelectorString [
ifFalse:
[stream
nextPutAll: ' ``@arg';
nextPutAll: i printString].
nextPutAll: each printString].
stream nextPut: $ ].
^stream contents
]
Expand All @@ -139,15 +142,15 @@ RBAddParameterRefactoring >> parseTreeRewriter [

{ #category : #private }
RBAddParameterRefactoring >> safeVariableNameFor: aClass temporaries: allTempVars [
| baseString i newString |
| baseString index newString |
newString := baseString := 'anObject'.
i := 0.
index := 0.

[(allTempVars includes: newString)
or: [aClass definesInstanceVariable: newString]]
whileTrue:
[i := i + 1.
newString := baseString , i printString].
[index := index + 1.
newString := baseString , index printString].
^newString
]

Expand All @@ -173,6 +176,8 @@ RBAddParameterRefactoring >> storeOn: aStream [
aStream
nextPutAll: ' newSelector: #';
nextPutAll: newSelector;
nextPutAll: ' permutation: ';
nextPutAll: permutation asString;
nextPutAll: ' initializer: ''';
nextPutAll: initializer;
nextPutAll: ''')'
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-Core/RBRenameMethodRefactoring.class.st
Expand Up @@ -29,7 +29,7 @@ RBRenameMethodRefactoring class >> model: aRBSmalltalk renameMethod: aSelector i
]

{ #category : #'instance creation' }
RBRenameMethodRefactoring class >> renameMethod: aSelector in: aClass to: newSelector permutation: aMap [
RBRenameMethodRefactoring class >> renameMethod: aSelector in: aClass to: newSelector permutation: aMap [
^self new renameMethod: aSelector
in: aClass
to: newSelector
Expand Down
43 changes: 28 additions & 15 deletions src/Refactoring-Tests-Core/RBAddParameterTest.class.st
Expand Up @@ -19,10 +19,11 @@ RBAddParameterTest >> testAddParameterForTwoArgumentMessage [
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
permutation: #(1 0 2)
initializer: '#(1.0)'.
self proceedThroughWarning: [ self executeRefactoring: refactoring ].
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self assert: (class parseTreeFor: newSelector) equals: (self parseMethod: 'called: anObject bar: aBlock on: anObject1
self assert: (class parseTreeFor: newSelector) equals: (self parseMethod: 'called: anObject bar: anObject1 on: aBlock
Transcript
show: anObject printString;
cr.
Expand All @@ -32,7 +33,7 @@ RBAddParameterTest >> testAddParameterForTwoArgumentMessage [
anObject := 5.
self
called: anObject + 1
bar: [^anObject] on: #(1.0)').
bar: #(1.0) on: [^anObject]').
self deny: (class directlyDefinesMethod: oldSelector)
]

Expand All @@ -43,10 +44,11 @@ RBAddParameterTest >> testAddParameterThatReferencesGlobalAndLiteral [
oldSelector := ('test' , 'Foo:') asSymbol.
newSelector := #testFoo:bar:.
refactoring := RBAddParameterRefactoring
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
initializer: 'OrderedCollection new: 5'.
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
permutation: #(1 0)
initializer: 'OrderedCollection new: 5'.
self proceedThroughWarning: [ self executeRefactoring: refactoring ].
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self
Expand All @@ -67,11 +69,12 @@ RBAddParameterTest >> testAddParameterThatReferencesModelGlobal [
oldSelector := ('test' , 'Foo:') asSymbol.
newSelector := #testFoo:bar:.
refactoring := RBAddParameterRefactoring
model: model
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
initializer: 'Bar new'.
model: model
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
permutation: #(1 0)
initializer: 'Bar new'.
self proceedThroughWarning: [ self executeRefactoring: refactoring ].
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self
Expand All @@ -92,10 +95,11 @@ RBAddParameterTest >> testAddParameterThatReferencesSelf [
oldSelector := ('test' , 'Foo:') asSymbol.
newSelector := #testFoo:bar:.
refactoring := RBAddParameterRefactoring
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
initializer: 'self printString'.
addParameterToMethod: oldSelector
in: RBRefactoryTestDataApp
newSelector: newSelector
permutation: #(1 0)
initializer: 'self printString'.
self proceedThroughWarning: [ self executeRefactoring: refactoring ].
class := refactoring model classNamed: #RBRefactoryTestDataApp.
self
Expand All @@ -117,11 +121,13 @@ RBAddParameterTest >> testBadInitializationCode [
addParameterToMethod: #name
in: RBLintRuleTestData
newSelector: #name:
permutation: #(0)
initializer: 'foo:');
shouldFail: (RBAddParameterRefactoring
addParameterToMethod: #name
in: RBLintRuleTestData
newSelector: #name:
permutation: #(0)
initializer: 'foo')
]

Expand All @@ -131,6 +137,7 @@ RBAddParameterTest >> testInvalidNumArgsOfNewSelector [
addParameterToMethod: #checkSendersAccessTo:
in: RBLintRuleTestData
newSelector: #checkSendersAccessTo:
permutation: #(0)
initializer: 'nil')
]

Expand All @@ -143,6 +150,7 @@ RBAddParameterTest >> testModelBadInitializationCode [
addParameterToMethod: #name1
in: RBLintRuleTestData
newSelector: #name1:
permutation: #(0)
initializer: 'AddParameterRefactoring new'.
self shouldFail: refactoring
]
Expand All @@ -156,6 +164,7 @@ RBAddParameterTest >> testModelNonExistantName [
addParameterToMethod: #name
in: RBLintRuleTestData
newSelector: #nameNew:
permutation: #(0)
initializer: 'nil'.
self shouldFail: refactoring
]
Expand All @@ -166,6 +175,7 @@ RBAddParameterTest >> testNonExistantName [
addParameterToMethod: #name1
in: RBLintRuleTestData
newSelector: #name1:
permutation: #(0)
initializer: 'nil')
]

Expand All @@ -180,12 +190,14 @@ RBAddParameterTest >> testPrimitiveMethods [
addParameterToMethod: #foo
in: Object
newSelector: #foo123124321s:
permutation: #(0)
initializer: '1'.
self shouldFail: refactoring.
refactoring := RBAddParameterRefactoring
addParameterToMethod: #at:
in: Object
newSelector: #at:foo:
permutation: #(1 0)
initializer: '1'.
self shouldFail: refactoring.

Expand All @@ -197,5 +209,6 @@ RBAddParameterTest >> testUseExistingNewSelector [
addParameterToMethod: #checkSendersAccessTo:
in: RBLintRuleTestData
newSelector: #safeVariableNameFor:temporaries:
permutation: #(1 0)
initializer: 'nil')
]
9 changes: 8 additions & 1 deletion src/System-Platforms/KeyboardKey.class.st
Expand Up @@ -753,8 +753,15 @@ KeyboardKey class >> initializeUnixVirtualKeyTable [
at: $w asciiValue put: (self value: 16r57); " kVK_ANSI_W = 0x0D"
at: $x asciiValue put: (self value: 16r58); " kVK_ANSI_X = 0x07"
at: $y asciiValue put: (self value: 16r59); " kVK_ANSI_Y = 0x10"
at: $z asciiValue put: (self value: 16r5a); " kVK_ANSI_Z = 0x06"
at: $z asciiValue put: (self value: 16r5a). " kVK_ANSI_Z = 0x06"

"Map also uppercase letters.
Old VM events use the ascii value of characters in linux to refer to keys.
Work it around by making lowercase and uppercase letters both refer to the same key"
($A to: $Z) do: [ :c |
UnixVirtualKeyTable at: c asciiValue put: (UnixVirtualKeyTable at: c asLowercase asciiValue) ].

UnixVirtualKeyTable
at: $0 asciiValue put: (self value: 16r30); " kVK_ANSI_0 = 0x1D"
at: $1 asciiValue put: (self value: 16r31); " kVK_ANSI_1 = 0x12"
at: $2 asciiValue put: (self value: 16r32); " kVK_ANSI_2 = 0x13"
Expand Down
Expand Up @@ -39,14 +39,33 @@ SycAddMessageArgumentCommand >> argumentDefaultValue: anObject [

{ #category : #execution }
SycAddMessageArgumentCommand >> createRefactoring [

| permutation |
permutation := newSelector argumentNames collect: [ :e |
originalMessage argumentNames indexOf: e ifAbsent: [ 0 ]
].
^RBAddParameterRefactoring
addParameterToMethod: originalMessage selector
in: (SycMessageOriginHack of: originalMessage) "look at SycMessageOriginHack comment"
newSelector: newSelector
newSelector: newSelector selector
permutation: permutation
initializer: argumentDefaultValue
]

{ #category : #execution }
SycAddMessageArgumentCommand >> createValidNameArgument [
|method newString baseString i|
method := originalMessage methodClass >> originalMessage selector.
newString := baseString := 'anObject'.
i := 0.

[(method tempNames includes: newString)
or: [originalMessage methodClass allInstVarNames includes: newString]]
whileTrue:
[i := i + 1.
newString := baseString , i printString].
^ {newString asSymbol}
]

{ #category : #accessing }
SycAddMessageArgumentCommand >> defaultMenuIconName [
^#smallAdd
Expand All @@ -71,15 +90,29 @@ SycAddMessageArgumentCommand >> newSelector: anObject [
{ #category : #execution }
SycAddMessageArgumentCommand >> prepareFullExecutionInContext: aToolContext [
super prepareFullExecutionInContext: aToolContext.
newSelector := UIManager default
request: 'Enter new selector:' initialAnswer: originalMessage selector.
newSelector isEmptyOrNil ifTrue: [ CmdCommandAborted signal ].

newSelector := self requestMessageIn: aToolContext.

argumentDefaultValue := UIManager default
request: 'Enter default value for argument' initialAnswer: 'nil'.
argumentDefaultValue isEmptyOrNil ifTrue: [ CmdCommandAborted signal ]
]

{ #category : #execution }
SycAddMessageArgumentCommand >> requestMessageIn: aToolContext [
| methodName dialog |
methodName := RBMethodName selector: originalMessage selector, 'arg:' arguments: originalMessage argumentNames, self createValidNameArgument.
dialog := SycMethodNameEditorPresenter openOn: methodName.
dialog cancelled ifTrue: [ CmdCommandAborted signal ].

originalMessage selector = methodName selector & (originalMessage argumentNames = methodName arguments)
ifTrue: [ CmdCommandAborted signal].

^(SycMessageDescription fromContextOf: aToolContext)
selector: methodName selector;
argumentNames: methodName arguments
]

{ #category : #execution }
SycAddMessageArgumentCommand >> resultMessageSelector [
^newSelector
Expand Down
Expand Up @@ -41,11 +41,13 @@ SycRefactoringStoreOnTest >> testSycAddMessageArgumentCommandIsProperlyStoreOn [
| refactorings |
refactorings := SycAddMessageArgumentCommand new
originalMessage: (MockTreeTableItem >> #title:) ast;
newSelector: #title:lala:;
newSelector: (SycMessageDescription new
selector: #title:lala:;
argumentNames: #(#anObject #anObject1));
argumentDefaultValue: 'nil';
asRefactorings.

self
assert: (String streamContents: [ :s | refactorings storeOn: s ])
equals: '((Array new: 1) at: 1 put: (RBAddParameterRefactoring addParameterToMethod: #title: in: MockTreeTableItem newSelector: #title:lala: initializer: ''nil''); yourself)'
equals: '((Array new: 1) at: 1 put: (RBAddParameterRefactoring addParameterToMethod: #title: in: MockTreeTableItem newSelector: #title:lala: permutation: #(1 0) initializer: ''nil''); yourself)'
]

0 comments on commit 5a65bb8

Please sign in to comment.