SourceCodeManagerUtilities.st
changeset 1994 eccaf18ff7a1
parent 1988 0294d9beb4c0
child 1995 f832f7ec6ccf
equal deleted inserted replaced
1993:68da9e3a68e9 1994:eccaf18ff7a1
  2698         #halt
  2698         #halt
  2699         #halt:
  2699         #halt:
  2700         #error
  2700         #error
  2701         (and maybe more in the future)"
  2701         (and maybe more in the future)"
  2702 
  2702 
  2703     |badStuff whatIsBad msg answer labels values defaultAnswer dontShowAgain|
  2703     |badStuff whatIsBad msg answer labels values defaultAnswer dontShowAgain
       
  2704      methodsWithBadStuff resources|
       
  2705 
       
  2706     resources := Dialog classResources.
  2704 
  2707 
  2705     badStuff := #(
  2708     badStuff := #(
  2706         ( halt         'sent of #halt (use for debugging only) - better use #error:''some message''' )
  2709         ( halt         'sent of #halt (use for debugging only) - better use #error:''some message'' or #breakPoint:')
  2707         ( halt:        'sent of #halt: (use for debugging only) - better use #error:' )
  2710         ( halt:        'sent of #halt: (use for debugging only) - better use #error: or #breakPoint:')
  2708         ( error        'sent of #error without descriptive message - better use #error:''some message''' )
  2711         ( error        'sent of #error without descriptive message - better use #error:''some message''' )
  2709     ).
  2712     ).
  2710 
  2713 
       
  2714     methodsWithBadStuff := Set new.
  2711     whatIsBad := Set new.
  2715     whatIsBad := Set new.
  2712     aClass theNonMetaclass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
  2716     aClass theNonMetaclass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
  2713         |setOfLiterals setOfSentMessages|
  2717         |setOfLiterals setOfSentMessages methodIsBad|
       
  2718 
       
  2719         methodIsBad := false.
  2714 
  2720 
  2715         setOfLiterals := mthd literals.  "/ try without parsing first.
  2721         setOfLiterals := mthd literals.  "/ try without parsing first.
  2716         (badStuff contains:[:eachEntry | setOfLiterals includes:eachEntry first]) ifTrue:[
  2722         (badStuff contains:[:eachEntry | setOfLiterals includes:eachEntry first]) ifTrue:[
  2717             setOfSentMessages := mthd messagesSent.
  2723             setOfSentMessages := mthd messagesSent.
  2718             badStuff do:[:eachEntry |
  2724             badStuff do:[:eachEntry | 
  2719                 (setOfSentMessages includes:eachEntry first) ifTrue:[
  2725                 (setOfSentMessages includes:eachEntry first) ifTrue:[
  2720                     whatIsBad add:eachEntry second
  2726                     whatIsBad add:eachEntry second.
       
  2727                     methodsWithBadStuff add:mthd.
  2721                 ]
  2728                 ]
  2722             ].
  2729             ].
  2723         ].
  2730         ].
  2724     ].
  2731     ].
  2725     whatIsBad notEmpty ifTrue:[
  2732     whatIsBad isEmpty ifTrue:[^ true].
  2726         (YesToAllQuery notNil and:[YesToAllQuery isHandled]) ifTrue:[
  2733 
  2727             answer := YesToAllQuery query.
  2734     (YesToAllQuery notNil and:[YesToAllQuery isHandled]) ifTrue:[
  2728             answer notNil ifTrue:[ ^ answer ].
  2735         answer := YesToAllQuery query.
  2729         ].
  2736         answer notNil ifTrue:[ ^ answer ].
  2730 
  2737     ].
  2731         msg := '%1 contains the following  (considered bad style) message sends:\\'.
  2738 
  2732         whatIsBad do:[:each |
  2739     msg := resources string:'%1 contains the following (considered bad style) message sends:' with:aClass name.
  2733             msg := msg , '   ' , each , '\'
  2740     msg := msg , '\\'.
  2734         ].
  2741     whatIsBad do:[:each |
  2735         msg := msg , '\\' , 'Do you really want to checkIn the %1 class ?'.
  2742         msg := msg , '   ' , each , '\'
  2736         msg := msg bindWith:aClass name.
  2743     ].
  2737 
  2744     msg := msg , '\'.
  2738         (YesToAllNotification notNil and:[YesToAllNotification isHandled]) ifTrue:[
  2745     methodsWithBadStuff size == 1 ifTrue:[
  2739             labels := #('Cancel All' 'Cancel' 'No to All' 'No' 'Yes to All' 'Yes') "#('Yes' 'Yes to All' 'No' 'No to All' 'Cancel')".
  2746         msg := msg , (resources string:'In %1.' 
  2740             values := #(#cancelAll nil #noToAll false #yesToAll true) "#(true #yesToAll false #noToAll nil)".
  2747                         with:methodsWithBadStuff anElement whoString allBold).
  2741             defaultAnswer := #yesToAll.
  2748     ] ifFalse:[
  2742         ] ifFalse:[
  2749         msg := msg , (resources string:'In %1 and %2 other methods.' 
  2743             labels := #('No' 'Yes').
  2750                         with:methodsWithBadStuff anElement whoString allBold 
  2744             values := #(false true).
  2751                         with:methodsWithBadStuff size-1).
  2745             defaultAnswer := true.
  2752     ].
  2746         ].
  2753     msg := msg , '\\' , (resources string:'Do you really want to checkIn the %1 class ?' with:aClass name).
       
  2754 
       
  2755     (YesToAllNotification notNil and:[YesToAllNotification isHandled]) ifTrue:[
       
  2756         labels := #('Cancel All' 'Cancel' 'No to All' 'No' 'No, Browse' 'Yes to All' 'Yes') "#('Yes' 'Yes to All' 'No' 'No to All' 'Cancel')".
       
  2757         values := #(#cancelAll nil #noToAll #noBrowse false #yesToAll true) "#(true #yesToAll false #noToAll nil)".
       
  2758         defaultAnswer := #yesToAll.
       
  2759     ] ifFalse:[
       
  2760         labels := #('No' 'No, Browse' 'Yes').
       
  2761         values := #(false #noBrowse true).
       
  2762         defaultAnswer := true.
       
  2763     ].
  2747 
  2764 
  2748 "/        AbortAllOperationRequest isHandled ifTrue:[
  2765 "/        AbortAllOperationRequest isHandled ifTrue:[
  2749 "/            labels := #('Cancel All') , labels.
  2766 "/            labels := #('Cancel All') , labels.
  2750 "/            values := #(#cancelAll) , values.
  2767 "/            values := #(#cancelAll) , values.
  2751 "/        ].
  2768 "/        ].
  2752 
  2769 
  2753         DialogBox aboutToOpenBoxNotificationSignal handle:[:ex |
  2770     DialogBox aboutToOpenBoxNotificationSignal handle:[:ex |
  2754             |box|
  2771         |box|
  2755 
  2772 
  2756             checkAgainHolder isValueModel ifTrue:[
  2773         checkAgainHolder isValueModel ifTrue:[
  2757                 dontShowAgain := checkAgainHolder value not asValue.
  2774             dontShowAgain := checkAgainHolder value not asValue.
  2758                 box := ex parameter.
  2775             box := ex parameter.
  2759                 box verticalPanel 
  2776             box verticalPanel 
  2760                     add:(CheckBox label:'Do not show this Dialog again.'
  2777                 add:(CheckBox label:(resources string:'Do not show this Dialog again.')
  2761                                   model:dontShowAgain).
  2778                               model:dontShowAgain).
  2762             ].
  2779         ].
  2763             ex proceed.
  2780         ex proceed.
  2764         ] do:[
  2781     ] do:[
  2765             answer := OptionBox 
  2782         answer := OptionBox 
  2766                           request:msg withCRs
  2783                       request:msg withCRs
  2767                           label:'Really checkIn ?'
  2784                       label:(resources string:'Really CheckIn ?')
  2768                           image:(InfoBox iconBitmap)
  2785                       image:(InfoBox iconBitmap)
  2769                           buttonLabels:labels
  2786                       buttonLabels:(resources array:labels)
  2770                           values:values
  2787                       values:values
  2771                           default:defaultAnswer
  2788                       default:defaultAnswer
  2772                           onCancel:nil.
  2789                       onCancel:nil.
  2773         ].
  2790     ].
  2774         answer isNil ifTrue:[
  2791     answer isNil ifTrue:[
  2775             AbortSignal raise.
  2792         AbortSignal raise.
  2776         ].
  2793     ].
  2777 
  2794 
  2778         dontShowAgain notNil ifTrue:[
  2795     dontShowAgain notNil ifTrue:[
  2779             checkAgainHolder value:dontShowAgain value not 
  2796         checkAgainHolder value:dontShowAgain value not 
  2780         ].
  2797     ].
  2781 
  2798 
  2782         answer == #cancelAll ifTrue:[
  2799     answer == #noBrowse ifTrue:[
  2783             AbortAllSignal raise.
  2800         UserPreferences browserClass browseMethods:methodsWithBadStuff title:'Methods with Bad Stuff'.
  2784         ].
  2801         YesToAllNotification queryWith:false.
  2785 
  2802         ^ false
  2786         answer == #yesToAll ifTrue:[
  2803     ].
  2787             YesToAllNotification queryWith:true.
  2804     answer == #cancelAll ifTrue:[
  2788             ^ true
  2805         AbortAllSignal raise.
  2789         ].
  2806     ].
  2790         answer == #noToAll ifTrue:[
  2807     answer == #yesToAll ifTrue:[
  2791             YesToAllNotification queryWith:false.
  2808         YesToAllNotification queryWith:true.
  2792             ^ false
  2809         ^ true
  2793         ].
  2810     ].
  2794         ^ answer
  2811     answer == #noToAll ifTrue:[
  2795     ].
  2812         YesToAllNotification queryWith:false.
  2796     ^ true.
  2813         ^ false
       
  2814     ].
       
  2815     ^ answer
  2797 
  2816 
  2798     "
  2817     "
  2799      self checkAndWarnAboutBadMessagesInClass:(SourceCodeManagerUtilities)  
  2818      self checkAndWarnAboutBadMessagesInClass:(SourceCodeManagerUtilities)  
  2800     "
  2819     "
  2801 !
  2820 !
  2891 ! !
  2910 ! !
  2892 
  2911 
  2893 !SourceCodeManagerUtilities class methodsFor:'documentation'!
  2912 !SourceCodeManagerUtilities class methodsFor:'documentation'!
  2894 
  2913 
  2895 version
  2914 version
  2896     ^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeManagerUtilities.st,v 1.164 2008-02-04 12:22:47 cg Exp $'
  2915     ^ '$Header: /cvs/stx/stx/libbasic3/SourceCodeManagerUtilities.st,v 1.165 2008-05-29 09:54:00 cg Exp $'
  2897 ! !
  2916 ! !