Skip to content

Commit

Permalink
There are lots of references to RBScanner to check if a string or sym…
Browse files Browse the repository at this point in the history
…bol is a valid selector

- add isValidSelector to String
- add test
- rewrite all senders
  • Loading branch information
MarcusDenker committed Jun 12, 2020
1 parent 7d07982 commit 9b52bf4
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/AST-Core/RBLiteralToken.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ RBLiteralToken >> storeOn: aStream [
value isSymbol
ifTrue:
[aStream nextPut: $#.
((RBScanner isSelector: value) and: [value ~~ #'||'])
(value isValidSelector and: [value ~~ #'||'])
ifTrue: [aStream nextPutAll: value]
ifFalse: [value asString printOn: aStream].
^self].
Expand Down
2 changes: 1 addition & 1 deletion src/AST-Core/RBLiteralValueNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ RBLiteralValueNode >> sourceText [
value isSymbol
ifTrue: [
aStream nextPut: $#.
((RBScanner isSelector: value) and: [value ~~ #'||'])
((value isValidSelector) and: [value ~~ #'||'])
ifTrue: [aStream nextPutAll: value]
ifFalse: [value asString printOn: aStream]]
ifFalse: [
Expand Down
9 changes: 4 additions & 5 deletions src/AST-Core/RBScanner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ RBScanner class >> initializeUnderscore [

{ #category : #testing }
RBScanner class >> isSelector: aSymbol [
| scanner |
scanner := self basicNew.
scanner on: (ReadStream on: aSymbol asString).
scanner step.
^ scanner isSelector
^ self basicNew
on: (ReadStream on: aSymbol asString);
step;
isSelector
]

{ #category : #testing }
Expand Down
7 changes: 7 additions & 0 deletions src/Collections-Strings/String.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,13 @@ String >> isValidGlobalName [
character isAlphaNumeric or: [ character = $_ ]]]
]
{ #category : #testing }
String >> isValidSelector [
"check I could be a valid selector (name of method).
For checking if there is symbol like me used as a selector, see #isSelectorSymbol on Symbol"
^ RBScanner isSelector: self
]
{ #category : #testing }
String >> isWideString [
"Answer whether the receiver is a WideString"
Expand Down
6 changes: 6 additions & 0 deletions src/Collections-Tests/StringTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,12 @@ StringTest >> testIsPatternVariable [
]
{ #category : #'tests - testing' }
StringTest >> testIsValidSelector [
self assert: 'class' isValidSelector.
self deny: '0class' isValidSelector
]
{ #category : #tests }
StringTest >> testIsWideString [
Expand Down
4 changes: 2 additions & 2 deletions src/Refactoring-Core/RBCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ RBCondition class >> checkInstanceVariableName: aName in: aClass [
RBCondition class >> checkMethodName: aString [
"Return whether the argument aName is can represent a selector"

^ aString isString and: [ RBScanner isSelector: aString ]
^ aString isString and: [ aString isValidSelector ]
]

{ #category : #utilities }
RBCondition class >> checkMethodName: aString in: aClass [
"Return whether the argument aName is can represent a selector"
"You probably look for checkMethodName: since the second argument is ignored"

^aString isString and: [ RBScanner isSelector: aString ]
^aString isString and: [ aString isValidSelector ]
]

{ #category : #'instance creation' }
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-Core/RBMethod.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ RBMethod >> refersToSymbol: aSymbol [
matches: '`#literal'
do:
[ :node :answer | answer or: [ self literal: node value containsReferenceTo: aSymbol ] ].
(RBScanner isSelector: aSymbol)
aSymbol isValidSelector
ifTrue: [ searcher
matches:
'`@object '
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-Core/RBMethodName.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RBMethodName >> arguments: nameCollection [
RBMethodName >> isValid [
"Return whether the receiver looks like a method with a selector in sync with the arguments in a possible class"

^ selector isString and: [(RBScanner isSelector: selector)
^ selector isString and: [ selector isValidSelector
and: [ selector numArgs = arguments size ]]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ RBExtractMethodTransformation >> newMethodName [
newAttempt := newSelector isNil.

"it's a valid selector"
(newSelector isString and: [RBScanner isSelector: newSelector])
(newSelector isString and: [newSelector isValidSelector])
ifFalse: [ self inform: newSelector asString, ' is not a valid selector.'.
newSelector := nil ].

Expand Down

0 comments on commit 9b52bf4

Please sign in to comment.