Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Kernel-CodeModel/Class.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ Class >> hasClassVariable: aGlobal [
^ self classVariables identityIncludes: aGlobal
]

{ #category : 'testing' }
Class >> hasClassVariableNamed: aSymbol [
"Return whether the receiver or any of its superclasses has a class variable named aSymbol."
<reflection: 'Class structural inspection - Class variable inspection'>

| var |
var := self lookupVar: aSymbol.
^ var notNil and: [ var isClassVariable ]
]

{ #category : 'accessing - comment' }
Class >> hasComment [
"Return whether this class truly has a comment other than the default"
Expand Down
36 changes: 18 additions & 18 deletions src/Refactoring-Core-Tests/RBClassTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ RBClassTest >> testClassSide [
self deny: abstractTransformationClass isMeta.
]

{ #category : 'tests - definition' }
RBClassTest >> testDefinesClassVariable [

self deny:
(abstractTransformationClass definesClassVariable: #ClassVariable1).
self assert: (abstractTransformationClass definesClassVariable:
self abstractTransformationClassVariable).
self assert: (newClass definesClassVariable: #ClassVariable1).
self deny: (refactoringClass definesClassVariable: #ClassVariable1).
self assert: (refactoringClass definesClassVariable:
self abstractTransformationClassVariable)
]

{ #category : 'tests - definition' }
RBClassTest >> testDefinesInstanceVariable [
self deny: (abstractTransformationClass definesInstanceVariable: 'instanceVariable1').
Expand Down Expand Up @@ -103,10 +90,10 @@ RBClassTest >> testDefinesSharedVariable2 [
root := rbNamespace classNamed: #MyClassARoot.
sub := rbNamespace classNamed: #MySubAccessingSuperclassState.
self assert: (root subclasses includes: sub).
self assert: (root definesClassVariable: #Shared2).
self assert: (root hasClassVariableNamed: #Shared2).

"a subclass is considered defining a variable even if it is defined by the superclass."
self assert: (sub definesClassVariable: #Shared2).
self assert: (sub hasClassVariableNamed: #Shared2).
]

{ #category : 'tests - definition' }
Expand Down Expand Up @@ -135,7 +122,7 @@ RBClassTest >> testDirectlyDefinesSharedVariable [
self assert: (root subclasses includes: sub).
self assert: (root directlyDefinesClassVariable: #Shared2).

self assert: (sub definesClassVariable: #Shared2).
self assert: (sub hasClassVariableNamed: #Shared2).
self deny: (sub directlyDefinesClassVariable: #Shared2).
]

Expand All @@ -148,10 +135,23 @@ RBClassTest >> testDirectlyDefinesSharedVariable2 [
root := rbNamespace classNamed: #MyClassARoot.
sub := rbNamespace classNamed: #MySubAccessingSuperclassState.
self assert: (root subclasses includes: sub).
self assert: (root definesClassVariable: #Shared2).
self assert: (root hasClassVariableNamed: #Shared2).

"a subclass is considered defining a variable even if it is defined by the superclass."
self assert: (sub definesClassVariable: #Shared2).
self assert: (sub hasClassVariableNamed: #Shared2).
]

{ #category : 'tests - definition' }
RBClassTest >> testHasClassVariableNamed [

self deny:
(abstractTransformationClass hasClassVariableNamed: #ClassVariable1).
self assert: (abstractTransformationClass hasClassVariableNamed:
self abstractTransformationClassVariable).
self assert: (newClass hasClassVariableNamed: #ClassVariable1).
self deny: (refactoringClass hasClassVariableNamed: #ClassVariable1).
self assert: (refactoringClass hasClassVariableNamed:
self abstractTransformationClassVariable)
]

{ #category : 'method tests' }
Expand Down
6 changes: 3 additions & 3 deletions src/Refactoring-Core-Tests/RBConditionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ RBConditionTest >> testHierarchyOfReferencesSharedVariableFromClassSide [
root := rbNamespace classNamed: #MyClassARoot.
sub := rbNamespace classNamed: #MySubAccessingSuperclassState.
self assert: (root subclasses includes: sub).
self assert: (root definesClassVariable: #Shared2).
self assert: (sub definesClassVariable: #Shared2).
self assert: (root hasClassVariableNamed: #Shared2).
self assert: (sub hasClassVariableNamed: #Shared2).

self assert: (ReSharedVariableHasReferences new
hierarchyOf: root
Expand All @@ -194,7 +194,7 @@ RBConditionTest >> testHierarchyOfReferencesSharedVariableFromSubclass [
root := rbNamespace classNamed: #MyClassARoot.
sub := rbNamespace classNamed: #MySubAccessingSuperclassState.
self assert: (root subclasses includes: sub).
self assert: (root definesClassVariable: #Shared2).
self assert: (root hasClassVariableNamed: #Shared2).

"We access the class var from the superclass only from a subclass."
self assert: (ReSharedVariableHasReferences new
Expand Down
12 changes: 6 additions & 6 deletions src/Refactoring-Core-Tests/RBSharedPoolTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ RBSharedPoolTest >> setUp [
userOf := rbNamespace classNamed: #DateAndTime
]

{ #category : 'method tests' }
RBSharedPoolTest >> testDefinesClassVariable [

self assert: (defineOf definesClassVariable: #DayNames)
]

{ #category : 'method tests' }
RBSharedPoolTest >> testDefinesPoolDictionary [
"Pay attention that definesPoolDictionary: is badly named, because in fact
Expand All @@ -58,6 +52,12 @@ RBSharedPoolTest >> testDefinesPoolDictionary [
self assert: (userOf definesPoolDictionary: #ChronologyConstants)
]

{ #category : 'method tests' }
RBSharedPoolTest >> testHasClassVariableNamed [

self assert: (defineOf hasClassVariableNamed: #DayNames)
]

{ #category : 'method tests' }
RBSharedPoolTest >> testIsNotSharedPool [

Expand Down
24 changes: 12 additions & 12 deletions src/Refactoring-Core/RBAbstractClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,6 @@ RBAbstractClass >> convertMethod: selector using: searchReplacer [
ifTrue: [ self compileTree: searchReplacer tree ]
]

{ #category : 'testing' }
RBAbstractClass >> definesClassVariable: aSymbol [
"Returns whether the class or its superclasses define a shared variable named: aSymbol"

self realClass isTrait ifTrue: [ ^ false ].
(self directlyDefinesClassVariable: aSymbol) ifTrue: [ ^ true ].
^ self superclass isNotNil
and: [ self superclass definesClassVariable: aSymbol ]
]

{ #category : 'testing' }
RBAbstractClass >> definesInstanceVariable: aString [

Expand All @@ -289,7 +279,7 @@ RBAbstractClass >> definesPoolDictionary: aSymbol [

{ #category : 'testing' }
RBAbstractClass >> definesVariable: aVariableName [
^(self definesClassVariable: aVariableName)
^(self hasClassVariableNamed: aVariableName)
or: [self definesInstanceVariable: aVariableName]
]

Expand Down Expand Up @@ -422,6 +412,16 @@ RBAbstractClass >> getterMethodFor: aVariableName [
ifNone: [ nil ]
]

{ #category : 'testing' }
RBAbstractClass >> hasClassVariableNamed: aSymbol [
"Returns whether the class or its superclasses define a shared variable named: aSymbol"

self realClass isTrait ifTrue: [ ^ false ].
(self directlyDefinesClassVariable: aSymbol) ifTrue: [ ^ true ].
^ self superclass isNotNil
and: [ self superclass hasClassVariableNamed: aSymbol ]
]

{ #category : 'testing' }
RBAbstractClass >> hasRemoved: aSelector [
^removedMethods isNotNil and: [removedMethods includes: aSelector]
Expand All @@ -434,7 +434,7 @@ RBAbstractClass >> hash [

{ #category : 'testing' }
RBAbstractClass >> hierarchyDefinesClassVariable: aString [
(self definesClassVariable: aString)
(self hasClassVariableNamed: aString)
ifTrue: [ ^ true ].
^ self allSubclasses
anySatisfy: [ :each | each directlyDefinesClassVariable: aString ]
Expand Down
16 changes: 8 additions & 8 deletions src/Refactoring-Core/RBCondition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ RBCondition class >> checkInstanceVariableName: aName in: aClass [
^ OCScanner isVariable: string
]

{ #category : 'instance creation' }
RBCondition class >> definesClassVariable: aString in: aClass [
^self new
block: [aClass definesClassVariable: aString]
errorString: aClass printString
, ' <1?:does not >define<1?s:> class variable ' , aString
]

{ #category : 'instance creation' }
RBCondition class >> definesInstanceVariable: aString in: aClass [
^self new
Expand Down Expand Up @@ -157,6 +149,14 @@ RBCondition class >> empty [
^ self true
]

{ #category : 'instance creation' }
RBCondition class >> hasClassVariableNamed: aString in: aClass [
^self new
block: [aClass hasClassVariableNamed: aString]
errorString: aClass printString
, ' <1?:does not >define<1?s:> class variable ' , aString
]

{ #category : 'instance creation' }
RBCondition class >> hasSuperclass: aClass [
^self new
Expand Down
2 changes: 1 addition & 1 deletion src/Refactoring-Core/RBExtractMethodRefactoring.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ RBExtractMethodRefactoring >> validateRenameNode: aParseTree withOldName: oldNam
conditions := ((RBCondition isValidInstanceVariableName: newName for: class)
& (RBCondition definesSelector: selector in: class)
& (RBCondition definesInstanceVariable: newName in: class) not
& (RBCondition definesClassVariable: newName in: class) not).
& (RBCondition hasClassVariableNamed: newName in: class) not).
conditions check
ifFalse: [ block := conditions errorBlock.
block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Class {
{ #category : 'preconditions' }
RBPushDownClassVariableRefactoring >> applicabilityPreconditions [

^ { (RBCondition definesClassVariable: variableName in: class) }
^ { (RBCondition hasClassVariableNamed: variableName in: class) }
]

{ #category : 'preconditions' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ReCreateAccessorsForVariableTransformation >> applicabilityPreconditions [

^ { (classVariable
ifTrue: [
RBCondition definesClassVariable: variableName asSymbol in: class ]
RBCondition hasClassVariableNamed: variableName asSymbol in: class ]
ifFalse: [
RBCondition definesInstanceVariable: variableName in: class ]) }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ RBRemoveClassVariableParametrizedTest >> testRemoveClassVariable [
refactoring := self createRefactoringWithModel: model andArguments:
{'Foo1' . #RBLintRuleTestData}.
class := refactoring model classNamed: #RBLintRuleTestData.
self assert: (class definesClassVariable: 'Foo1').
self assert: (class hasClassVariableNamed: 'Foo1').

self executeRefactoring: refactoring.

self deny: (class definesClassVariable: 'Foo1')
self deny: (class hasClassVariableNamed: 'Foo1')
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RBAddVariableAccessorTransformation >> applicabilityPreconditions [

^ { (isClassVariable
ifTrue: [
RBCondition definesClassVariable: variableName asSymbol in: class ]
RBCondition hasClassVariableNamed: variableName asSymbol in: class ]
ifFalse: [
RBCondition definesInstanceVariable: variableName in: class ]) }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ RBMergeInstanceVariableIntoAnotherTransformation >> applicabilityPreconditions [
conds , {
(RBCondition isMetaclass: class) not.
(RBCondition
definesClassVariable: newVariableName asString
hasClassVariableNamed: newVariableName asString
in: class).
(RBCondition
definesClassVariable: variableName asString
hasClassVariableNamed: variableName asString
in: class) } ]
ifFalse: [
conds , {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Class {
RBPushDownVariableTransformation >> applicabilityPreconditionsForClassVariable [

^ { RBCondition
definesClassVariable: variableName
hasClassVariableNamed: variableName
in: self definingClass }
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RBRemoveVariableTransformation >> applicabilityPreconditions [
RBRemoveVariableTransformation >> applicabilityPreconditionsForClassVariable [

^ { (RBCondition isMetaclass: class) not.
(RBCondition definesClassVariable: variableName in: class) }
(RBCondition hasClassVariableNamed: variableName in: class) }
]

{ #category : 'preconditions' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ RBRenameVariableTransformation >> applicabilityPreconditions [
isValidClassVarName: newVariableName asString
for: class).
(RBCondition
definesClassVariable: variableName asString
hasClassVariableNamed: variableName asString
in: class) } ]
ifFalse: [
{
Expand Down