Tools__MethodRewriter.st
changeset 15200 9e2705b68633
parent 14388 8f404d61e5c8
child 15202 31fdbb042c81
equal deleted inserted replaced
15199:9c150c84fdc9 15200:9e2705b68633
    30 ApplicationModel subclass:#MethodRewriter
    30 ApplicationModel subclass:#MethodRewriter
    31 	instanceVariableNames:'replaceTextView methods classes searchTextView
    31 	instanceVariableNames:'replaceTextView methods classes searchTextView
    32 		actionInProgresHolder infoHolder progressHolder
    32 		actionInProgresHolder infoHolder progressHolder
    33 		templateSearchPatternHolder templateReplacePatternHolder
    33 		templateSearchPatternHolder templateReplacePatternHolder
    34 		selectedTemplateIndex templates selectedTabIndex
    34 		selectedTemplateIndex templates selectedTabIndex
    35 		selectedClassesHolder'
    35 		selectedClassesHolder selectedRuleIndex rules
       
    36 		ruleReplacePatternHolder ruleSearchPatternHolder
       
    37 		ruleSearchAndReplacePatternHolder ruleForRewriteOrNilForAdHoc
       
    38 		adHocFindAndReplaceVisibleHolder ruleNameHolder'
    36 	classVariableNames:''
    39 	classVariableNames:''
    37 	poolDictionaries:''
    40 	poolDictionaries:''
    38 	category:'Interface-MethodRewriter'
    41 	category:'Interface-MethodRewriter'
    39 !
    42 !
    40 
    43 
   100         with: '``@receiver isNil ifTrue: ``@block'
   103         with: '``@receiver isNil ifTrue: ``@block'
   101 
   104 
   102     "Created: / 04-07-2011 / 19:25:06 / cg"
   105     "Created: / 04-07-2011 / 19:25:06 / cg"
   103 !
   106 !
   104 
   107 
       
   108 templateReplaceIfNotNilByNotNilIfTrue
       
   109 
       
   110     ^Array 
       
   111         with:('Replace ','ifNotNil:' allBold,' by ','notNil ifTrue:' allBold)
       
   112         with: '``@receiver ifNotNil: ``@block'
       
   113         with: '``@receiver notNil ifTrue: ``@block'
       
   114 !
       
   115 
   105 templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
   116 templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
   106 
   117 
   107     ^Array 
   118     ^Array 
   108         with:('Replace ','isNilOrEmptyCollection' allBold,' by ','isEmptyOrNil' allBold)
   119         with:('Replace ','isNilOrEmptyCollection' allBold,' by ','isEmptyOrNil' allBold)
   109         with: '``@receiver isNilOrEmptyCollection'
   120         with: '``@receiver isNilOrEmptyCollection'
   137     "Modified: / 17-02-2008 / 08:35:09 / janfrog"
   148     "Modified: / 17-02-2008 / 08:35:09 / janfrog"
   138     "Modified: / 04-07-2011 / 17:41:33 / cg"
   149     "Modified: / 04-07-2011 / 17:41:33 / cg"
   139 !
   150 !
   140 
   151 
   141 templates
   152 templates
   142 
   153     "finds all methods here, which start with 'template'"
   143     |templateSelectors|
   154 
       
   155     |templateSelectors templatesHere|
   144 
   156 
   145     templateSelectors := 
   157     templateSelectors := 
   146         (self class selectors select:[:e|(e startsWith:'template') 
   158         (self class selectors select:[:e|(e startsWith:'template') 
   147             and:[e ~= #templates and:[e ~= #templatesSpec]]]).
   159             and:[e ~= #templates and:[e ~= #templatesSpec]]]).
   148     ^templateSelectors 
   160 
   149         collect:[:e|self perform:e]
   161     templatesHere := templateSelectors collect:[:e| (self perform:e) copyWith:nil ].
   150 
   162     templatesHere := templatesHere sort:[:a :b | a first < b first].
   151     "
   163     ^ templatesHere 
   152         self templates
   164 
       
   165     "
       
   166      self templates
   153     "
   167     "
   154 
   168 
   155     "Created: / 12-12-2007 / 11:03:32 / janfrog"
   169     "Created: / 12-12-2007 / 11:03:32 / janfrog"
   156 ! !
   170 ! !
   157 
   171 
   170     "
   184     "
   171 
   185 
   172     <resource: #canvas>
   186     <resource: #canvas>
   173 
   187 
   174     ^ 
   188     ^ 
   175      #(FullSpec
   189     #(FullSpec
   176         name: classesSpec
   190        name: classesSpec
   177         window: 
   191        window: 
   178        (WindowSpec
   192       (WindowSpec
   179           label: 'Classes'
   193          label: 'Classes'
   180           name: 'Classes'
   194          name: 'Classes'
   181           min: (Point 10 10)
   195          min: (Point 10 10)
   182           bounds: (Rectangle 0 0 300 300)
   196          bounds: (Rectangle 0 0 300 300)
   183         )
   197        )
   184         component: 
   198        component: 
   185        (SpecCollection
   199       (SpecCollection
   186           collection: (
   200          collection: (
   187            (LabelSpec
   201           (LabelSpec
   188               label: 'Hint: drag''n''drop classes from browser'
   202              label: 'Hint: drag''n''drop classes from browser'
   189               name: 'HintLabel'
   203              name: 'HintLabel'
   190               layout: (LayoutFrame 0 0 0 0 0 1 30 0)
   204              layout: (LayoutFrame 0 0 0 0 0 1 30 0)
   191               translateLabel: true
   205              translateLabel: true
   192               adjust: left
   206              adjust: left
   193             )
       
   194            (SelectionInListModelViewSpec
       
   195               name: 'ClassesList'
       
   196               layout: (LayoutFrame 0 0 30 0 0 1 -30 1)
       
   197               model: selectedClassesHolder
       
   198               hasHorizontalScrollBar: true
       
   199               hasVerticalScrollBar: true
       
   200               listModel: classes
       
   201               multipleSelectOk: true
       
   202               useIndex: false
       
   203               highlightMode: line
       
   204               properties: 
       
   205              (PropertyListDictionary
       
   206                 dragArgument: nil
       
   207                 dropArgument: nil
       
   208                 canDropSelector: canDropClasses:
       
   209                 dropSelector: doDropClasses:
       
   210               )
       
   211             )
       
   212            (ActionButtonSpec
       
   213               label: 'Remove selected classes'
       
   214               name: 'RemoveClassesButton'
       
   215               layout: (LayoutFrame 5 0 -25 1 -5 1 -5 1)
       
   216               translateLabel: true
       
   217               model: removeSeletedClassesAction
       
   218             )
       
   219            )
   207            )
   220          
   208           (SelectionInListModelViewSpec
   221         )
   209              name: 'ClassesList'
   222       )
   210              layout: (LayoutFrame 0 0 30 0 0 1 -30 1)
   223 
   211              model: selectedClassesHolder
   224     "Modified: / 12-12-2007 / 12:07:17 / janfrog"
   212              hasHorizontalScrollBar: true
       
   213              hasVerticalScrollBar: true
       
   214              listModel: classes
       
   215              multipleSelectOk: true
       
   216              useIndex: false
       
   217              highlightMode: line
       
   218              properties: 
       
   219             (PropertyListDictionary
       
   220                canDropSelector: canDropClasses:
       
   221                dropArgument: nil
       
   222                dropSelector: doDropClasses:
       
   223                dragArgument: nil
       
   224              )
       
   225            )
       
   226           (HorizontalPanelViewSpec
       
   227              name: 'HorizontalPanel1'
       
   228              layout: (LayoutFrame 0 0 -30 1 -16 1 0 1)
       
   229              horizontalLayout: center
       
   230              verticalLayout: center
       
   231              horizontalSpace: 3
       
   232              verticalSpace: 3
       
   233              component: 
       
   234             (SpecCollection
       
   235                collection: (
       
   236                 (ActionButtonSpec
       
   237                    label: 'Remove Selected Classes'
       
   238                    name: 'RemoveClassesButton'
       
   239                    translateLabel: true
       
   240                    model: removeSeletedClassesAction
       
   241                    useDefaultExtent: true
       
   242                  )
       
   243                 )
       
   244               
       
   245              )
       
   246              keepSpaceForOSXResizeHandleH: true
       
   247            )
       
   248           )
       
   249         
       
   250        )
       
   251      )
       
   252 !
       
   253 
       
   254 howToUseSpec
       
   255     "This resource specification was automatically generated
       
   256      by the UIPainter of ST/X."
       
   257 
       
   258     "Do not manually edit this!! If it is corrupted,
       
   259      the UIPainter may not be able to read the specification."
       
   260 
       
   261     "
       
   262      UIPainter new openOnClass:Tools::MethodRewriter andSelector:#howToUseSpec
       
   263      Tools::MethodRewriter new openInterface:#howToUseSpec
       
   264     "
       
   265 
       
   266     <resource: #canvas>
       
   267 
       
   268     ^ 
       
   269     #(FullSpec
       
   270        name: howToUseSpec
       
   271        window: 
       
   272       (WindowSpec
       
   273          label: 'Classes'
       
   274          name: 'Classes'
       
   275          min: (Point 10 10)
       
   276          bounds: (Rectangle 0 0 300 300)
       
   277        )
       
   278        component: 
       
   279       (SpecCollection
       
   280          collection: (
       
   281           (HTMLViewSpec
       
   282              name: 'HTMLBrowser1'
       
   283              layout: (LayoutFrame 0 0 0 0 0 1 0 1)
       
   284              model: howToUseRewriteToolURL
       
   285              hasHorizontalScrollBar: true
       
   286              hasVerticalScrollBar: true
       
   287            )
       
   288           )
       
   289         
       
   290        )
       
   291      )
       
   292 !
       
   293 
       
   294 rulesSpec
       
   295     "This resource specification was automatically generated
       
   296      by the UIPainter of ST/X."
       
   297 
       
   298     "Do not manually edit this!! If it is corrupted,
       
   299      the UIPainter may not be able to read the specification."
       
   300 
       
   301     "
       
   302      UIPainter new openOnClass:Tools::MethodRewriter andSelector:#rulesSpec
       
   303      Tools::MethodRewriter new openInterface:#rulesSpec
       
   304     "
       
   305 
       
   306     <resource: #canvas>
       
   307 
       
   308     ^ 
       
   309     #(FullSpec
       
   310        name: rulesSpec
       
   311        window: 
       
   312       (WindowSpec
       
   313          label: 'Method Rewriter'
       
   314          name: 'Method Rewriter'
       
   315          min: (Point 10 10)
       
   316          bounds: (Rectangle 0 0 472 354)
       
   317        )
       
   318        component: 
       
   319       (SpecCollection
       
   320          collection: (
       
   321           (VariableVerticalPanelSpec
       
   322              name: 'FindAndReplacePanel'
       
   323              layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
       
   324              showHandle: true
       
   325              snapMode: both
       
   326              component: 
       
   327             (SpecCollection
       
   328                collection: (
       
   329                 (SelectionInListModelViewSpec
       
   330                    name: 'SelectionInListModelView1'
       
   331                    model: selectedRuleIndex
       
   332                    hasHorizontalScrollBar: true
       
   333                    hasVerticalScrollBar: true
       
   334                    listModel: ruleNameList
       
   335                    highlightMode: line
       
   336                  )
       
   337                 (ViewSpec
       
   338                    name: 'ReplaceBox'
       
   339                    component: 
       
   340                   (SpecCollection
       
   341                      collection: (
       
   342                       (LabelSpec
       
   343                          label: 'Finds and Replaces With:'
       
   344                          name: 'ReplaceLabel'
       
   345                          layout: (LayoutFrame 0 0 0 0 0 1 20 0)
       
   346                          translateLabel: true
       
   347                          adjust: left
       
   348                        )
       
   349                       (TextEditorSpec
       
   350                          name: 'ReplaceText'
       
   351                          layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   352                          model: ruleSearchAndReplacePatternHolder
       
   353                          hasHorizontalScrollBar: true
       
   354                          hasVerticalScrollBar: true
       
   355                          isReadOnly: true
       
   356                          hasKeyboardFocusInitially: false
       
   357                        )
       
   358                       )
       
   359                     
       
   360                    )
       
   361                  )
       
   362                 )
       
   363               
       
   364              )
       
   365              handles: (Any 0.5 1.0)
       
   366            )
       
   367           (HorizontalPanelViewSpec
       
   368              name: 'HorizontalPanel1'
       
   369              layout: (LayoutFrame 0 0 -30 1 -16 1 0 1)
       
   370              horizontalLayout: center
       
   371              verticalLayout: center
       
   372              horizontalSpace: 3
       
   373              verticalSpace: 3
       
   374              component: 
       
   375             (SpecCollection
       
   376                collection: (
       
   377                 (ActionButtonSpec
       
   378                    label: 'Use Rule'
       
   379                    name: 'UseAsRuleButton'
       
   380                    translateLabel: true
       
   381                    model: useAsRuleAction
       
   382                    useDefaultExtent: true
       
   383                  )
       
   384                 )
       
   385               
       
   386              )
       
   387              keepSpaceForOSXResizeHandleH: true
       
   388            )
       
   389           )
       
   390         
       
   391        )
       
   392      )
   225 !
   393 !
   226 
   394 
   227 searchAndReplaceSpec
   395 searchAndReplaceSpec
   228     "This resource specification was automatically generated
   396     "This resource specification was automatically generated
   229      by the UIPainter of ST/X."
   397      by the UIPainter of ST/X."
   237     "
   405     "
   238 
   406 
   239     <resource: #canvas>
   407     <resource: #canvas>
   240 
   408 
   241     ^ 
   409     ^ 
   242      #(FullSpec
   410     #(FullSpec
   243         name: searchAndReplaceSpec
   411        name: searchAndReplaceSpec
   244         window: 
   412        window: 
   245        (WindowSpec
   413       (WindowSpec
   246           label: 'Method Rewriter'
   414          label: 'Method Rewriter'
   247           name: 'Method Rewriter'
   415          name: 'Method Rewriter'
   248           min: (Point 10 10)
   416          min: (Point 10 10)
   249           bounds: (Rectangle 0 0 418 294)
   417          bounds: (Rectangle 0 0 418 294)
   250         )
   418        )
   251         component: 
   419        component: 
   252        (SpecCollection
   420       (SpecCollection
   253           collection: (
   421          collection: (
   254            (VariableVerticalPanelSpec
   422           (VariableVerticalPanelSpec
   255               name: 'FindAndReplacePanel'
   423              name: 'FindAndReplacePanel'
   256               layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
   424              layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
   257               showHandle: true
   425              visibilityChannel: adHocFindAndReplaceVisibleHolder
   258               snapMode: both
   426              showHandle: true
   259               component: 
   427              snapMode: both
   260              (SpecCollection
   428              component: 
   261                 collection: (
   429             (SpecCollection
   262                  (ViewSpec
   430                collection: (
   263                     name: 'FindBox'
   431                 (ViewSpec
   264                     component: 
   432                    name: 'FindBox'
   265                    (SpecCollection
   433                    component: 
   266                       collection: (
   434                   (SpecCollection
   267                        (LabelSpec
   435                      collection: (
   268                           label: 'Find:'
   436                       (LabelSpec
   269                           name: 'FindLabel'
   437                          label: 'Find:'
   270                           layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   438                          name: 'FindLabel'
   271                           translateLabel: true
   439                          layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   272                           adjust: left
   440                          translateLabel: true
   273                         )
   441                          adjust: left
   274                        (TextEditorSpec
       
   275                           name: 'FindText'
       
   276                           layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   277                           hasHorizontalScrollBar: true
       
   278                           hasVerticalScrollBar: true
       
   279                           postBuildCallback: postBuildFindTextView:
       
   280                         )
       
   281                        )
   442                        )
   282                      
   443                       (TextEditorSpec
   283                     )
   444                          name: 'FindText'
   284                   )
   445                          layout: (LayoutFrame 0 0 20 0 0 1 0 1)
   285                  (ViewSpec
   446                          hasHorizontalScrollBar: true
   286                     name: 'ReplaceBox'
   447                          hasVerticalScrollBar: true
   287                     component: 
   448                          hasKeyboardFocusInitially: false
   288                    (SpecCollection
   449                          postBuildCallback: postBuildFindTextView:
   289                       collection: (
       
   290                        (LabelSpec
       
   291                           label: 'Replace with:'
       
   292                           name: 'ReplaceLabel'
       
   293                           layout: (LayoutFrame 0 0 0 0 0 1 20 0)
       
   294                           translateLabel: true
       
   295                           adjust: left
       
   296                         )
       
   297                        (TextEditorSpec
       
   298                           name: 'ReplaceText'
       
   299                           layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   300                           hasHorizontalScrollBar: true
       
   301                           hasVerticalScrollBar: true
       
   302                           postBuildCallback: postBuildReplaceTextView:
       
   303                         )
       
   304                        )
   450                        )
   305                      
   451                       )
   306                     )
   452                     
   307                   )
   453                    )
   308                  )
   454                  )
   309                
   455                 (ViewSpec
   310               )
   456                    name: 'ReplaceBox'
   311               handles: (Any 0.5 1.0)
   457                    component: 
   312             )
   458                   (SpecCollection
   313            (LabelSpec
   459                      collection: (
   314               label: 'Enjoy'
   460                       (LabelSpec
   315               name: 'InfoLabel'
   461                          label: 'Replace with:'
   316               layout: (LayoutFrame 5 0 -25 1 205 0 -5 1)
   462                          name: 'ReplaceLabel'
   317               visibilityChannel: actionInProgresHolder
   463                          layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   318               translateLabel: true
   464                          translateLabel: true
   319               labelChannel: infoHolder
   465                          adjust: left
   320               adjust: left
   466                        )
   321             )
   467                       (TextEditorSpec
   322            (ProgressIndicatorSpec
   468                          name: 'ReplaceText'
   323               name: 'ProgressIndicator'
   469                          layout: (LayoutFrame 0 0 20 0 0 1 0 1)
   324               layout: (LayoutFrame 210 0 -25 1 -215 1 -5 1)
   470                          hasHorizontalScrollBar: true
   325               visibilityChannel: actionInProgresHolder
   471                          hasVerticalScrollBar: true
   326               model: progressHolder
   472                          hasKeyboardFocusInitially: false
   327             )
   473                          postBuildCallback: postBuildReplaceTextView:
   328            (ActionButtonSpec
   474                        )
   329               label: 'Search'
   475                       )
   330               name: 'SearchButton'
   476                     
   331               layout: (LayoutFrame -210 1 -25 1 -110 1 -5 1)
   477                    )
   332               translateLabel: true
   478                  )
   333               model: doSearchAction
   479                 )
   334             )
   480               
   335            (ActionButtonSpec
   481              )
   336               label: 'Rewrite'
   482              handles: (Any 0.5 1.0)
   337               name: 'RewriteButton'
       
   338               layout: (LayoutFrame -105 1 -25 1 -5 1 -5 1)
       
   339               translateLabel: true
       
   340               model: doRewriteAction
       
   341             )
       
   342            )
   483            )
   343          
   484           (ViewSpec
   344         )
   485              name: 'ExecuteRuleBox'
   345       )
   486              layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
   346 
   487              visibilityChannel: ruleExecutionVisibleHolder
   347     "Modified: / 12-12-2007 / 11:15:58 / janfrog"
   488              component: 
       
   489             (SpecCollection
       
   490                collection: (
       
   491                 (LabelSpec
       
   492                    label: 'Rule:'
       
   493                    name: 'Label2'
       
   494                    layout: (LayoutFrame 0 0 0 0 100 0 25 0)
       
   495                    translateLabel: true
       
   496                    adjust: left
       
   497                  )
       
   498                 (LabelSpec
       
   499                    name: 'Label4'
       
   500                    layout: (LayoutFrame 100 0 0 0 0 1 25 0)
       
   501                    translateLabel: true
       
   502                    labelChannel: ruleNameHolder
       
   503                  )
       
   504                 (TextEditorSpec
       
   505                    name: 'TextEditor1'
       
   506                    layout: (LayoutFrame 0 0 25 0 0 1 0 1)
       
   507                    model: ruleSearchAndReplacePatternHolder
       
   508                    hasHorizontalScrollBar: true
       
   509                    hasVerticalScrollBar: true
       
   510                    isReadOnly: true
       
   511                    hasKeyboardFocusInitially: false
       
   512                  )
       
   513                 )
       
   514               
       
   515              )
       
   516            )
       
   517           (ViewSpec
       
   518              name: 'Box1'
       
   519              layout: (LayoutFrame 0 0 -30 1 -16 1 0 1)
       
   520              component: 
       
   521             (SpecCollection
       
   522                collection: (
       
   523                 (LabelSpec
       
   524                    label: 'Enjoy'
       
   525                    name: 'Label1'
       
   526                    layout: (LayoutFrame 5 0 -25 1 205 0 -5 1)
       
   527                    visibilityChannel: actionInProgresHolder
       
   528                    translateLabel: true
       
   529                    labelChannel: infoHolder
       
   530                    adjust: left
       
   531                  )
       
   532                 (ProgressIndicatorSpec
       
   533                    name: 'ProgressIndicator1'
       
   534                    layout: (LayoutFrame 210 0 -25 1 -215 1 -5 1)
       
   535                    visibilityChannel: actionInProgresHolder
       
   536                    model: progressHolder
       
   537                  )
       
   538                 (ActionButtonSpec
       
   539                    label: 'Search'
       
   540                    name: 'Button2'
       
   541                    layout: (LayoutFrame -210 1 -26 1 -110 1 -5 1)
       
   542                    translateLabel: true
       
   543                    model: doSearchAction
       
   544                  )
       
   545                 (ActionButtonSpec
       
   546                    label: 'Rewrite'
       
   547                    name: 'Button1'
       
   548                    layout: (LayoutFrame -105 1 -25 1 -5 1 -5 1)
       
   549                    translateLabel: true
       
   550                    model: doRewriteAction
       
   551                  )
       
   552                 )
       
   553               
       
   554              )
       
   555              keepSpaceForOSXResizeHandleH: true
       
   556            )
       
   557           )
       
   558         
       
   559        )
       
   560      )
       
   561 !
       
   562 
       
   563 searchPatternHelpSpec
       
   564     "This resource specification was automatically generated
       
   565      by the UIPainter of ST/X."
       
   566 
       
   567     "Do not manually edit this!! If it is corrupted,
       
   568      the UIPainter may not be able to read the specification."
       
   569 
       
   570     "
       
   571      UIPainter new openOnClass:Tools::MethodRewriter andSelector:#searchPatternHelpSpec
       
   572      Tools::MethodRewriter new openInterface:#searchPatternHelpSpec
       
   573     "
       
   574 
       
   575     <resource: #canvas>
       
   576 
       
   577     ^ 
       
   578     #(FullSpec
       
   579        name: searchPatternHelpSpec
       
   580        window: 
       
   581       (WindowSpec
       
   582          label: 'Classes'
       
   583          name: 'Classes'
       
   584          min: (Point 10 10)
       
   585          bounds: (Rectangle 0 0 300 300)
       
   586        )
       
   587        component: 
       
   588       (SpecCollection
       
   589          collection: (
       
   590           (HTMLViewSpec
       
   591              name: 'HTMLBrowser1'
       
   592              layout: (LayoutFrame 0 0 0 0 0 1 0 1)
       
   593              model: searchPatternHelpURL
       
   594              hasHorizontalScrollBar: true
       
   595              hasVerticalScrollBar: true
       
   596            )
       
   597           )
       
   598         
       
   599        )
       
   600      )
   348 !
   601 !
   349 
   602 
   350 templatesSpec
   603 templatesSpec
   351     "This resource specification was automatically generated
   604     "This resource specification was automatically generated
   352      by the UIPainter of ST/X."
   605      by the UIPainter of ST/X."
   360     "
   613     "
   361 
   614 
   362     <resource: #canvas>
   615     <resource: #canvas>
   363 
   616 
   364     ^ 
   617     ^ 
   365      #(FullSpec
   618     #(FullSpec
   366         name: templatesSpec
   619        name: templatesSpec
   367         window: 
   620        window: 
   368        (WindowSpec
   621       (WindowSpec
   369           label: 'Method Rewriter'
   622          label: 'Method Rewriter'
   370           name: 'Method Rewriter'
   623          name: 'Method Rewriter'
   371           min: (Point 10 10)
   624          min: (Point 10 10)
   372           bounds: (Rectangle 0 0 472 354)
   625          bounds: (Rectangle 0 0 472 354)
   373         )
   626        )
   374         component: 
   627        component: 
   375        (SpecCollection
   628       (SpecCollection
   376           collection: (
   629          collection: (
   377            (VariableVerticalPanelSpec
   630           (VariableVerticalPanelSpec
   378               name: 'FindAndReplacePanel'
   631              name: 'FindAndReplacePanel'
   379               layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
   632              layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
   380               showHandle: true
   633              showHandle: true
   381               snapMode: both
   634              snapMode: both
   382               component: 
   635              component: 
   383              (SpecCollection
   636             (SpecCollection
   384                 collection: (
   637                collection: (
   385                  (SelectionInListModelViewSpec
   638                 (SelectionInListModelViewSpec
   386                     name: 'SelectionInListModelView1'
   639                    name: 'SelectionInListModelView1'
   387                     model: selectedTemplateIndex
   640                    model: selectedTemplateIndex
   388                     hasHorizontalScrollBar: true
   641                    hasHorizontalScrollBar: true
   389                     hasVerticalScrollBar: true
   642                    hasVerticalScrollBar: true
   390                     listModel: templateNameList
   643                    listModel: templateNameList
   391                     highlightMode: line
   644                    highlightMode: line
   392                   )
   645                  )
   393                  (ViewSpec
   646                 (ViewSpec
   394                     name: 'FindBox'
   647                    name: 'FindBox'
   395                     component: 
   648                    component: 
   396                    (SpecCollection
   649                   (SpecCollection
   397                       collection: (
   650                      collection: (
   398                        (LabelSpec
   651                       (LabelSpec
   399                           label: 'Find:'
   652                          label: 'Find:'
   400                           name: 'FindLabel'
   653                          name: 'FindLabel'
   401                           layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   654                          layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   402                           translateLabel: true
   655                          translateLabel: true
   403                           adjust: left
   656                          adjust: left
   404                         )
       
   405                        (TextEditorSpec
       
   406                           name: 'FindText'
       
   407                           layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   408                           model: templateSearchPatternHolder
       
   409                           hasHorizontalScrollBar: true
       
   410                           hasVerticalScrollBar: true
       
   411                         )
       
   412                        )
   657                        )
   413                      
   658                       (TextEditorSpec
   414                     )
   659                          name: 'FindText'
   415                   )
   660                          layout: (LayoutFrame 0 0 20 0 0 1 0 1)
   416                  (ViewSpec
   661                          enableChannel: templateSearchPatternIsEditable
   417                     name: 'ReplaceBox'
   662                          model: templateSearchPatternHolder
   418                     component: 
   663                          hasHorizontalScrollBar: true
   419                    (SpecCollection
   664                          hasVerticalScrollBar: true
   420                       collection: (
   665                          hasKeyboardFocusInitially: false
   421                        (LabelSpec
       
   422                           label: 'Replace with:'
       
   423                           name: 'ReplaceLabel'
       
   424                           layout: (LayoutFrame 0 0 0 0 0 1 20 0)
       
   425                           translateLabel: true
       
   426                           adjust: left
       
   427                         )
       
   428                        (TextEditorSpec
       
   429                           name: 'ReplaceText'
       
   430                           layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   431                           model: templateReplacePatternHolder
       
   432                           hasHorizontalScrollBar: true
       
   433                           hasVerticalScrollBar: true
       
   434                         )
       
   435                        )
   666                        )
   436                      
   667                       )
   437                     )
   668                     
   438                   )
   669                    )
   439                  )
   670                  )
   440                
   671                 (ViewSpec
   441               )
   672                    name: 'ReplaceBox'
   442               handles: (Any 0.2 0.6 1.0)
   673                    component: 
   443             )
   674                   (SpecCollection
   444            (ActionButtonSpec
   675                      collection: (
   445               label: 'Use as template'
   676                       (LabelSpec
   446               name: 'UseAsTemplateButton'
   677                          label: 'Replace With:'
   447               layout: (LayoutFrame 0 0 -25 1 -5 1 -5 1)
   678                          name: 'ReplaceLabel'
   448               translateLabel: true
   679                          layout: (LayoutFrame 0 0 0 0 0 1 20 0)
   449               model: useAsTemplateAction
   680                          translateLabel: true
   450             )
   681                          adjust: left
       
   682                        )
       
   683                       (TextEditorSpec
       
   684                          name: 'ReplaceText'
       
   685                          layout: (LayoutFrame 0 0 20 0 0 1 0 1)
       
   686                          enableChannel: templateReplacePatternIsEditable
       
   687                          model: templateReplacePatternHolder
       
   688                          hasHorizontalScrollBar: true
       
   689                          hasVerticalScrollBar: true
       
   690                          hasKeyboardFocusInitially: false
       
   691                        )
       
   692                       )
       
   693                     
       
   694                    )
       
   695                  )
       
   696                 )
       
   697               
       
   698              )
       
   699              handles: (Any 0.20000000000000001 0.59999999999999998 1.0)
   451            )
   700            )
   452          
   701           (HorizontalPanelViewSpec
   453         )
   702              name: 'HorizontalPanel1'
   454       )
   703              layout: (LayoutFrame 0 0 -30 1 -16 1 0 1)
   455 
   704              horizontalLayout: center
   456     "Modified: / 12-12-2007 / 11:23:34 / janfrog"
   705              verticalLayout: center
       
   706              horizontalSpace: 3
       
   707              verticalSpace: 3
       
   708              component: 
       
   709             (SpecCollection
       
   710                collection: (
       
   711                 (ActionButtonSpec
       
   712                    label: 'Use as Template'
       
   713                    name: 'UseAsTemplateButton'
       
   714                    translateLabel: true
       
   715                    model: useAsTemplateAction
       
   716                    useDefaultExtent: true
       
   717                  )
       
   718                 )
       
   719               
       
   720              )
       
   721              keepSpaceForOSXResizeHandleH: true
       
   722            )
       
   723           )
       
   724         
       
   725        )
       
   726      )
   457 !
   727 !
   458 
   728 
   459 windowSpec
   729 windowSpec
   460     "This resource specification was automatically generated
   730     "This resource specification was automatically generated
   461      by the UIPainter of ST/X."
   731      by the UIPainter of ST/X."
   529        (TabItem
   799        (TabItem
   530           label: 'Templates'
   800           label: 'Templates'
   531           createNewBuilder: false
   801           createNewBuilder: false
   532           minorKey: templatesSpec
   802           minorKey: templatesSpec
   533         )
   803         )
       
   804        (TabItem
       
   805           label: 'Existing Rules'
       
   806           createNewBuilder: false
       
   807           minorKey: rulesSpec
       
   808         )
       
   809        (TabItem
       
   810           label: 'How To Use This Tool'
       
   811           createNewBuilder: false
       
   812           minorKey: howToUseSpec
       
   813         )
       
   814        (TabItem
       
   815           label: 'Pattern Info'
       
   816           createNewBuilder: false
       
   817           minorKey: searchPatternHelpSpec
       
   818         )
   534        )
   819        )
   535      
   820      
   536       collect:[:aTab| TabItem new fromLiteralArrayEncoding:aTab ]
   821       collect:[:aTab| TabItem new fromLiteralArrayEncoding:aTab ]
   537 
   822 
   538     "Modified: / 12-12-2007 / 11:21:27 / janfrog"
   823     "Modified: / 12-12-2007 / 11:21:27 / janfrog"
   584     ^ replaceTextView contents: pattern trimSeparators
   869     ^ replaceTextView contents: pattern trimSeparators
   585 
   870 
   586     "Created: / 12-12-2007 / 11:38:22 / janfrog"
   871     "Created: / 12-12-2007 / 11:38:22 / janfrog"
   587 !
   872 !
   588 
   873 
       
   874 ruleTemplate
       
   875 
       
   876     ^self rules at:self selectedRuleIndex value
       
   877 !
       
   878 
       
   879 rules
       
   880     rules isNil ifTrue:[
       
   881         |knownRules separator1 separator2 separator3|
       
   882 
       
   883         "/ construct a pseudo list from existing transformation rules
       
   884         separator1 := '----------- search for:' asText colorizeAllWith:Color grey.
       
   885         separator2 := '----------- replace by:' asText colorizeAllWith:Color grey.   
       
   886         separator3 := '\=================================================================================\' withCRs asText colorizeAllWith:Color grey.
       
   887 
       
   888         knownRules := OrderedCollection new.
       
   889         (RBTransformationRule allSubclasses asNewOrderedCollection sort:[:a :b | a basicNew name < b basicNew name]) 
       
   890         do:[:each |
       
   891             |rule | 
       
   892 
       
   893             rule := each new.
       
   894             knownRules add:{ rule .
       
   895                              (rule rewriteRule searches 
       
   896                                 collectAll:[:each |
       
   897                                     { 
       
   898                                       separator1.
       
   899                                       each searchString 
       
   900                                         asText backgroundColorizeAllWith:(Color red lightened lightened lightened) .
       
   901                                       separator2.
       
   902                                       each replaceString asText 
       
   903                                         asText backgroundColorizeAllWith:(Color green lightened lightened lightened) .
       
   904                                       separator3
       
   905                                     }
       
   906                                 ]
       
   907                              ) asStringCollection asString.
       
   908                            }
       
   909         ].
       
   910 
       
   911         rules := knownRules
       
   912     ].
       
   913     ^ rules
       
   914 
       
   915     "
       
   916      self new rules
       
   917     "
       
   918 !
       
   919 
   589 searchPattern
   920 searchPattern
   590     ^ searchTextView contents trimSeparators
   921     ^ searchTextView contents trimSeparators
   591 
   922 
   592     "Created: / 20-07-2007 / 16:51:49 / janfrog"
   923     "Created: / 20-07-2007 / 16:51:49 / janfrog"
   593     "Modified: / 21-07-2007 / 06:29:29 / janfrog"
   924     "Modified: / 21-07-2007 / 06:29:29 / janfrog"
   602 selectedClasses
   933 selectedClasses
   603 
   934 
   604     ^self selectedClassesHolder value
   935     ^self selectedClassesHolder value
   605 
   936 
   606     "Created: / 12-12-2007 / 12:02:03 / janfrog"
   937     "Created: / 12-12-2007 / 12:02:03 / janfrog"
       
   938 !
       
   939 
       
   940 selectedRule
       
   941 
       
   942     ^self selectedRuleSpec first
       
   943 !
       
   944 
       
   945 selectedRuleSpec
       
   946 
       
   947     ^self rules at:(self selectedRuleIndex value)
   607 !
   948 !
   608 
   949 
   609 selectedTemplate
   950 selectedTemplate
   610 
   951 
   611     ^self templates at:self selectedTemplateIndex value
   952     ^self templates at:self selectedTemplateIndex value
   621 
   962 
   622     "Created: / 12-12-2007 / 11:17:55 / janfrog"
   963     "Created: / 12-12-2007 / 11:17:55 / janfrog"
   623 ! !
   964 ! !
   624 
   965 
   625 !MethodRewriter methodsFor:'actions'!
   966 !MethodRewriter methodsFor:'actions'!
   626 
       
   627 doRewrite
       
   628     | methodsMatching anyChange compositeChangeCollector |
       
   629 
       
   630     compositeChangeCollector := CompositeRefactoryChange new.
       
   631     compositeChangeCollector name:'Rewrite Change'.
       
   632 
       
   633     anyChange := false.
       
   634 
       
   635     methodsMatching := self methodsMatching.
       
   636     methodsMatching isEmptyOrNil ifTrue:[^Dialog warn:'No methods matching'].
       
   637     methodsMatching do:[:mth|
       
   638         | newTree change |
       
   639 
       
   640         newTree := ParseTreeRewriter new
       
   641                     replace: self searchPattern 
       
   642                     with: self replacePattern;
       
   643                     executeTree: mth parseTree;
       
   644                     tree.
       
   645 
       
   646         change := InteractiveAddMethodChange compile:(newTree formattedCode) in:mth mclass classified:mth category.
       
   647 
       
   648         "/ collect in order to have only one change in the undo-list (instead of many)
       
   649         compositeChangeCollector addChange:change.
       
   650         anyChange := true.
       
   651 
       
   652 "/        mth mclass 
       
   653 "/            compile: newTree formattedCode
       
   654 "/            classified: mth category
       
   655     ].
       
   656 
       
   657     anyChange ifTrue:[
       
   658         RefactoryChangeManager performChange:compositeChangeCollector.
       
   659     ].
       
   660 
       
   661     "Created: / 20-07-2007 / 16:03:47 / janfrog"
       
   662     "Modified: / 21-07-2007 / 06:55:42 / janfrog"
       
   663     "Modified: / 04-08-2011 / 19:05:25 / cg"
       
   664 !
       
   665 
   967 
   666 doRewrite: methodsMatching
   968 doRewrite: methodsMatching
   667     | changes compositeChangeCollector |
   969     | changes compositeChangeCollector |
   668 
   970 
   669     changes := ChangeSet new name:'Rewrite Changes'.    
   971     changes := ChangeSet new name:'Rewrite Changes'.    
   707     "Created: / 22-03-2012 / 18:22:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1009     "Created: / 22-03-2012 / 18:22:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   708 !
  1010 !
   709 
  1011 
   710 doRewriteAction
  1012 doRewriteAction
   711 
  1013 
   712     self doSearch: self searchPattern withResultDo: [:methodsMatching|
  1014     self replacePattern isEmptyOrNil ifTrue:[
   713         self doRewrite:  methodsMatching
  1015         (Dialog confirm:'No replace-pattern given.\\Proceed to delete that code.') ifFalse:[
   714     ].
  1016             AbortSignal raise
       
  1017         ].
       
  1018     ].
       
  1019 
       
  1020     self 
       
  1021         doSearchPattern: self searchPattern 
       
  1022         withResultDo: [:methodsMatching|
       
  1023             self doRewrite:  methodsMatching
       
  1024         ].
   715 
  1025 
   716     "Created: / 12-12-2007 / 11:14:19 / janfrog"
  1026     "Created: / 12-12-2007 / 11:14:19 / janfrog"
   717     "Modified: / 22-03-2012 / 18:23:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1027     "Modified: / 22-03-2012 / 18:23:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   718 !
  1028 !
   719 
  1029 
   720 doSearch
       
   721     |methods|
       
   722 
       
   723     methods := self methodsMatching.
       
   724     methods isEmpty 
       
   725         ifTrue:
       
   726             [Dialog warn:'Nothing found']
       
   727         ifFalse:
       
   728             [self showMethods:methods
       
   729                   title:'Methods matching ' , self searchPattern]
       
   730 
       
   731     "Created: / 20-07-2007 / 16:08:08 / janfrog"
       
   732     "Modified: / 21-07-2007 / 06:51:58 / janfrog"
       
   733 !
       
   734 
       
   735 doSearchAction
  1030 doSearchAction
   736 
  1031     |methods what|
   737    self 
  1032 
   738         doSearch: self searchPattern 
  1033     ruleForRewriteOrNilForAdHoc notNil ifTrue:[
   739         withResultDo: 
  1034        self 
   740             [:matchingMethods|
  1035             doSearchRule: self selectedRule 
   741             matchingMethods isEmpty
  1036             withResultDo:[:matchingMethods|
   742                 ifTrue:[Dialog warn:'No methods found']
  1037                 matchingMethods isEmpty
   743                 ifFalse:
  1038                     ifTrue:[
   744                     [self
  1039                         Dialog warn:'No methods found by rule: ', self selectedRule name
   745                         showMethods: matchingMethods asArray
  1040                     ]
   746                         title: 'Methods matching ', self searchPattern]]
  1041                     ifFalse:[
       
  1042                         self
       
  1043                             showMethods: matchingMethods asArray
       
  1044                             title: 'Methods matching rule: ', self selectedRule name
       
  1045                     ]
       
  1046             ]
       
  1047     ] ifFalse:[
       
  1048        self 
       
  1049             doSearchPattern: self searchPattern 
       
  1050             withResultDo:[:matchingMethods|
       
  1051                 matchingMethods isEmpty
       
  1052                     ifTrue:[
       
  1053                         Dialog warn:'No methods found for search pattern'
       
  1054                     ]
       
  1055                     ifFalse:[
       
  1056                         self
       
  1057                             showMethods: matchingMethods asArray
       
  1058                             title: 'Methods matching ', self searchPattern
       
  1059                     ]
       
  1060             ]
       
  1061     ]
   747 
  1062 
   748     "Created: / 12-12-2007 / 11:14:25 / janfrog"
  1063     "Created: / 12-12-2007 / 11:14:25 / janfrog"
   749 !
  1064 !
   750 
  1065 
   751 removeSeletedClassesAction
  1066 removeSeletedClassesAction
   753     self classes removeAll: self selectedClasses
  1068     self classes removeAll: self selectedClasses
   754 
  1069 
   755     "Created: / 12-12-2007 / 12:05:15 / janfrog"
  1070     "Created: / 12-12-2007 / 12:05:15 / janfrog"
   756 !
  1071 !
   757 
  1072 
       
  1073 useAsRuleAction
       
  1074     self adHocFindAndReplaceVisibleHolder value:false.
       
  1075     ruleForRewriteOrNilForAdHoc := self selectedRule.
       
  1076     ruleNameHolder value: ruleForRewriteOrNilForAdHoc name.
       
  1077     
       
  1078     self selectedTabIndex value:1
       
  1079 !
       
  1080 
   758 useAsTemplateAction
  1081 useAsTemplateAction
   759 
  1082     self adHocFindAndReplaceVisibleHolder value:true.
       
  1083     ruleForRewriteOrNilForAdHoc := nil. "/ ad hoc
   760     self searchPattern: self templateSearchPatternHolder value.
  1084     self searchPattern: self templateSearchPatternHolder value.
   761     self replacePattern: self templateReplacePatternHolder value.
  1085     self replacePattern: self templateReplacePatternHolder value.
   762     self selectedTabIndex value:1
  1086     self selectedTabIndex value:1
   763 
  1087 
   764     "Created: / 12-12-2007 / 11:14:15 / janfrog"
  1088     "Created: / 12-12-2007 / 11:14:15 / janfrog"
   765 ! !
  1089 ! !
   766 
  1090 
   767 !MethodRewriter methodsFor:'aspects'!
  1091 !MethodRewriter methodsFor:'aspects'!
   768 
  1092 
   769 actionInProgresHolder
  1093 actionInProgresHolder
   770     "automatically generated by UIPainter ..."
       
   771 
       
   772     "*** the code below creates a default model when invoked."
       
   773     "*** (which may not be the one you wanted)"
       
   774     "*** Please change as required and accept it in the browser."
       
   775     "*** (and replace this comment by something more useful ;-)"
       
   776 
       
   777     actionInProgresHolder isNil ifTrue:[
  1094     actionInProgresHolder isNil ifTrue:[
   778         actionInProgresHolder := true asValue.
  1095         actionInProgresHolder := true asValue.
   779 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   780 "/       actionInProgresHolder addDependent:self.
       
   781 "/       actionInProgresHolder onChangeSend:#actionInProgresHolderChanged to:self.
       
   782     ].
  1096     ].
   783     ^ actionInProgresHolder.
  1097     ^ actionInProgresHolder.
   784 
  1098 
   785     "Created: / 12-12-2007 / 10:00:05 / janfrog"
  1099     "Created: / 12-12-2007 / 10:00:05 / janfrog"
   786 !
  1100 !
   787 
  1101 
       
  1102 adHocFindAndReplaceVisibleHolder
       
  1103     adHocFindAndReplaceVisibleHolder isNil ifTrue:[
       
  1104         adHocFindAndReplaceVisibleHolder := true asValue.
       
  1105     ].
       
  1106     ^ adHocFindAndReplaceVisibleHolder.
       
  1107 !
       
  1108 
       
  1109 howToUseRewriteToolURL
       
  1110     ^ HTMLDocumentFrame documentFileFor:'help/Browser/RewriteToolHelp.html'
       
  1111 !
       
  1112 
   788 infoHolder
  1113 infoHolder
   789     "automatically generated by UIPainter ..."
       
   790 
       
   791     "*** the code below creates a default model when invoked."
       
   792     "*** (which may not be the one you wanted)"
       
   793     "*** Please change as required and accept it in the browser."
       
   794     "*** (and replace this comment by something more useful ;-)"
       
   795 
       
   796     infoHolder isNil ifTrue:[
  1114     infoHolder isNil ifTrue:[
   797         infoHolder := 'Really cool tool!!' asValue.
  1115         infoHolder := 'Really cool tool!!' asValue.
   798 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   799 "/       infoHolder addDependent:self.
       
   800 "/       infoHolder onChangeSend:#infoHolderChanged to:self.
       
   801     ].
  1116     ].
   802     ^ infoHolder.
  1117     ^ infoHolder.
   803 
  1118 
   804     "Created: / 12-12-2007 / 10:00:05 / janfrog"
  1119     "Created: / 12-12-2007 / 10:00:05 / janfrog"
   805     "Modified: / 12-12-2007 / 11:40:17 / janfrog"
  1120     "Modified: / 12-12-2007 / 11:40:17 / janfrog"
   806 !
  1121 !
   807 
  1122 
   808 progressHolder
  1123 progressHolder
   809     "automatically generated by UIPainter ..."
       
   810 
       
   811     "*** the code below creates a default model when invoked."
       
   812     "*** (which may not be the one you wanted)"
       
   813     "*** Please change as required and accept it in the browser."
       
   814     "*** (and replace this comment by something more useful ;-)"
       
   815 
       
   816     progressHolder isNil ifTrue:[
  1124     progressHolder isNil ifTrue:[
   817         progressHolder := 0 asValue
  1125         progressHolder := 0 asValue
   818 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   819 "/       progressHolder addDependent:self.
       
   820 "/       progressHolder onChangeSend:#progressHolderChanged to:self.
       
   821     ].
  1126     ].
   822     ^ progressHolder.
  1127     ^ progressHolder.
   823 
  1128 
   824     "Created: / 12-12-2007 / 10:00:05 / janfrog"
  1129     "Created: / 12-12-2007 / 10:00:05 / janfrog"
   825 !
  1130 !
   826 
  1131 
       
  1132 ruleExecutionVisibleHolder
       
  1133     ^ BlockValue forLogicalNot:self adHocFindAndReplaceVisibleHolder 
       
  1134 !
       
  1135 
       
  1136 ruleNameHolder
       
  1137     ruleNameHolder isNil ifTrue:[
       
  1138         ruleNameHolder := '' asValue.
       
  1139     ].
       
  1140     ^ ruleNameHolder.
       
  1141 !
       
  1142 
       
  1143 ruleNameList
       
  1144 
       
  1145     ^self rules collect:[:ruleSpec | ruleSpec first name ]
       
  1146 !
       
  1147 
       
  1148 ruleSearchAndReplacePatternHolder
       
  1149     ruleSearchAndReplacePatternHolder isNil ifTrue:[
       
  1150         ruleSearchAndReplacePatternHolder := '' asValue.
       
  1151     ].
       
  1152     ^ ruleSearchAndReplacePatternHolder.
       
  1153 !
       
  1154 
       
  1155 searchPatternHelpURL
       
  1156     ^ HTMLDocumentFrame documentFileFor:'help/Browser/RBSearchPatterns.html'
       
  1157 !
       
  1158 
   827 selectedClassesHolder
  1159 selectedClassesHolder
   828     "automatically generated by UIPainter ..."
       
   829 
       
   830     "*** the code below creates a default model when invoked."
       
   831     "*** (which may not be the one you wanted)"
       
   832     "*** Please change as required and accept it in the browser."
       
   833     "*** (and replace this comment by something more useful ;-)"
       
   834 
       
   835     selectedClassesHolder isNil ifTrue:[
  1160     selectedClassesHolder isNil ifTrue:[
   836         selectedClassesHolder := ValueHolder new.
  1161         selectedClassesHolder := ValueHolder new.
   837 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   838 "/       selectedClassesHolder addDependent:self.
       
   839 "/       selectedClassesHolder onChangeSend:#selectedClassesHolderChanged to:self.
       
   840     ].
  1162     ].
   841     ^ selectedClassesHolder.
  1163     ^ selectedClassesHolder.
   842 
  1164 
   843     "Created: / 12-12-2007 / 12:01:40 / janfrog"
  1165     "Created: / 12-12-2007 / 12:01:40 / janfrog"
   844 !
  1166 !
   845 
  1167 
       
  1168 selectedRuleIndex
       
  1169 
       
  1170     selectedRuleIndex isNil ifTrue:[
       
  1171         selectedRuleIndex := ValueHolder new.
       
  1172         selectedRuleIndex onChangeSend:#selectedRuleIndexChanged to:self.
       
  1173     ].
       
  1174     ^ selectedRuleIndex.
       
  1175 !
       
  1176 
   846 selectedTabIndex
  1177 selectedTabIndex
   847     "automatically generated by UIPainter ..."
       
   848 
       
   849     "*** the code below creates a default model when invoked."
       
   850     "*** (which may not be the one you wanted)"
       
   851     "*** Please change as required and accept it in the browser."
       
   852     "*** (and replace this comment by something more useful ;-)"
       
   853 
       
   854     selectedTabIndex isNil ifTrue:[
  1178     selectedTabIndex isNil ifTrue:[
   855         selectedTabIndex := ValueHolder new.
  1179         selectedTabIndex := ValueHolder new.
   856 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   857 "/       selectedTabIndex addDependent:self.
       
   858 "/       selectedTabIndex onChangeSend:#selectedTabIndexChanged to:self.
       
   859     ].
  1180     ].
   860     ^ selectedTabIndex.
  1181     ^ selectedTabIndex.
   861 
  1182 
   862     "Created: / 12-12-2007 / 11:39:29 / janfrog"
  1183     "Created: / 12-12-2007 / 11:39:29 / janfrog"
   863 !
  1184 !
   892 
  1213 
   893     "Created: / 12-12-2007 / 11:17:16 / janfrog"
  1214     "Created: / 12-12-2007 / 11:17:16 / janfrog"
   894 !
  1215 !
   895 
  1216 
   896 templateReplacePatternHolder
  1217 templateReplacePatternHolder
   897     "automatically generated by UIPainter ..."
       
   898 
       
   899     "*** the code below creates a default model when invoked."
       
   900     "*** (which may not be the one you wanted)"
       
   901     "*** Please change as required and accept it in the browser."
       
   902     "*** (and replace this comment by something more useful ;-)"
       
   903 
       
   904     templateReplacePatternHolder isNil ifTrue:[
  1218     templateReplacePatternHolder isNil ifTrue:[
   905         templateReplacePatternHolder := '' asValue.
  1219         templateReplacePatternHolder := '' asValue.
   906 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   907 "/       templateReplacePatternHolder addDependent:self.
       
   908 "/       templateReplacePatternHolder onChangeSend:#templateReplacePatternHolderChanged to:self.
       
   909     ].
  1220     ].
   910     ^ templateReplacePatternHolder.
  1221     ^ templateReplacePatternHolder.
   911 
  1222 
   912     "Created: / 12-12-2007 / 11:17:16 / janfrog"
  1223     "Created: / 12-12-2007 / 11:17:16 / janfrog"
   913 !
  1224 !
   914 
  1225 
       
  1226 templateReplacePatternIsEditable
       
  1227     |holder|
       
  1228 
       
  1229     (holder := builder bindingAt:#templateReplacePatternIsEditable) isNil ifTrue:[
       
  1230         builder aspectAt:#templateReplacePatternIsEditable put:(holder := true asValue).
       
  1231     ].
       
  1232     ^ holder.
       
  1233 !
       
  1234 
   915 templateSearchPatternHolder
  1235 templateSearchPatternHolder
   916     "automatically generated by UIPainter ..."
       
   917 
       
   918     "*** the code below creates a default model when invoked."
       
   919     "*** (which may not be the one you wanted)"
       
   920     "*** Please change as required and accept it in the browser."
       
   921     "*** (and replace this comment by something more useful ;-)"
       
   922 
       
   923     templateSearchPatternHolder isNil ifTrue:[
  1236     templateSearchPatternHolder isNil ifTrue:[
   924         templateSearchPatternHolder := '' asValue.
  1237         templateSearchPatternHolder := '' asValue.
   925 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   926 "/       templateSearchPatternHolder addDependent:self.
       
   927 "/       templateSearchPatternHolder onChangeSend:#templateSearchPatternHolderChanged to:self.
       
   928     ].
  1238     ].
   929     ^ templateSearchPatternHolder.
  1239     ^ templateSearchPatternHolder.
   930 
  1240 
   931     "Created: / 12-12-2007 / 11:17:16 / janfrog"
  1241     "Created: / 12-12-2007 / 11:17:16 / janfrog"
       
  1242 !
       
  1243 
       
  1244 templateSearchPatternIsEditable
       
  1245     |holder|
       
  1246 
       
  1247     (holder := builder bindingAt:#templateSearchPatternIsEditable) isNil ifTrue:[
       
  1248         builder aspectAt:#templateSearchPatternIsEditable put:(holder := true asValue).
       
  1249     ].
       
  1250     ^ holder.
   932 ! !
  1251 ! !
   933 
  1252 
   934 !MethodRewriter methodsFor:'change & update'!
  1253 !MethodRewriter methodsFor:'change & update'!
   935 
  1254 
       
  1255 selectedRuleIndexChanged
       
  1256     |selectedRuleSpec|
       
  1257 
       
  1258     selectedRuleSpec := self selectedRuleSpec.
       
  1259     "/ entries are:
       
  1260     "/ 1) rule
       
  1261     "/ 2) search & replacement pattern
       
  1262 
       
  1263     self ruleSearchAndReplacePatternHolder value: selectedRuleSpec second.
       
  1264 !
       
  1265 
   936 selectedTemplateIndexChanged
  1266 selectedTemplateIndexChanged
   937 
  1267     |selectedTemplate|
   938     self templateSearchPatternHolder value: self selectedTemplate second.
  1268 
   939     self templateReplacePatternHolder value: self selectedTemplate third.
  1269     selectedTemplate := self selectedTemplate.
       
  1270     "/ entries are:
       
  1271     "/ 1) name
       
  1272     "/ 2) search pattern
       
  1273     "/ 3) replacement pattern
       
  1274     "/ 4) rule or nil; nil for ad-hoc rewrite
       
  1275     selectedTemplate fourth isNil ifTrue:[
       
  1276         "/ ad hoc
       
  1277         self templateReplacePatternIsEditable value:true.
       
  1278         self templateSearchPatternIsEditable value:true.
       
  1279     ] ifFalse:[
       
  1280         "/ existing rule
       
  1281         self templateReplacePatternIsEditable value:false.
       
  1282         self templateSearchPatternIsEditable value:false.
       
  1283     ].
       
  1284     self templateSearchPatternHolder value: selectedTemplate second.
       
  1285     self templateReplacePatternHolder value: selectedTemplate third.
   940 
  1286 
   941     "Created: / 12-12-2007 / 11:20:16 / janfrog"
  1287     "Created: / 12-12-2007 / 11:20:16 / janfrog"
   942 ! !
  1288 ! !
   943 
  1289 
   944 !MethodRewriter methodsFor:'drag & drop'!
  1290 !MethodRewriter methodsFor:'drag & drop'!
   985     "Created: / 20-07-2007 / 15:55:29 / janfrog"
  1331     "Created: / 20-07-2007 / 15:55:29 / janfrog"
   986 ! !
  1332 ! !
   987 
  1333 
   988 !MethodRewriter methodsFor:'private'!
  1334 !MethodRewriter methodsFor:'private'!
   989 
  1335 
   990 doSearch: pattern withResultDo: block
  1336 doSearchPattern: pattern withResultDo: block
   991 
  1337 
   992     | matchingMethods |
  1338     | matchingMethods |
       
  1339 
       
  1340     pattern isEmptyOrNil ifTrue:[
       
  1341         Dialog warn:'No searchpattern given.'.
       
  1342         AbortSignal raise
       
  1343     ].
       
  1344 
   993     matchingMethods := Set new.
  1345     matchingMethods := Set new.
   994     self
  1346     self
   995         withMethodsDo:
  1347         withMethodsDo:[:mthd| 
   996             [:mth| | tree |
  1348             | tree |
   997             tree := mth parseTree.
  1349             tree := mthd parseTree.
   998             tree ifNil:[self breakPoint: #jv] ifNotNil:[
  1350             tree 
   999             (ParseTreeSearcher new)
  1351                 ifNil:[
  1000                 matches:self searchPattern do:[:aNode :answer | matchingMethods add:mth ];
  1352                     Transcript showCR:'MethodRewriter: parse tree error in ',mthd whoString.
  1001                executeTree: tree]
  1353                     self breakPoint: #jv
  1002             ]
  1354                 ] 
  1003         finallyDo: 
  1355                 ifNotNil:[
  1004             [block value: matchingMethods]
  1356                     (ParseTreeSearcher new)
       
  1357                         matches:pattern do:[:aNode :answer | matchingMethods add:mthd ];
       
  1358                        executeTree: tree
       
  1359                 ]
       
  1360         ]
       
  1361         finallyDo:[
       
  1362             block value: matchingMethods
       
  1363         ]
       
  1364 
       
  1365     "Created: / 12-12-2007 / 10:34:50 / janfrog"
       
  1366     "Modified: / 07-04-2011 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1367 !
       
  1368 
       
  1369 doSearchRule: rule withResultDo: block
       
  1370 
       
  1371     | matchingMethods searcher currentMethod|
       
  1372 
       
  1373     rule isNil ifTrue:[
       
  1374         Dialog warn:'No rule selected.'.
       
  1375         AbortSignal raise
       
  1376     ].
       
  1377 
       
  1378     searcher := ParseTreeSearcher new.
       
  1379     rule rewriteRule searches do:[:eachSearch |
       
  1380         searcher matchesTree:eachSearch searchTree do:[:aNode :answer | matchingMethods add:currentMethod ] 
       
  1381     ].
       
  1382 
       
  1383     matchingMethods := Set new.
       
  1384     self
       
  1385         withMethodsDo:[:mthd| 
       
  1386             | tree |
       
  1387 
       
  1388             tree := mthd parseTree.
       
  1389             tree 
       
  1390                 ifNil:[
       
  1391                     Transcript showCR:'MethodRewriter: parse tree error in ',mthd whoString.
       
  1392                     self breakPoint: #jv
       
  1393                 ] 
       
  1394                 ifNotNil:[
       
  1395                     currentMethod := mthd.
       
  1396                     searcher executeTree: tree
       
  1397                 ]
       
  1398         ]
       
  1399         finallyDo:[
       
  1400             block value: matchingMethods
       
  1401         ]
  1005 
  1402 
  1006     "Created: / 12-12-2007 / 10:34:50 / janfrog"
  1403     "Created: / 12-12-2007 / 10:34:50 / janfrog"
  1007     "Modified: / 07-04-2011 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1404     "Modified: / 07-04-2011 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1008 !
  1405 !
  1009 
  1406 
  1034                 yourself]
  1431                 yourself]
  1035 
  1432 
  1036     "Created: / 21-07-2007 / 06:25:42 / janfrog"
  1433     "Created: / 21-07-2007 / 06:25:42 / janfrog"
  1037 !
  1434 !
  1038 
  1435 
  1039 methodsMatching
  1436 methodsMatchingPattern: searchPattern
  1040 
  1437     |methods matchingMethods|
  1041     ^self methodsMatching: self searchPattern
  1438 
  1042 
  1439     searchPattern isEmptyOrNil ifTrue:[
  1043     "Created: / 21-07-2007 / 06:26:44 / janfrog"
  1440         Dialog warn:'No searchpattern given'.
  1044 !
  1441         AbortSignal raise
  1045 
  1442     ].
  1046 methodsMatching: searchPattern
  1443     methods := self methodsToSearchOrAbortIfNone.
  1047     |matchingMethods|
       
  1048 
  1444 
  1049     matchingMethods := OrderedCollection new.
  1445     matchingMethods := OrderedCollection new.
  1050     self methods do:[:mth | 
  1446     methods do:[:mth | 
  1051         (ParseTreeSearcher new)
  1447         (ParseTreeSearcher new)
  1052             matches:searchPattern do:[:aNode :answer | matchingMethods add:mth ];
  1448             matches:searchPattern do:[:aNode :answer | matchingMethods add:mth ];
  1053             executeTree:mth parseTree.
  1449             executeTree:mth parseTree.
  1054     ].
  1450     ].
  1055     ^ matchingMethods
  1451     ^ matchingMethods
  1056 
  1452 
  1057     "Created: / 21-07-2007 / 06:26:19 / janfrog"
  1453     "Created: / 21-07-2007 / 06:26:19 / janfrog"
       
  1454 !
       
  1455 
       
  1456 methodsMatchingRule: rule
       
  1457     |methods matchingMethods|
       
  1458 
       
  1459     rule isNil ifTrue:[
       
  1460         Dialog warn:'No rule given'.
       
  1461         AbortSignal raise
       
  1462     ].
       
  1463     methods := self methodsToSearchOrAbortIfNone.
       
  1464 
       
  1465     matchingMethods := OrderedCollection new.
       
  1466     methods do:[:mth | 
       
  1467         |searcher|
       
  1468 
       
  1469         searcher := ParseTreeSearcher new.
       
  1470         rule searches halt.
       
  1471 "/            matches:searchPattern do:[:aNode :answer | matchingMethods add:mth ];
       
  1472 "/            executeTree:mth parseTree.
       
  1473     ].
       
  1474     ^ matchingMethods
       
  1475 !
       
  1476 
       
  1477 methodsToSearchOrAbortIfNone
       
  1478     (methods := self methods) isEmptyOrNil ifTrue:[
       
  1479         Dialog warn:'No methods or classes defined for search'.
       
  1480         AbortSignal raise.
       
  1481     ].
       
  1482     ^ methods
  1058 !
  1483 !
  1059 
  1484 
  1060 showMethods: methods title: title
  1485 showMethods: methods title: title
  1061 
  1486 
  1062     NewSystemBrowser 
  1487     NewSystemBrowser 
  1094 !
  1519 !
  1095 
  1520 
  1096 withMethodsDo: methodBlock finallyDo: finallyBlock
  1521 withMethodsDo: methodBlock finallyDo: finallyBlock
  1097 
  1522 
  1098    ^self 
  1523    ^self 
  1099         withMethods: self methods asArray
  1524         withMethods: self methodsToSearchOrAbortIfNone asArray
  1100         do: methodBlock
  1525         do: methodBlock
  1101         finallyDo: finallyBlock
  1526         finallyDo: finallyBlock
  1102 
  1527 
  1103     "Modified: / 12-12-2007 / 10:32:48 / janfrog"
  1528     "Modified: / 12-12-2007 / 10:32:48 / janfrog"
  1104 ! !
  1529 ! !
  1113 ! !
  1538 ! !
  1114 
  1539 
  1115 !MethodRewriter class methodsFor:'documentation'!
  1540 !MethodRewriter class methodsFor:'documentation'!
  1116 
  1541 
  1117 version_CVS
  1542 version_CVS
  1118     ^ '$Header: /cvs/stx/stx/libtool/Tools__MethodRewriter.st,v 1.19 2014-05-23 08:09:07 stefan Exp $'
  1543     ^ '$Header: /cvs/stx/stx/libtool/Tools__MethodRewriter.st,v 1.20 2015-02-04 22:34:40 cg Exp $'
  1119 !
  1544 !
  1120 
  1545 
  1121 version_SVN
  1546 version_SVN
  1122     ^ '$Id: Tools__MethodRewriter.st,v 1.19 2014-05-23 08:09:07 stefan Exp $'
  1547     ^ '$Id: Tools__MethodRewriter.st,v 1.20 2015-02-04 22:34:40 cg Exp $'
  1123 ! !
  1548 ! !
  1124 
  1549