gui/PPExtractProdcutionRefactoring.st
author Claus Gittinger <cg@exept.de>
Wed, 05 Mar 2014 00:34:06 +0100
changeset 364 96239b58228c
parent 337 e1480829e5db
permissions -rw-r--r--
class: PPExtractProdcutionRefactoring changed: #nameNewMethod:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
337
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser/gui' }"
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
ExtractMethodRefactoring subclass:#PPExtractProdcutionRefactoring
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	instanceVariableNames:'targetProduction'
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	classVariableNames:''
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	poolDictionaries:''
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	category:'PetitGui-Refactoring'
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!PPExtractProdcutionRefactoring class methodsFor:'instance creation'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
onClass: aClass production: aSelector interval: anInterval to: aTargetSelector
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
	^ (self extract: anInterval from: aSelector in: aClass)
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
		setTargetProduction: aTargetSelector;
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
		yourself
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!PPExtractProdcutionRefactoring methodsFor:'initialization'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
setTargetProduction: aSymbol
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	targetProduction := aSymbol
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!PPExtractProdcutionRefactoring methodsFor:'preconditions'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
preconditions
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	^ (self checkCompositeParser: class)
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
		& super preconditions		
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
		& (RBCondition definesSelector: targetProduction asSymbol in: class) not
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
		& (RBCondition definesInstanceVariable: targetProduction asString in: class) not
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
!PPExtractProdcutionRefactoring methodsFor:'requests'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
shouldExtractAssignmentTo: aString
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
	^ false
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!PPExtractProdcutionRefactoring methodsFor:'transforming'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
existingSelector
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
	^ nil
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
getNewMethodName
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
	parameters isEmpty
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
		ifFalse: [ self refactoringError: 'Cannot extract production since it contains references.' ].
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
	targetProduction asSymbol isUnary
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
		ifFalse: [ self refactoringError: 'Invalid production name.' ].
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
	^ targetProduction asSymbol
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
nameNewMethod: aSymbol 
364
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    55
        class addInstanceVariable: aSymbol asString.
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    56
        extractedParseTree renameSelector: aSymbol andArguments: #().
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    57
        modifiedParseTree := ParseTreeRewriter 
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    58
                replace: self methodDelimiter
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    59
                with: aSymbol asString
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    60
                in: modifiedParseTree
337
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
!PPExtractProdcutionRefactoring class methodsFor:'documentation'!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
version
364
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    66
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/PPExtractProdcutionRefactoring.st,v 1.2 2014-03-04 23:34:06 cg Exp $'
337
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
version_CVS
364
96239b58228c class: PPExtractProdcutionRefactoring
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    70
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/gui/PPExtractProdcutionRefactoring.st,v 1.2 2014-03-04 23:34:06 cg Exp $'
337
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
! !
e1480829e5db initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72