Skip to content

Commit

Permalink
Merge pull request pharo-project#3504 from Ducasse/3358-Why-do-we-hav…
Browse files Browse the repository at this point in the history
…e-RBRefactoryChangeManager-and-RBRefactoringManager

3358-Why-do-we-have-RBRefactoryChangeManager-and-RBRefactoringManager
  • Loading branch information
Ducasse committed Jun 14, 2019
2 parents a89ce51 + 85fcd2a commit 930b73e
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 272 deletions.
2 changes: 1 addition & 1 deletion src/Refactoring-Core/RBRefactoring.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ RBRefactoring >> defaultEnvironment [
{ #category : #transforming }
RBRefactoring >> execute [
self primitiveExecute.
RBRefactoringManager instance addRefactoring: self
RBRefactoryChangeManager instance performChange: self changes.
]

{ #category : #transforming }
Expand Down
64 changes: 0 additions & 64 deletions src/Refactoring-Core/RBRefactoringManager.class.st

This file was deleted.

15 changes: 0 additions & 15 deletions src/Refactoring-Tests-Core/RBRefactoringTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ m
{ #category : #running }
RBRefactoringTest >> setUp [
super setUp.
manager := RBRefactoringManager classVarNamed: #Instance.
RBRefactoringManager classVarNamed: #Instance put: nil.
model := RBClassModelFactory rbNamespace new
]
Expand Down Expand Up @@ -437,14 +435,6 @@ RBRefactoringTest >> shouldWarn: aRefactoring [
raise: RBRefactoringWarning
]
{ #category : #running }
RBRefactoringTest >> tearDown [
RBRefactoringManager instance release.
RBRefactoringManager classVarNamed: #Instance put: manager.
super tearDown
]
{ #category : #tests }
RBRefactoringTest >> testConditions [
| condition newCondition |
Expand All @@ -471,8 +461,3 @@ RBRefactoringTest >> testConditions [
self assert: (condition not & condition not) check.
self assert: (condition & condition) errorString equals: 'false OR false'
]
{ #category : #tests }
RBRefactoringTest >> testPrintRefactoringManager [
self assert: RBRefactoringManager instance printString isString
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ RBMethodProtocolTransformationTest >> testRefactoring [
self assert: (RBDummyEmptyClass organization protocolOrganizer protocolNamed: 'empty protocol 2') isEmpty.

refactoring := (RBMethodProtocolTransformation protocol: 'empty protocol 2' inMethod: #someMethod inClass: #RBDummyEmptyClass) asRefactoring transform.
RBRefactoringManager instance addRefactoring: refactoring.
RBRefactoryChangeManager instance performChange: refactoring changes.

self deny: (RBDummyEmptyClass organization protocolOrganizer protocolNamed: 'empty protocol 2') isEmpty.

refactoring := (RBMethodProtocolTransformation protocol: 'empty protocol 1' inMethod: #someMethod inClass: #RBDummyEmptyClass) asRefactoring transform.
RBRefactoringManager instance addRefactoring: refactoring.
RBRefactoryChangeManager instance performChange: refactoring changes.

self assert: (RBDummyEmptyClass organization protocolOrganizer protocolNamed: 'empty protocol 2') isEmpty
]
Expand All @@ -53,7 +53,7 @@ RBMethodProtocolTransformationTest >> testTransform [
inMethod: #someMethod
inClass: #RBDummyEmptyClass)
transform.
RBRefactoringManager instance addRefactoring: transformation.
RBRefactoryChangeManager instance performChange: transformation changes.

self assert: ( RBDummyEmptyClass
organization protocolOrganizer
Expand All @@ -64,8 +64,7 @@ RBMethodProtocolTransformationTest >> testTransform [
inMethod: #someMethod
inClass: #RBDummyEmptyClass)
transform.
RBRefactoringManager instance addRefactoring: transformation.

RBRefactoryChangeManager instance performChange: transformation changes.
self assert: ( RBDummyEmptyClass
organization protocolOrganizer
protocolNamed: 'empty protocol 2' ) isEmpty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RBRemoveProtocolTransformationTest >> testRefactoring [
protocol: 'transforming'
inClass: #RBDummyEmptyClass)
transform.
RBRefactoringManager instance addRefactoring: refactoring.
RBRefactoryChangeManager instance performChange: refactoring changes.

refactoring := (RBRemoveProtocolTransformation
protocol: 'transforming'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ RBTransformationTest >> setUp [
super setUp.
self createMockClass.
manager := RBRefactoringManager classVarNamed: #Instance.
RBRefactoringManager classVarNamed: #Instance put: nil.
model := RBNamespace2 new
]
Expand All @@ -153,8 +151,6 @@ RBTransformationTest >> shouldFail: aRefactoring [
{ #category : #running }
RBTransformationTest >> tearDown [
RBRefactoringManager instance release.
RBRefactoringManager classVarNamed: #Instance put: manager.
self removeMockClass.
super tearDown
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,17 @@ RBAddAssignmentTransformation >> privateTransform [
| methodTree assignmentNode assignments previousNode |
methodTree := self definingMethod.
assignmentNode := RBAssignmentNode
variable: ( RBVariableNode named: variableName )
value: ( RBParser parseExpression: value ).
variable: (RBVariableNode named: variableName)
value: (self parserClass parseExpression: value).

"check whether there are some dependencies in the expression"
assignments := ( methodTree allChildren
select: #isAssignment )
assignments := (methodTree allChildren select: #isAssignment)
select: [ :each | each variable name asString = variableName ].
previousNode := assignments detectMax: #stop.

previousNode
ifNil: [ methodTree body addNodeFirst: assignmentNode ]
ifNotNil: [ previousNode parent addNode: assignmentNode after: previousNode ].
class compileTree: methodTree.
class compileTree: methodTree
]

{ #category : #printing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,19 @@ RBAddMessageSendTransformation >> preconditions [

{ #category : #executing }
RBAddMessageSendTransformation >> privateTransform [

| methodTree messageNode assignments variables previousNode |
| methodTree messageNode assignments variables previousNode |
methodTree := self definingMethod.
messageNode := RBParser parseExpression: message.
messageNode := self parserClass parseExpression: message.

"if the message requires variables, look for the right variables in this context"
variables := messageNode allVariables.
assignments := ( methodTree allChildren
select: #isAssignment )
assignments := (methodTree allChildren select: #isAssignment)
select: [ :each | variables includes: each variable ].

previousNode := assignments detectMax: #stop.

previousNode
ifNil: [ methodTree body addNodeFirst: messageNode ]
ifNotNil: [ previousNode parent addNode: messageNode after: previousNode ].

class compileTree: methodTree.
class compileTree: methodTree
]

{ #category : #printing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ RBAddPragmaTransformation >> privateTransform [

| methodTree pragmaNode |
methodTree := self definingMethod.
pragmaNode := RBParser parsePragma: pragma.

pragmaNode := self parserClass parsePragma: pragma.
methodTree addPragma: pragmaNode.
self definingClass compileTree: methodTree.
self definingClass compileTree: methodTree
]

{ #category : #printing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ RBAddReturnStatementTransformation >> privateTransform [

| methodTree messageNode |
methodTree := self definingMethod.
messageNode := RBParser parseExpression: returnValue.

messageNode := self parserClass parseExpression: returnValue.
methodTree body addNode: messageNode.
self definingClass compileTree: methodTree.
self definingClass compileTree: methodTree
]

{ #category : #api }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,25 @@ RBAddSubtreeTransformation >> preconditions [

{ #category : #executing }
RBAddSubtreeTransformation >> privateTransform [

| parseTree newNode |
parseTree := self definingClass parseTreeFor: selector.
parseTree ifNil: [ ^ self ].
newNode := RBParser parseExpression: sourceCode onError: [ :string :pos | ^ self ].

newNode := self parserClass
parseExpression: sourceCode
onError: [ :string :pos | ^ self ].

"The method is empty, then just add the new code"
parseTree body statements
ifEmpty: [ parseTree addNode: newNode. ^ self ].

ifEmpty: [ parseTree addNode: newNode.
^ self ].

"It tries to find the block to insert new code.
If not found, e.g., the interval is invalid, it adds the code at the end."
parseTree := parseTree allSequenceNodes
detect: [ :sequence | sequence intersectsInterval: interval ]
ifFound: [ :sequence | self addNode: newNode toSequence: sequence ]
ifNone: [ parseTree body addNodeLast: newNode. parseTree ].

ifNone: [ parseTree body addNodeLast: newNode.
parseTree ].
self definingClass compileTree: parseTree
]

Expand Down
39 changes: 0 additions & 39 deletions src/Refactoring2-Transformations/RBChangesBrowser.class.st

This file was deleted.

10 changes: 10 additions & 0 deletions src/Refactoring2-Transformations/RBClassTransformation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ RBClassTransformation >> definingClass [
class := self model
classObjectFor: self className ]
]

{ #category : #preconditions }
RBClassTransformation >> parseTreeRewriterClass [
^ RBParseTreeRewriter
]

{ #category : #executing }
RBClassTransformation >> parserClass [
^ RBParser
]
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Class {
{ #category : #api }
RBCustomTransformation class >> model: aRBModel with: aBlockWithOneArg [

^ (self new)
^ self new
model: aRBModel;
transformationBlock: aBlockWithOneArg;
yourself
Expand All @@ -34,7 +34,7 @@ RBCustomTransformation class >> model: aRBModel with: aBlockWithOneArg [
{ #category : #api }
RBCustomTransformation class >> with: aBlockWithOneArg [

^ (self new)
^ self new
transformationBlock: aBlockWithOneArg;
yourself
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ RBMoveTemporaryVariableDefinitionTransformation >> checkAllBlocksIn: aParseTree

{ #category : #private }
RBMoveTemporaryVariableDefinitionTransformation >> checkBlocksIn: aParseTree [

| searcher |
searcher := RBParseTreeSearcher new.
searcher := self parseTreeSearcher.
searcher
matches: '[:`@args | | `@temps | `@.Statements]'
do: [ :aNode :answer | answer];
matches: variableName do: [:aNode :answer | true].
^ (searcher executeTree: aParseTree initialAnswer: false)
do: [ :aNode :answer | answer ];
matches: variableName do: [ :aNode :answer | true ].
^ searcher executeTree: aParseTree initialAnswer: false
]

{ #category : #private }
Expand Down Expand Up @@ -150,11 +149,6 @@ RBMoveTemporaryVariableDefinitionTransformation >> definingBlock [
^ definingNode
]

{ #category : #private }
RBMoveTemporaryVariableDefinitionTransformation >> parseTreeSearcher [
^ RBParseTreeSearcher new
]

{ #category : #preconditions }
RBMoveTemporaryVariableDefinitionTransformation >> preconditions [

Expand Down

0 comments on commit 930b73e

Please sign in to comment.