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