author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 08 Oct 2015 09:41:03 +0100 | |
changeset 548 | 5536a6da50e4 |
parent 364 | 96239b58228c |
permissions | -rw-r--r-- |
337 | 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 |
|
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 | 61 |
! ! |
62 |
||
63 |
!PPExtractProdcutionRefactoring class methodsFor:'documentation'! |
|
64 |
||
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 | 67 |
! |
68 |
||
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 | 71 |
! ! |
72 |