DoWhatIMeanSupport.st
changeset 4784 7c4d1f1a6b30
parent 4780 ac7e1d23c65b
child 4823 76bba777a498
equal deleted inserted replaced
4782:e43a7165041e 4784:7c4d1f1a6b30
  2697                 allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
  2697                 allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
  2698                                         collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
  2698                                         collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
  2699                 nameBag := Bag new.
  2699                 nameBag := Bag new.
  2700                 allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
  2700                 allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
  2701                 namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
  2701                 namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
       
  2702 
  2702                 "/ take the one which occurs most often
  2703                 "/ take the one which occurs most often
  2703                 "/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
  2704                 "/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
  2704                 argNames := (namesByCount collect:[:a | a key]).
  2705                 argNames := (namesByCount collect:[:a | a key]).
  2705                 editAction :=
  2706                 editAction :=
  2706                         [:chosenIndex |
  2707                         [:chosenIndex |
  2903     "/ are we in the method's selector spec ?
  2904     "/ are we in the method's selector spec ?
  2904     (parent notNil
  2905     (parent notNil
  2905     and:[parent isMethod
  2906     and:[parent isMethod
  2906     and:[parent arguments includes:node]]) ifTrue:[
  2907     and:[parent arguments includes:node]]) ifTrue:[
  2907         "/ yes -
  2908         "/ yes -
  2908         "/ now thats cool: look how the name of this argument is in other implementations
  2909         "/ now that's cool: look how the name of this argument is in other implementations
  2909         "/ of this method, and take that as a basis of the selection
  2910         "/ of this method, and take that as a basis of the selection
  2910 
  2911 
  2911         implementors := SystemBrowser
  2912         implementors := SystemBrowser
  2912                             findImplementorsOf:(parent selector)
  2913                             findImplementorsOf:(parent selector)
  2913                             in:(Smalltalk allClasses)
  2914                             in:(Smalltalk allClasses)
  2925                                 ifFalse:nil
  2926                                 ifFalse:nil
  2926                                 ifTrue:[ (parseTree arguments at:argIdx) name] ]
  2927                                 ifTrue:[ (parseTree arguments at:argIdx) name] ]
  2927                         thenSelect:[:a | a notNil].
  2928                         thenSelect:[:a | a notNil].
  2928 
  2929 
  2929         addWithFactorBlock value:namesUsed value:(2 * localFactor).
  2930         addWithFactorBlock value:namesUsed value:(2 * localFactor).
       
  2931 
       
  2932         "/ try some commonly used arg names, such as aBoolean, anInteger, etc.
       
  2933         nm size > 1 ifTrue:[
       
  2934             |tryClassNamesWith|
       
  2935 
       
  2936             ((nm startsWith:'a') and:[(nm at:2) isUppercase]) ifTrue:[
       
  2937                 tryClassNamesWith := 'a'
       
  2938             ] ifFalse:[
       
  2939                 (nm size > 2 and:[ (nm startsWith:'an') and:[(nm at:3) isUppercase]]) ifTrue:[
       
  2940                     tryClassNamesWith := 'an'.
       
  2941                 ].
       
  2942             ].
       
  2943             tryClassNamesWith notNil ifTrue:[
       
  2944                 addWithFactorBlock 
       
  2945                     value:(Smalltalk keys 
       
  2946                             collect:[:className | tryClassNamesWith,className]
       
  2947                             thenSelect:[:name | name startsWith:nm])
       
  2948                     value:(1.5 * localFactor)
       
  2949             ].
       
  2950         ].
  2930 
  2951 
  2931         classOrNil notNil ifTrue:[
  2952         classOrNil notNil ifTrue:[
  2932             "/ also, look for the keyword before the argument,
  2953             "/ also, look for the keyword before the argument,
  2933             "/ and see if there is such an instVar
  2954             "/ and see if there is such an instVar
  2934             "/ if so, add it with -Arg
  2955             "/ if so, add it with -Arg
  4772 ! !
  4793 ! !
  4773 
  4794 
  4774 !DoWhatIMeanSupport class methodsFor:'documentation'!
  4795 !DoWhatIMeanSupport class methodsFor:'documentation'!
  4775 
  4796 
  4776 version
  4797 version
  4777     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.224 2015-06-08 00:24:35 cg Exp $'
  4798     ^ '$Header$'
  4778 !
  4799 !
  4779 
  4800 
  4780 version_CVS
  4801 version_CVS
  4781     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.224 2015-06-08 00:24:35 cg Exp $'
  4802     ^ '$Header$'
  4782 ! !
  4803 ! !
  4783 
  4804