DoWhatIMeanSupport.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 27 Sep 2013 11:28:05 +0200
changeset 4426 76a0c105e8f4
parent 4423 c21baefab5d0
child 4427 fb066a08ef83
permissions -rw-r--r--
Updated to take codeAspect as an argument for completion. The codeAspect is then stored in an instvar for later use.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Object subclass:#DoWhatIMeanSupport
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
    15
	instanceVariableNames:'tree tokens languageOrNil classOrNil methodOrNil contextOrNil
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    16
		instanceOrNil codeView rememberedScopeNodes codeAspect'
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    17
	classVariableNames:'LastSource LastParseTree LastScanTokens LastChoices'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'System-Support'
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    22
Array variableSubclass:#InputCompletionResult
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    23
	instanceVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    24
	classVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    25
	poolDictionaries:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    26
	privateIn:DoWhatIMeanSupport
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    27
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    28
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
copyright
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 COPYRIGHT (c) 2002 by eXept Software AG
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
              All Rights Reserved
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
documentation
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    47
    Attention: this is currently being rewritten and refactored.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    48
    Don't get mad at the ugly (and duplicate) code.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    49
    Will cleanup when finished.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    50
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    misc collected UI support (functional)
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    52
    These used to be in the Smalltalk and SystemBrowser class; 
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    53
    however, they are only needed for programmers, and some of the stuff is useful in multiple
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    54
    places. 
3667
acb358ca4b0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3660
diff changeset
    55
    Therefore it is:
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    56
        1) not needed for standalone executables
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    57
        2) published here to avoid multiple implementations
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    [author:]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
        Claus Gittinger (cg@exept.de)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    62
"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    63
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    64
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    65
!DoWhatIMeanSupport class methodsFor:'code completion'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    66
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    67
codeCompletionFor: aspect language: languageOrNil method:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    68
    "aspect is so-called code-aspect symbol saying what's edited - #method, #expression, #classDefinition...
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    69
     contextOrNil is the current context, if this is called from the debugger;
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    70
     nil, if called from the browser.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    71
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    72
     This is not yet done, sigh"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    73
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    74
    ^ self new
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    75
        codeCompletionFor: aspect
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    76
        language: languageOrNil 
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    77
        method:methodOrNil orClass:classOrNil 
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    78
        context:contextOrNil 
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    79
        codeView:codeView into:actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    80
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    81
    "Created: / 27-09-2013 / 10:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    82
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    83
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    84
codeCompletionForLanguage: languageOrNil class: classOrNil context:contextOrNil codeView:codeView
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    85
    "contextOrNil is the current context, if this is called from the debugger;
3557
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    86
     nil, if called from the browser.
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    87
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    88
     This is not yet done, sigh"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    89
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    90
    ^ self new 
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    91
        codeCompletionForLanguage: languageOrNil class:classOrNil context:contextOrNil codeView:codeView
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    92
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    93
    "Created: / 18-09-2013 / 13:34:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    94
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    95
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    96
!DoWhatIMeanSupport class methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    97
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    98
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    99
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   100
    "contextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   101
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   102
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   103
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   104
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   105
    ^ self  
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   106
        codeCompletionForLanguage: nil class:classOrNil context:contextOrNil codeView:codeView
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   107
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   108
    "Modified: / 18-09-2013 / 13:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   109
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   110
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   111
codeCompletionForMethod:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   112
    <resource: #obsolete>
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   113
    "contextOrNil is the current context, if this is called from the debugger;
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   114
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   115
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   116
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   117
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   118
    ^ self new
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   119
        codeCompletionForMethod:methodOrNil orClass:classOrNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   120
        context:contextOrNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   121
        codeView:codeView into:actionBlock
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   122
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   123
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   124
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   125
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   126
findNodeForInterval:interval in:source
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   127
    ^ self new findNodeForInterval:interval in:source
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   128
!
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   129
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   130
findNodeForInterval:interval in:source allowErrors:allowErrors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   131
    ^ self new findNodeForInterval:interval in:source allowErrors:allowErrors
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   132
!
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   133
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   134
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   135
    "if mustBeMethod is true, do not try a regular expression (as in a workspace)."
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   136
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   137
    ^ self new
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   138
        findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
3306
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   139
!
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   140
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   141
findNodeForInterval:interval inParseTree:parseTree
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   142
    ^ self new findNodeForInterval:interval inParseTree:parseTree
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   143
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   144
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   145
findNodeIn:tree forInterval:interval
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   146
    ^ self new findNodeIn:tree forInterval:interval
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   149
!DoWhatIMeanSupport class methodsFor:'input completion support'!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   150
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   151
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   152
    "given a partial class category name, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   153
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   154
                2nd: collection consisting of matching categories"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   155
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   156
    |matches best lcName|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   157
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   158
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   159
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   160
    "/ search for exact match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   161
    anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   162
        |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   163
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   164
        category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   165
        (category notNil and:[category startsWith:aPartialCategory]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   166
            matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   167
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   168
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   169
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   170
        "/ search for case-ignoring match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   171
        lcName := aPartialCategory asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   172
        anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   173
            |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   174
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   175
            category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   176
            (category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   177
                matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   178
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   179
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   180
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   181
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   182
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   183
        ^ Array with:aPartialCategory with:(Array with:aPartialCategory)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   184
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   185
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   186
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   187
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   188
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   189
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   190
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   191
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   192
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   193
     Smalltalk classCategoryCompletion:'Sys'    
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   194
     Smalltalk classCategoryCompletion:'System'              
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   195
     Smalltalk classCategoryCompletion:'System-BinaryStorage' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   196
    "
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   197
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   198
    "Created: / 10-08-2006 / 13:06:45 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   199
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   200
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   201
classNameEntryCompletionBlock
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   202
    "this block can be used in a dialog to perform className completion"
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   203
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   204
    ^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:'
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   205
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   206
    "Modified: / 10-08-2006 / 13:22:02 / cg"
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   207
!
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   208
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   209
classnameCompletion:aPartialClassName filter:filterBlock inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   210
    "given a partial classname, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   211
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   212
                2nd: collection consisting of matching names"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   213
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   214
    |searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix 
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   215
     others lcSearchName tryToMatch idx words w1 w2 rslt bestMatch matchesForLongestPrefix|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   216
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   217
    aPartialClassName isEmpty ifTrue:[
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   218
        matches := Smalltalk allClassesForWhich:filterBlock.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   219
        ^ InputCompletionResult bestName:aPartialClassName matchingNames:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   220
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   221
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   222
    (words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   223
        w1 := words first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   224
        w2 := words second.
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   225
        rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   226
        bestMatch := rslt first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   227
        matches := rslt second.
3549
c7c19ab7e225 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3547
diff changeset
   228
        ('class' copyTo:(w2 size min:5)) = w2 ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   229
            matches := matches collect:[:m | m , ' class'].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   230
            bestMatch := bestMatch , ' class'.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   231
        ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   232
        ^ InputCompletionResult bestName:bestMatch matchingNames:matches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   233
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   234
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   235
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   236
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   237
        nsPrefix := 'Smalltalk::'.
4214
f7cb4aea81db refactored
Claus Gittinger <cg@exept.de>
parents: 4210
diff changeset
   238
        searchName := aPartialClassName withoutPrefix:'Smalltalk::'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   239
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   240
        nsPrefix := ''.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   241
        searchName := aPartialClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   242
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   243
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   244
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   245
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   246
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   247
    isMatchString := searchName includesMatchCharacters.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   248
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   249
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   250
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   251
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   252
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   253
    tryToMatch := 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   254
        [:className :fullClassName|
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   255
            |addIt|
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   256
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   257
            isMatchString ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   258
                addIt := searchName match:className
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   259
            ] ifFalse:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   260
                addIt := className startsWith:searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   261
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   262
            addIt ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   263
                matches add:(nsPrefix , fullClassName).
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   264
                matchedNamesWithoutPrefix add:className.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   265
            ] ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   266
                "/ try ignoring case
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   267
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   268
                isMatchString ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   269
                    addIt := searchName match:className caseSensitive:false
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   270
                ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   271
                    addIt := className asLowercase startsWith:lcSearchName.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   272
                    addIt ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   273
                        others add:className 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   274
                    ]
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   275
                ].
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   276
                addIt ifTrue:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   277
                    ignCaseMatches add:(nsPrefix , fullClassName).
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   278
                    matchedNamesWithoutPrefix add:className.
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   279
                ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   280
            ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   281
            addIt
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   282
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   283
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   284
    anEnvironment allClassesForWhich:filterBlock do:[:aClass |
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   285
        |addIt fullClassName classNameWithoutPrefix|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   286
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   287
        aClass isMeta ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   288
            fullClassName := aClass name.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   289
            classNameWithoutPrefix := aClass nameWithoutPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   290
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   291
            addIt := tryToMatch value:fullClassName value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   292
            addIt ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   293
                classNameWithoutPrefix ~~ fullClassName ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   294
                    tryToMatch value:classNameWithoutPrefix value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   295
                ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   296
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   297
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   298
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   299
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   300
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   301
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   302
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   303
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   304
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   305
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   306
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   307
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   308
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   309
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   310
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   311
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   312
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   313
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   314
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   315
"/"/            dist := lcClassName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   316
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   317
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   318
"/"/            dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   319
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   320
"/"/            dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   321
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   322
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   323
"/"/            ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   324
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   325
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   326
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   327
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   328
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   329
    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   330
        ^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   331
    ].                           
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   332
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   333
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   334
        best := matches first.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   335
        ^ InputCompletionResult bestName:best matchingNames:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   336
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   337
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   338
    matches 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   339
        sort:[:name1 :name2 |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   340
            "name1 comes before:name2 iff"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   341
            ((name2 includes:$:) and:[(name1 includes:$:) not])
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   342
            or:[ ((name1 includes:$:) == (name2 includes:$:))
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   343
                  and:[ (name1 size < name2 size) 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   344
                        or: [ name1 < name2 ]]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   345
               ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   346
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   347
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   348
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   349
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   350
    ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   351
        matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   352
        best := ignCaseMatches isEmpty
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   353
                    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   354
                    ifFalse:[ matchesForLongestPrefix longestCommonPrefixCaseSensitive:false ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   355
3198
fea29ae859c9 classnamecompletion fixed when namespace is involved
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   356
        best size < aPartialClassName size "best size == 0" ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   357
            best := matchedNamesWithoutPrefix longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   358
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   359
        best size == 0 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   360
            "if tried again, return next match"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   361
            idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   362
            idx ~~ 1 ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   363
                ^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   364
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   365
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   366
        best size < aPartialClassName size ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   367
            best := aPartialClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   368
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   369
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   370
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   371
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   372
    (cls isBehavior and:[cls isNameSpace]) ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   373
        (matches conform:[:each | each = best
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   374
                                 or:[each startsWith:(best , '::')]])
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   375
        ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   376
            best := best , '::'
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   377
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   378
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   379
    ^ InputCompletionResult bestName:best matchingNames:matches asArray
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   380
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   381
    "
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   382
     Smalltalk classnameCompletion:'Arr'    
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   383
     Smalltalk classnameCompletion:'Arra' 
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   384
     Smalltalk classnameCompletion:'arra'  
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   385
     Smalltalk classnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   386
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   387
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   388
    "Created: / 10-08-2006 / 13:01:08 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   389
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   390
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   391
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   392
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   393
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   394
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   395
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   396
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   397
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   398
        filter:[:cls | true] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   399
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   400
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   401
    "
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   402
     self classnameCompletion:'Arr'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   403
     self classnameCompletion:'Arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   404
     self classnameCompletion:'arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   405
     self classnameCompletion:'*rray' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   406
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   407
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   408
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   409
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   410
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   411
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   412
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   413
    "this block can be used in a dialog to perform className completion"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   414
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   415
    ^ [:contents :field  |
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   416
          |s what m|
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   417
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   418
          s := contents withoutSpaces.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   419
          field topView withCursor:(Cursor questionMark) do:[  
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   420
              what := self perform:completionSelector with:s with:Smalltalk.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   421
          ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   422
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   423
          field contents:(what first).
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   424
          (what at:2) size ~~ 1 ifTrue:[
3693
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   425
              UserPreferences current beepInEditor ifTrue:[                
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   426
                field device beep
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   427
              ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   428
          ]
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   429
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   430
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   431
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   432
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   433
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   434
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   435
    "given a partial globalName, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   436
     2 entries: 1st: the best (longest) match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   437
                2nd: collection consisting of matching names"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   438
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   439
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   440
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   441
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   442
     Smalltalk globalnameCompletion:'Arr' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   443
     Smalltalk globalnameCompletion:'Arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   444
     Smalltalk globalnameCompletion:'arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   445
     Smalltalk globalnameCompletion:'*rray' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   446
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   447
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   448
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   449
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   450
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   451
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   452
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   453
     2 entries: 1st: the best (longest) match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   454
                2nd: collection consisting of matching names"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   455
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   456
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   457
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   458
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   459
    searchName isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   460
        ^ Array with:searchName with:#()
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   461
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   462
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   463
    (searchName at:1) isLowercase ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   464
        searchName := searchName copy asUppercaseFirst
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   465
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   466
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   467
    isMatchString := doMatch and:[ searchName includesMatchCharacters ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   468
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   469
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   470
    anEnvironment keysDo:[:aGlobalName |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   471
        | addIt|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   472
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   473
        isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   474
            addIt := searchName match:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   475
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   476
            addIt := aGlobalName startsWith:searchName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   477
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   478
        addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   479
            matches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   480
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   481
            "/ try ignoring case
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   482
            isMatchString ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   483
                addIt := searchName match:aGlobalName caseSensitive:false
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   484
            ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   485
                addIt := aGlobalName asLowercase startsWith:searchName asLowercase
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   486
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   487
            addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   488
                ignCaseMatches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   489
            ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   490
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   491
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   492
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   493
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   494
        matches := ignCaseMatches
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   495
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   496
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   497
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   498
        ^ Array with:searchName with:(Array with:searchName)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   499
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   500
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   501
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   502
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   503
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   504
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   505
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   506
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   507
        best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   508
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   509
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   510
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   511
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   512
     Smalltalk globalnameCompletion:'Arr' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   513
     Smalltalk globalnameCompletion:'Arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   514
     Smalltalk globalnameCompletion:'arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   515
     Smalltalk globalnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   516
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   517
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   518
    "Created: / 10-08-2006 / 13:06:23 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   519
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   520
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   521
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   522
    "given a partial method protocol name, return an array consisting of
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   523
     2 entries: 1st: the best (longest) match 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   524
                2nd: collection consisting of matching protocols"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   525
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   526
    |matches best lcName|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   527
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   528
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   529
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   530
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   531
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   532
        |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   533
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   534
        protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   535
        (protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   536
            matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   537
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   538
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   539
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   540
        "/ search for case-ignoring match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   541
        lcName := aPartialProtocolName asLowercase.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   542
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   543
            |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   544
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   545
            protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   546
            (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   547
                matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   548
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   549
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   550
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   551
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   552
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   553
        ^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   554
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   555
    matches size == 1 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   556
        ^ Array with:matches first with:(matches asArray)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   557
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   558
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   559
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   560
    ^ Array with:best with:matches asArray
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   561
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   562
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   563
     Smalltalk methodProtocolCompletion:'doc'
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   564
     Smalltalk methodProtocolCompletion:'docu' 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   565
     Smalltalk methodProtocolCompletion:'documenta' 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   566
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   567
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   568
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   569
    "Modified: / 16-03-2011 / 12:30:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   570
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   571
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   572
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   573
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   574
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   575
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   576
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   577
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   578
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   579
        filter:[:cls | cls isNameSpace] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   580
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   581
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   582
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   583
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk  
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   584
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   585
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   586
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   587
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   588
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   589
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   590
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   591
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   592
                2nd: collection consisting of matching packages"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   593
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   594
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   595
4195
f154f90d39a6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
   596
    matches := Smalltalk allProjectIDs
f154f90d39a6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
   597
        select:[:package | package startsWith:aPartialPackage].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   598
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   599
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   600
        "/ search for case-ignoring match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   601
        lcName := aPartialPackage asLowercase.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   602
        anEnvironment allClassesDo:[:aClass |
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   603
            |package|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   604
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   605
            package := aClass package.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   606
            (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   607
                matches add:package
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   608
            ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   609
        ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   610
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   611
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   612
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   613
        ^ Array with:aPartialPackage with:(Array with:aPartialPackage)
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   614
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   615
    matches size == 1 ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   616
        ^ Array with:matches first with:(matches asArray)
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   617
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   618
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   619
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   620
    ^ Array with:best with:matches asArray
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   621
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   622
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   623
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk   
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   624
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk                
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   625
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   626
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   627
    "Created: / 10-08-2006 / 13:05:07 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   628
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   629
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   630
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   631
    "this block can be used in a dialog to perform className completion"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   632
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   633
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   634
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   635
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   636
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   637
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   638
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   639
    "given a partial poolname, return an array consisting of
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   640
     2 entries: 1st: the best (longest) match
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   641
                2nd: collection consisting of matching names"
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   642
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   643
    ^ self
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   644
        classnameCompletion:aPartialClassName 
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   645
        filter:[:cls | cls isSharedPool] 
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   646
        inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   647
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   648
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   649
     self poolnameCompletion:'Win' inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   650
     self poolnameCompletion:'Z'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   651
     self poolnameCompletion:'a'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   652
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   653
!
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   654
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   655
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   656
    "given a partial resource name, return an array consisting of
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   657
     2 entries: 1st: the longest match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   658
                2nd: collection consisting of matching defined resources"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   659
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   660
    |matches best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   661
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   662
    matches := IdentitySet new.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   663
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   664
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   665
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   666
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   667
        eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   668
            eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   669
                (isMatch 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   670
                    ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:ignoreCase not) ]
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   671
                    ifFalse:[ ignoreCase 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   672
                                ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ]  
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   673
                                ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   674
                ) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   675
                    matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   676
                ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   677
            ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   678
        ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   679
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   680
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   681
        "/ search for case-ignoring match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   682
        lcSym := aPartialResourceName asLowercase.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   683
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   684
            eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   685
                eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   686
                    (isMatch 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   687
                        ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:false) ]
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   688
                        ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ])
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   689
                     ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   690
                        matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   691
                    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   692
                ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   693
            ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   694
        ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   695
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   696
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   697
    matches isEmpty ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   698
        ^ Array with:aPartialResourceName with:#() 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   699
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   700
    matches size == 1 ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   701
        ^ Array with:matches first with:(matches asArray)
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   702
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   703
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   704
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   705
    ^ Array with:best with:matches asArray
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   706
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   707
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   708
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   709
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   710
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   711
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   712
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   713
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   714
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   715
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   716
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   717
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   718
    "given a partial selector, return an array consisting of
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   719
     2 entries: 1st: the longest match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   720
                2nd: collection consisting of matching implemented selectors"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   721
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   722
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   723
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   724
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   725
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   726
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   727
     2 entries: 1st: the longest match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   728
                2nd: collection consisting of matching implemented selectors"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   729
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   730
    ^ self 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   731
        selectorCompletion:aPartialSymbolName 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   732
        inEnvironment:anEnvironment 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   733
        match:doMatch 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   734
        ignoreCase:false
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   735
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   736
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   737
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   738
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   739
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   740
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   741
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   742
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   743
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   744
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   745
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   746
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   747
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   748
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   749
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   750
     2 entries: 1st: the longest match
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   751
                2nd: collection consisting of matching implemented selectors"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   752
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   753
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   754
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   755
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   756
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   757
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   758
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   759
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   760
        (isMatch 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   761
            ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:ignoreCase not) ]
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   762
            ifFalse:[ ignoreCase 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   763
                        ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ]  
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   764
                        ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ])
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   765
         ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   766
            matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   767
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   768
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   769
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   770
        "/ search for case-ignoring match
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   771
        lcSym := aPartialSymbolName asLowercase.
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   772
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   773
            (isMatch 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
   774
                ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:false) ]
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   775
                ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ])
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   776
             ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   777
                matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   778
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   779
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   780
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   781
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   782
    matches isEmpty ifTrue:[
3864
10c7db09a580 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
   783
        ^ Array with:aPartialSymbolName with:#() "/ (Array with:aPartialSymbolName)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   784
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   785
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   786
        ^ Array with:matches first with:(matches asArray)
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   787
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   788
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   789
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   790
    ^ Array with:best with:matches asArray
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   791
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   792
    "
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   793
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   794
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   795
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   796
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   797
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   798
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   799
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   800
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   801
    "Created: / 26-10-2010 / 20:30:06 / cg"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   802
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   803
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   807
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   808
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   809
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   810
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
    (lastNewName endsWith:lastOldName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   818
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   819
            'foo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   820
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   821
            'bar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   822
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
        ^ (prefix , oldName).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
    (lastOldName endsWith:lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   827
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   828
            'Xfoo' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   829
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   830
            'Xbar' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   831
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   833
        (oldName startsWith:prefix) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   834
            ^ (oldName copyFrom:prefix size+1).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   835
        ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   836
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   837
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   838
        (lastOldName first ~= lastNewName first) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   839
            (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   840
                "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   841
                    'xfoo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   842
                 then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   843
                    'xbar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   844
                "
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   845
                lastOldName first isLowercase ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   846
                    ^ oldName first asUppercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   847
                ] ifFalse:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   848
                    ^ oldName first asLowercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   849
                ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   850
            ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   851
        ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   854
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   855
            '  foo   ' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   856
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   857
            '  bar   ' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   858
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
        ^ oldName withoutSeparators.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
    (lastNewName startsWith:lastOldName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   862
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   863
            'foo' -> 'fooX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   864
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   865
            'bar' would be 'barX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   866
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
        ^ (oldName , suffix).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
    (lastOldName startsWith:lastNewName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   871
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   872
            'fooX' -> 'foo'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   873
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   874
            'barX' would be 'bar'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   875
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
        (oldName endsWith:suffix) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   878
            ^ (oldName copyButLast:suffix size).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
        ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   881
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   882
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   883
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   884
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   885
    (prefix size > 0) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   886
        (suffix size > 0) ifTrue:[
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   887
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   888
            prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   889
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   890
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   891
                'fooR' -> 'fooXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   892
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   893
                'barR' would be 'barXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   894
            "
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   895
            left := lastOldName copyTo:prefix size.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   896
            right := lastOldName copyLast:suffix size.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   897
            lastNewSize > lastOldSize ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   898
                inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   899
                inserted size > 0 ifTrue:[
3532
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   900
                    (oldName startsWith:prefix) ifTrue:[
4341
ad65afd01683 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4340
diff changeset
   901
                        ^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
3532
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   902
                    ].
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   903
                ].
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   904
            ].
3585
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   905
            (oldName string endsWith:suffix string) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   906
                deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
3585
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   907
                (oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   908
                    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   909
                        "last rename was 
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   910
                            'fooXR' -> 'fooR'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   911
                         then, a good default for
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   912
                            'barXS' would be 'barS'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   913
                        "
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   914
                        ^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   915
                    ]
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   916
                ]
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   917
            ]
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   918
        ].
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   919
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   920
        (oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   921
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   922
                'fooX' -> 'fooY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   923
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   924
                'barX' would be 'barY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   925
            "
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   926
            left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   927
            right := lastNewName copyFrom:prefix size+1.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   928
            ^ left , right
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   929
        ] 
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   930
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   931
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   932
    suffix size > 0 ifTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   933
        |prefix2|
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   934
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   935
        "last rename was:
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   936
            'fooSUFF1' -> 'barSUFF1'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   937
         then, a good default for
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   938
            'fooSUFF2' -> 'barSUFF2'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   939
        "
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   940
        prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   941
        (oldName startsWith:prefix) ifTrue:[    
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   942
            prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   943
            ^ prefix2,(oldName copyFrom:(prefix size+1)).
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   944
        ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   945
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   946
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   947
    "/ was there something stripped at the end?
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   948
    suffix := oldName commonSuffixWith:lastOldName. 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   949
    [suffix size > 0] whileTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   950
        tryAgain := self
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   951
                    goodRenameDefaultFor:(oldName copyButLast:suffix size)
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   952
                    lastOld:(lastOldName copyButLast:suffix size)
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   953
                    lastNew:lastNewName.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   954
        tryAgain notNil ifTrue:[^ tryAgain].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   955
        suffix := suffix copyFrom:2.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   956
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   957
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   958
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   959
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   960
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   961
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   962
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   963
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   964
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   965
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   966
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   967
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'  
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   968
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   969
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   970
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   971
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'            
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   972
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'          
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   973
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   974
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   975
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'  
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   976
     self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'  
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   977
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   978
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   979
                       lastOld:'mti.odt2.level1HeadlineMatchPattern' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   980
                       lastNew:'Key_odt2_level1HeadlineMatchPattern'  
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   981
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   982
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   983
    "Modified: / 24-07-2011 / 11:06:03 / cg"
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   984
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   985
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   986
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   987
    "generate a reasonable default for a file rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   988
     (Try to rename multiple files in the new fileBrowser, 
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   989
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   990
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   991
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   992
     lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   993
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   994
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   995
    default := self goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName.
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   996
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   997
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
   998
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
   999
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1000
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1002
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1003
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1004
        lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1005
            ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1006
        ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1007
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1008
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1009
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1010
    default notNil ifTrue:[ 
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1011
        lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1012
        lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1013
        oldRest := oldName copyFrom:oldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1014
        
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1015
        ^ default , lastNewRest
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1016
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1017
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1019
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1020
        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1021
        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
        oldRest := oldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1023
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
        (lastNewRest endsWith:lastOldRest) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
  1025
            t := lastNewRest copyButLast:lastOldRest size.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1026
            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1027
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1028
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1029
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1030
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1031
    suffix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1032
        "/ last change changed something at the beginning
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
        prefix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
            "/ this name starts with the same characters
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
  1036
            lastRemoved := lastOldWOSuffix copyButLast:suffix size.
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
  1037
            lastInserted := lastNewWOSuffix copyButLast:suffix size.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
            (lastRemoved startsWith:lastInserted) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1039
                oldWOSuffix size >= lastInserted size ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1040
                    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1041
                ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
            ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1048
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1049
    "Modified: / 07-11-2006 / 13:58:39 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1050
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1051
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1052
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1053
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1054
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1055
    "return true, if k1 and k2 are adjacent keys on the keyboard.
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1056
     This is used to specially priorize plausible typing errors of adjacent keys.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1057
     CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else."
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1058
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1059
    ^ self isKey:k1 nextTo:k2 onKeyboard:(self keyboard)
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1060
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1061
    "
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1062
     self isKey:$a nextTo:$a   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1063
     self isKey:$a nextTo:$s   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1064
     self isKey:$a nextTo:$q   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1065
     self isKey:$a nextTo:$w   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1066
     self isKey:$a nextTo:$z   
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1067
     self isKey:$a nextTo:$x 
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1068
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1069
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1070
    "Modified: / 16-01-2008 / 17:17:31 / cg"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1071
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1072
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1073
isKey:k1 nextTo:k2 onKeyboard:keys
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1074
    "return true, if k1 and k2 are adjacent keys on the keyboard defined by keys"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1075
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1076
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1077
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1078
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1079
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1080
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1081
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1082
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1083
    ^ (row1-row2) abs <= 1 and:[(col1-col2) abs <= 1]
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1084
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1085
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1086
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1087
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1088
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1089
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1090
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1091
keyboard
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1092
    "the keyboard layout 
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1093
     (useful to figure out which keys are nearby a key, to find possible typing errors)
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1094
     CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else."
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1095
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1096
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1097
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1098
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1099
    lang == #de ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1100
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1101
               '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1102
               '*qwertzuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1103
               '**asdfghjkl:'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1104
               '***yxcvbnm' 
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1105
        ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1106
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1107
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1108
    lang == #fr ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1109
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1110
               '1234567890'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1111
               '*azertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1112
               '**qsdfghjklm'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1113
               '***wxcvbn,' 
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1114
        ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1115
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1116
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1117
    ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1118
           '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1119
           '*qwertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1120
           '**asdfghjkl:'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1121
           '***zxcvbnm' 
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1122
    ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1123
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1124
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1125
     self keyboard 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1126
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1127
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1128
    "Created: / 16-01-2008 / 17:17:13 / cg"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1129
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1130
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1131
!DoWhatIMeanSupport methodsFor:'code completion'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1132
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1133
codeCompletionFor: codeAspectArg language: languageOrNilArg method:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1134
    "provide code completion information by analyzing what the editing state is in codeViewArg
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1135
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1136
     the info as argument. Te interface has been defined in that way (and tight coupling with internals
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1137
     of the editor) because
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1138
        1) the completer needs to know about the text around the cursor position
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1139
        2) the edit operation for completion may be non-trivial
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1140
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1141
     For example, in many situations, both a completion of a unary selector before the cursor,
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1142
     or adding another keyword part after the cursor is posisble.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1143
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1144
     perform the completion.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1145
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1146
     An additional array containing a textual description for each suggestion is also provided, which could
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1147
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1148
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1149
     ContextOrNil is the current context, if this is called from the debugger;
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1150
     or nil, if called from the browser.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1151
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1152
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1153
    | language |
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1154
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1155
    codeAspect := codeAspectArg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1156
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1157
    languageOrNilArg notNil ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1158
        language := languageOrNilArg
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1159
    ] ifFalse:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1160
        contextOrNilArg notNil ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1161
            language := contextOrNilArg method programmingLanguage
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1162
        ] ifFalse:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1163
            methodOrNilArg notNil ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1164
                language := methodOrNilArg programmingLanguage          
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1165
            ] ifFalse:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1166
                classOrNilArg notNil ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1167
                    language := classOrNilArg programmingLanguage
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1168
                ]
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1169
            ]
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1170
        ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1171
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1172
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1173
    language notNil ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1174
        language isSmalltalk ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1175
            ^self codeCompletionForSmalltalkMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1176
        ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1177
        language isSTXJavaScript ifTrue:[
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1178
            ^self codeCompletionForJavascriptMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1179
        ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1180
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1181
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1182
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1183
    "/ No completion support for given language
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1184
    self breakPoint: #cg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1185
    self breakPoint: #jv.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1186
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1187
    "Created: / 27-09-2013 / 10:21:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1188
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1189
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1190
codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNilArg codeView:codeViewArg
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1191
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1192
     contextOrNil is the current context, if this is called from the debugger;
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1193
     nil, if called from the browser.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1194
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1195
     This is not yet done, sigh"
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1196
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1197
    | language |
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1198
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1199
    languageOrNil notNil ifTrue:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1200
        language := languageOrNil
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1201
    ] ifFalse:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1202
        contextOrNilArg notNil ifTrue:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1203
            language := contextOrNilArg method programmingLanguage.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1204
        ] ifFalse:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1205
            classOrNilArg notNil ifTrue:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1206
                language := classOrNilArg programmingLanguage.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1207
            ]
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1208
        ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1209
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1210
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1211
    language notNil ifTrue:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1212
        language isSmalltalk ifTrue:[
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1213
            ^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1214
        ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1215
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1216
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1217
    "/ No completion support for given language
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1218
    self breakPoint: #cg.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1219
    self breakPoint: #jv.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1220
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1221
    "Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1222
! !
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1223
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1224
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'!
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1225
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1226
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1227
    "provide code completion information by analyzing what the editing state is in codeViewArg
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1228
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1229
     the info as argument. The interface has been defined in that way (and tight coupling with internals
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1230
     of the editor) because
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1231
        1) the completer needs to know about the text around the cursor position
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1232
        2) the edit operation for completion may be non-trivial
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1233
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1234
     For example, in many situations, both a completion of a unary selector before the cursor,
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1235
     or adding another keyword part after the cursor is posisble.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1236
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1237
     perform the completion.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1238
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1239
     An additional array containing a textual description for each suggestion is also provided, which could
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1240
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1241
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1242
     ContextOrNil is the current context, if this is called from the debugger;
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1243
     or nil, if called from the browser.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1244
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1245
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1246
    languageOrNil := STXJavaScriptLanguage instance.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1247
    methodOrNil := methodOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1248
    classOrNil := classOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1249
    codeView := codeViewArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1250
    contextOrNil := contextOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1251
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1252
    JavaScriptCompletionEngine notNil ifTrue:[
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1253
        JavaScriptCompletionEngine new
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1254
           completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock.
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1255
    ].    
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1256
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1257
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1258
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1259
    self information:'Not yet supported'.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1260
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1261
    "Created: / 18-09-2013 / 16:24:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1262
    "Modified: / 25-09-2013 / 15:13:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1263
! !
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1264
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1265
!DoWhatIMeanSupport methodsFor:'code completion - Smalltalk'!
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1266
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1267
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1268
4379
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1269
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1270
     contextOrNil is the current context, if this is called from the debugger;
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1271
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1272
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1273
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1274
    
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1275
    |crsrPos char interval source node parent checkedNode instanceOrNilArg
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1276
     forceNewMessageSend classOfReceiver|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1277
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1278
    languageOrNil := SmalltalkLanguage instance.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1279
    classOrNil := classOrNilArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1280
    codeView := codeViewArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1281
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1282
    crsrPos := codeView characterPositionOfCursor"-1".
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1283
    char := codeView characterAtCharacterPosition:crsrPos.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1284
    "/ Transcript show:crsrPos; show:' '; showCR:char.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1285
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1286
        crsrPos := crsrPos - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1287
        char := codeView characterAtCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1288
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1289
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1290
    interval := codeView selectedInterval.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1291
    "/ Transcript show:'iv: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1292
    interval isEmpty ifTrue:[
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1293
        interval := crsrPos"-1" to:crsrPos.
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1294
        "/ Transcript show:'iv2: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1295
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1296
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1297
    source := codeView contentsAsString string.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1298
    source := source copyTo:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1299
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1300
    "/ this is too naive and stupid; if there is a syntactic error,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1301
    "/ we will not find a node for a long time (stepping back more and more,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1302
    "/ until reaching the beginning). This leads to a thousand and more times reparsing
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1303
    "/ without any progress.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1304
    "/ TODO: do it vice-versa, in that the parser does a callOut for every node generated
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1305
    "/ as it parses the code. Stop, when the interval is hit.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1306
    "/ that will also work for syntactic incorrect source code.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1307
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1308
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.   
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1309
        "/ Transcript show:'nd1: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1310
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1311
    node isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1312
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.   
4374
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1313
        "/ Transcript show:'nd2 try: '; showCR:node.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1314
        node isNil ifTrue:[
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1315
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1316
            self breakPoint:#cg.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1317
            "/ self information:'No parseNode found (syntax error before or in comment?)'.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1318
            ^ self.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  1319
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1320
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1321
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1322
    forceNewMessageSend := false.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1323
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1324
    "/ if there a separator between the variable's name and the cursor position...
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1325
    (codeView characterBeforeCursor isSeparator
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1326
        or:[ ')}]''' includes:codeView characterBeforeCursor ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1327
    ) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1328
        (node isVariable
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1329
            and:[ (parent := node parent) notNil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1330
            and:[ parent isMessage ]]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1331
        ) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1332
            "/ completion after a variable node...
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1333
            parent isKeyword ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1334
                "/ and it is a keyword message, we complete the keyword message instead
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1335
                node := parent.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1336
            ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1337
                "/ otherwise, a unary message is probably intended to be sent to the variable.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1338
                "/ (however, no character is available to determine what is useful)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1339
                forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1340
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1341
        ] ifFalse:[
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1342
            (node isMessage and:[node isUnary]) ifTrue:[
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1343
                "/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1344
                "/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1345
                forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1346
"/                "/ can we see what we get from foo?
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1347
"/                classOfReceiver := self 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1348
"/                                    classOfReceiver:node receiver
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1349
"/                                    inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1350
"/                classOfReceiver notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1351
"/                    |mthd|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1352
"/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1353
"/                    mthd := classOfReceiver lookupMethodFor:node selector.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1354
"/                    mthd notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1355
"/                        self halt.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1356
"/                        (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1357
"/                            forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1358
"/                        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1359
"/                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1360
"/                ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1361
            ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1362
        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1363
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1364
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1365
    forceNewMessageSend ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1366
        "/ completion with nothing to start (right after a variable)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1367
        "/ see what the variable can understand and present the most useful stuff (very thin ice here)
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1368
        classOfReceiver := self classOfNode:node.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1369
        classOfReceiver isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1370
            "/ it does not make sense to offer anything, if we don't have any idea of what this
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1371
            "/ will be...
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1372
            Screen current beep.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1373
        ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1374
            |superClass possible choice|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1375
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1376
            possible := classOfReceiver selectors.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1377
            superClass := classOfReceiver superclass.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1378
            [superClass notNil and:[(possible size + superClass selectors size) < 50]] whileTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1379
                possible := possible,superClass selectors.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1380
                superClass := superClass superclass.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1381
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1382
            possible := possible copy sort.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1383
            choice := self askUserForCompletion:('Message to "%1"' bindWith:node name) for:codeView from:possible.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1384
            choice isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1385
                Screen current beep. 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1386
                ^ self
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1387
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1388
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1389
            codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1390
                undoableDo:[ 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1391
                    codeView insertStringAtCursor:choice
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1392
                ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1393
                info:'Completion'.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1394
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1395
        ^ self
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1396
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1397
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1398
    node isVariable ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1399
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1400
        ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1401
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1402
    node isLiteral ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1403
        node value isSymbol ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1404
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1405
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1406
        ].
4348
d935a4f7c740 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4346
diff changeset
  1407
        ^ self "/ huh - strings or what?
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1408
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1409
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1410
    checkedNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1411
    [checkedNode notNil] whileTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1412
        checkedNode isMessage ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1413
            "/ completion in a message-send
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1414
            contextOrNilArg notNil ifTrue:[
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1415
"/                |rcvrNode idx rcvr val|
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1416
"/
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1417
"/                (rcvrNode := checkedNode receiver) isVariable ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1418
"/                    rcvrNode isSelf ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1419
"/                        classOrNil := contextOrNil receiver class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1420
"/                    ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1421
"/                        (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1422
"/                            val := contextOrNil argsAndVars at:idx.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1423
"/                            classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1424
"/                        ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1425
"/                            (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1426
"/                                val := contextOrNil receiver instVarNamed:rcvrNode name.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1427
"/                                classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1428
"/                            ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1429
"/                        ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1430
"/                    ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1431
"/                ].
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1432
                instanceOrNilArg := contextOrNilArg receiver
4326
4dbf9b13bc59 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4314
diff changeset
  1433
            ].
4344
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1434
            self 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1435
                codeCompletionForMessage:checkedNode 
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1436
                inClass:classOrNil instance:instanceOrNilArg 
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1437
                context:contextOrNilArg codeView:codeView.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1438
            ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1439
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1440
        checkedNode isMethod ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1441
            "/ completion in a method's selector pattern
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1442
            self codeCompletionForMethodSpec:checkedNode.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1443
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1444
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1445
        checkedNode := checkedNode parent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1446
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1447
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1448
    self information:'Node is neither variable nor message.'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1449
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1450
    "Created: / 18-09-2013 / 15:25:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1451
!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1452
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1453
codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1454
    "provide code completion information by analyzing what the editing state is in codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1455
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1456
     the info as argument. The interface has been defined in that way (and tight coupling with internals
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1457
     of the editor) because
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1458
        1) the completer needs to know about the text around the cursor position
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1459
        2) the edit operation for completion may be non-trivial
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1460
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1461
     For example, in many situations, both a completion of a unary selector before the cursor,
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1462
     or adding another keyword part after the cursor is posisble.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1463
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1464
     perform the completion.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1465
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1466
     An additional array containing a textual description for each suggestion is also provided, which could
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1467
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1468
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1469
     ContextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1470
     or nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1471
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1472
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1473
    |crsrPos char interval source partialSource suggestions1 suggestions2 actions1 actions2 title1 title2|
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1474
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1475
    languageOrNil := SmalltalkLanguage instance.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1476
    methodOrNil := methodOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1477
    classOrNil := classOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1478
    codeView := codeViewArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1479
    contextOrNil := contextOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1480
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1481
"/    classOrNil isNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1482
"/        self information:'No class'.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1483
"/        ^ self.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1484
"/    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1485
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1486
    crsrPos := codeView characterPositionOfCursor"-1".
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1487
    char := codeView characterAtCharacterPosition:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1488
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1489
        crsrPos := crsrPos - 1.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1490
        char := codeView characterAtCharacterPosition:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1491
    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1492
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1493
    interval := crsrPos-1 to:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1494
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1495
    source := codeView contentsAsString string.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1496
    partialSource := source copyTo:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1497
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1498
    self 
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1499
        tryCodeCompletionWithSource:partialSource nodeInterval:interval 
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1500
        into:[:listOfSuggestions :listOfActions :titleWhenAsking |
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1501
            suggestions1 := listOfSuggestions.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1502
            actions1 := listOfActions.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1503
            title1 := titleWhenAsking.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1504
            "/ suggestions1 size>100 ifTrue:[ self halt].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1505
        ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1506
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1507
    suggestions1 notEmptyOrNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1508
        actionBlock value:suggestions1 value:actions1 value:title1.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1509
    ] ifFalse:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1510
        self 
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1511
            tryCodeCompletionWithSource:source nodeInterval:interval 
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1512
            into:[:listOfSuggestions :listOfActions :titleWhenAsking |  
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1513
                suggestions2 := listOfSuggestions.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1514
                actions2 := listOfActions.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1515
                title2 := titleWhenAsking.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1516
            ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1517
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1518
        suggestions2 notEmptyOrNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1519
            actionBlock value:suggestions2 value:actions2 value:title2.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1520
        ]
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1521
    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1522
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1523
    "Created: / 18-09-2013 / 15:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1524
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1525
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1526
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1527
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1528
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1529
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1530
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1531
     contextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1532
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1533
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1534
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1535
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1536
    ^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1537
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1538
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1539
    "Modified: / 28-08-2013 / 17:15:25 / cg"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1540
    "Modified: / 18-09-2013 / 14:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1541
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1542
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1543
codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1544
    <resource: #obsolete>
4379
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1545
    "provide code completion information by analyzing what the editing state is in codeViewArg
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1546
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1547
     the info as argument. Te interface has been defined in that way (and tight coupling with internals
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1548
     of the editor) because
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1549
        1) the completer needs to know about the text around the cursor position
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1550
        2) the edit operation for completion may be non-trivial
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1551
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1552
     For example, in many situations, both a completion of a unary selector before the cursor,
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1553
     or adding another keyword part after the cursor is posisble.
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1554
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1555
     perform the completion.
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1556
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1557
     An additional array containing a textual description for each suggestion is also provided, which could
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1558
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1559
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1560
     ContextOrNil is the current context, if this is called from the debugger;
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1561
     or nil, if called from the browser.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1562
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1563
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1564
    |crsrPos char interval source partialSource suggestions1 suggestions2 actions1 actions2 title1 title2|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1565
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1566
    methodOrNil := methodOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1567
    classOrNil := classOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1568
    codeView := codeViewArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1569
    contextOrNil := contextOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1570
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1571
"/    classOrNil isNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1572
"/        self information:'No class'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1573
"/        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1574
"/    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1575
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1576
    crsrPos := codeView characterPositionOfCursor"-1".
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1577
    char := codeView characterAtCharacterPosition:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1578
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1579
        crsrPos := crsrPos - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1580
        char := codeView characterAtCharacterPosition:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1581
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1582
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1583
    interval := crsrPos-1 to:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1584
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1585
    source := codeView contentsAsString string.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1586
    partialSource := source copyTo:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1587
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1588
    self 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1589
        tryCodeCompletionWithSource:partialSource nodeInterval:interval 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1590
        into:[:listOfSuggestions :listOfActions :titleWhenAsking |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1591
            suggestions1 := listOfSuggestions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1592
            actions1 := listOfActions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1593
            title1 := titleWhenAsking.
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1594
            "/ suggestions1 size>100 ifTrue:[ self halt].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1595
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1596
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1597
    suggestions1 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1598
        actionBlock value:suggestions1 value:actions1 value:title1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1599
    ] ifFalse:[
4353
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1600
        self 
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1601
            tryCodeCompletionWithSource:source nodeInterval:interval 
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1602
            into:[:listOfSuggestions :listOfActions :titleWhenAsking |  
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1603
                suggestions2 := listOfSuggestions.
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1604
                actions2 := listOfActions.
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1605
                title2 := titleWhenAsking.
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1606
            ].
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  1607
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1608
        suggestions2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1609
            actionBlock value:suggestions2 value:actions2 value:title2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1610
        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1611
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1612
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1613
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1614
!DoWhatIMeanSupport methodsFor:'code completion-helpers'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1615
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1616
askUserForCompletion:what for:codeView at:position from:allTheBest 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1617
    |list choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1618
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1619
    "/ cg: until the new stuff works,...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1620
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1621
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1622
"/    allTheBest isEmpty ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1623
"/        ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1624
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1625
"/    allTheBest size == 1 ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1626
"/        ^ allTheBest first
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1627
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1628
"/    list := allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1629
"/    LastChoices notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1630
"/        lastChoice := LastChoices at:what ifAbsent:nil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1631
"/        lastChoice notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1632
"/            list := { lastChoice allBold } , (list copyWithout:lastChoice).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1633
"/        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1634
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1635
"/    choice := Tools::CodeCompletionMenu 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1636
"/                openFor:codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1637
"/                at:position
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1638
"/                with:allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1639
"/    LastChoices isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1640
"/        LastChoices := Dictionary new.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1641
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1642
"/    LastChoices at:what put:choice.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1643
"/    ^ choice string
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1644
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1645
    "Created: / 16-02-2010 / 10:09:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1646
    "Modified: / 28-08-2013 / 16:41:35 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1647
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1648
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1649
askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1650
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1651
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1652
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1653
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1654
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1655
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1656
    LastChoices notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1657
        lastChoice := LastChoices at:what ifAbsent:nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1658
        lastChoice notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1659
            list := {lastChoice. nil. } , (list copyWithout:lastChoice).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1660
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1661
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1662
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1663
    list size < 30 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1664
        |menu idx exitKey|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1665
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1666
        menu := PopUpMenu labels:list.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1667
        menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1668
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1669
                hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1670
                    exitKey := key.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1671
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1672
                hide].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1673
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1674
        idx := menu startUp.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1675
        idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1676
            exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1677
                codeView keyPress:exitKey x:0 y:0.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1678
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1679
            ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1680
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1681
        choice := list at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1682
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1683
        resources := codeView application isNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1684
                        ifTrue:[ codeView resources]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1685
                        ifFalse:[ codeView application resources ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1686
                    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1687
        choice := Dialog
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1688
           choose:(resources string:'Choose ',what)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1689
           fromList:list
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1690
           lines:20
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1691
           title:(resources string:'Code completion').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1692
        choice isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1693
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1694
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1695
    LastChoices isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1696
        LastChoices := Dictionary new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1697
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1698
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1699
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1700
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1701
    "Created: / 10-11-2006 / 14:00:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1702
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1703
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1704
classOfNode:aNode
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1705
    "when showing possible completions for a message, 
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1706
     it is a good idea to know what the kind receiver is."
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1707
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1708
    | nm nodeVal receiverClass nodeSelector nodeReceiver|
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1709
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  1710
    aNode isBlock ifTrue:[
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  1711
        ^ Block
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  1712
    ].
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1713
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1714
    (nodeVal := self valueOfNode:aNode) notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1715
        "/ knowing the value is always great!!
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1716
        ^ nodeVal class
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1717
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1718
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1719
    aNode isVariable ifTrue:[
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1720
        nm := aNode name.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1721
        nm = 'self' ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1722
            classOrNil isNil ifTrue:[^ UndefinedObject].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1723
            ^ classOrNil
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1724
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1725
        nm = 'super' ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1726
            classOrNil isNil ifTrue:[^ Object].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1727
            ^ classOrNil superclass
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1728
        ].
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1729
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1730
"/        classOrNil notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1731
"/            (classOrNil allInstVarNames includes:nm) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1732
"/                "/ could look at existing instances here...
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1733
"/                self breakPoint:#cg.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1734
"/            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1735
"/        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1736
        ^ nil
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1737
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1738
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1739
    aNode isMessage ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1740
        nodeSelector := aNode selector.
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1741
        nodeReceiver := aNode receiver.
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1742
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1743
        "/ some hardwired knowlegde here
4390
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1744
        ( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: nodeSelector ) ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1745
            receiverClass := self classOfNode:nodeReceiver.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1746
            receiverClass notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1747
                receiverClass isBehavior ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1748
                    receiverClass isMeta ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1749
                        ^ receiverClass theNonMetaclass
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1750
                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1751
                ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1752
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1753
        ].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1754
        classOrNil notNil ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1755
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1756
                ^ classOrNil class
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1757
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1758
        ].
4390
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1759
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1760
        (nodeSelector = #'asFilename') ifTrue:[
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1761
            ^ Filename
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1762
        ].
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1763
        (nodeSelector = #'size') ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1764
            ^ SmallInteger
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1765
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  1766
4411
ff6e37d9ab5f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  1767
        "/ some wellknown boolean returners (need better type inference here)
ff6e37d9ab5f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  1768
        (#( isNil notNil not isEmptyOrNil notEmptyOrNil notEmpty isEmpty 
4413
9a6c7c84ec0e class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4412
diff changeset
  1769
            isBehavior isMeta
4411
ff6e37d9ab5f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4410
diff changeset
  1770
            = ~= == ~~ > >= < <= 
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1771
            includes: contains:
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1772
            and: or:
4390
8302e1520ab1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4389
diff changeset
  1773
            exists atEnd
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1774
        ) includes:nodeSelector ) ifTrue:[
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1775
            ^ True "/ Boolean - not boolean; it does not contain the full protocol (would not find ifTrue:)
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1776
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  1777
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  1778
        ( #( + - * / // \\ ) includes:nodeSelector) ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1779
            "/ assume numeric
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1780
            ^ Number
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1781
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  1782
4412
c75ff2894fb9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1783
        ( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  1784
            "/ assume behavior
4412
c75ff2894fb9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
  1785
            ^ Behavior
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  1786
        ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1787
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1788
    ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1789
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1790
    "Created: / 28-08-2013 / 16:34:53 / cg"
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1791
!
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1792
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1793
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1794
    "looking for all symbols is way too much and inprecise;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1795
     experiment: only present symbols which are used by the class,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1796
     and classes in that class category. We'll see..."
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1797
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1798
    |sym possibleCompletions longest editAction start stop addSymbol
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1799
     parentSelector parent symbolSelectorClass|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1800
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1801
    "/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1802
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1803
    start := (nodeOrNil ? tokenOrNil) start.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1804
    stop := (nodeOrNil ? tokenOrNil) stop.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1805
    (codeView characterAtCharacterPosition:stop) == $' ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1806
        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1807
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1808
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1809
    sym := (nodeOrNil ? tokenOrNil) value.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1810
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1811
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1812
    addSymbol :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1813
        [:aSymbol |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1814
            (aSymbol startsWith:sym) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1815
                (aSymbol = sym) ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1816
                    possibleCompletions add:aSymbol
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1817
                ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1818
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1819
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1820
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1821
    (nodeOrNil notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1822
    and:[ (parent := nodeOrNil parent) notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1823
    and:[ parent isMessage ]]) ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1824
        parentSelector := parent selector.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1825
        ( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1826
            symbolSelectorClass := self classOfNode:parent receiver.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1827
        ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1828
        ( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1829
            "/ assume that send-target will be self.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1830
            (methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1831
                addSymbol value:(methodOrNil selector,'Changed').
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1832
            ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1833
            symbolSelectorClass := classOrNil.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1834
        ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1835
        ( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1836
            symbolSelectorClass := self classOfNode:parent arguments second.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1837
        ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1838
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1839
        symbolSelectorClass notNil ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1840
            symbolSelectorClass withAllSuperclassesDo:[:cls |
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1841
                cls ~~ Object ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1842
                    cls ~~ Model ifTrue:[
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1843
                        cls methodDictionary keysDo:addSymbol.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1844
                    ]
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1845
                ]
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1846
            ]
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1847
        ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1848
    ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1849
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1850
    (considerAll or:[classOrNil isNil]) ifTrue:[
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1851
        Symbol allInstancesDo:addSymbol.
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1852
    ] ifFalse:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1853
        Smalltalk allClassesInCategory:classOrNil do:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1854
            cls theNonMetaclass instAndClassMethodsDo:[:mthd |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1855
                mthd usedSymbols do:addSymbol
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1856
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1857
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1858
    ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1859
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1860
    possibleCompletions sort.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1861
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1862
    longest := possibleCompletions longestCommonPrefix.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1863
    possibleCompletions remove:longest ifAbsent:[].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1864
    possibleCompletions addFirst: longest.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1865
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1866
    editAction :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1867
        [:chosenIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1868
            |chosen oldSym oldLen newLen|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1869
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1870
            chosen := possibleCompletions at:chosenIndex.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1871
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1872
            (codeView characterAtCharacterPosition:start) == $# ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1873
                start := start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1874
            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1875
            (codeView characterAtCharacterPosition:start) == $' ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1876
                start := start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1877
            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1878
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1879
            oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1880
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1881
            codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1882
                undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1883
                    codeView replaceFromCharacterPosition:start to:stop with:chosen 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1884
                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1885
                info:'Completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1886
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1887
            (chosen startsWith:oldSym) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1888
                oldLen := stop - start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1889
                newLen := chosen size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1890
                codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1891
                codeView dontReplaceSelectionOnInput
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1892
            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1893
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1894
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1895
    actionBlock value:possibleCompletions value:editAction value:'symbol'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1896
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1897
    "Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1898
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1899
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1900
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1901
codeCompletionForMessage:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1902
    |selector srchClass implClass 
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1903
     bestSelectors selector2 bestSelectors2 bestSelectors3 allBest best info numArgs
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1904
     newParts nSelParts oldLen newLen selectorParts 
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1905
     findBest parentNode nodeReceiver selectorsSentInCode split editAction parentNodeClassIfKnown 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1906
     receiverNodeClassIfKnown|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1907
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1908
    "/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1909
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1910
    findBest := [:node :selector |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1911
        |srchClass bestSelectors bestPrefixes|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1912
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1913
        srchClass := self classOfNode:node.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1914
        bestSelectors := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1915
        bestSelectors := self 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1916
                            withoutSelectorsUnlikelyFor:srchClass 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1917
                            from:bestSelectors
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1918
                            forPartial:selector.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1919
        (bestSelectors includes:selector) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1920
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1921
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1922
        bestSelectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1923
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1924
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1925
    selector := node selector.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1926
    parentNode := node parent.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1927
    nodeReceiver := node receiver.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1928
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1929
    "/ if there is already space before the cursor, and the parent node is not a message,
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1930
    "/ do not attempty to complete the current message.
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1931
    "/ If it is a message, we will look for parent-message completion also below (best2 stuff)
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1932
    (codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1933
        (parentNode notNil and:[ parentNode isMessage ]) ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1934
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1935
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1936
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1937
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1938
    bestSelectors := findBest value:nodeReceiver value:selector.  
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1939
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1940
    "/ if the receiver is a real variable, 
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1941
    "/ we can look for other messages being sent to that variable in the current method.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1942
    "/ Also, if there is are assignment to it (like constants or '<class> new'), use that as a hint...
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  1943
    (tree notNil 
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1944
        and:[ nodeReceiver isVariable 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1945
        and:[ nodeReceiver isSelf not
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1946
        and:[ nodeReceiver isSuper not ]]])
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1947
    ifTrue:[
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1948
        |classesFromAssignmentsToReceiver otherMessagesToReceiver possibleClasses possibleClassesFromOtherSends|
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1949
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1950
        classesFromAssignmentsToReceiver := tree allAssignmentNodes 
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1951
                                    collect:[:eachAssignmentNode |
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1952
                                                |cls|
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1953
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1954
                                                (nodeReceiver = eachAssignmentNode variable
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1955
                                                    and:[ (cls := self classOfNode:eachAssignmentNode value) notNil ]
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1956
                                                ) ifTrue:[
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1957
                                                    cls
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1958
                                                ] ifFalse:[
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1959
                                                    nil
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1960
                                                ]
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1961
                                            ]
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1962
                                    thenSelect:[:classOrNil | classOrNil notNil].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1963
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1964
        possibleClasses := classesFromAssignmentsToReceiver.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1965
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1966
        otherMessagesToReceiver := tree allMessageNodes 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1967
                                    select:[:eachMessageNode | 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1968
                                                nodeReceiver = eachMessageNode receiver
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1969
                                                and:[ selector ~= eachMessageNode selector]]
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1970
                                    thenCollect:[:eachNode | eachNode selector].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1971
        otherMessagesToReceiver notEmpty ifTrue:[
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1972
            otherMessagesToReceiver := otherMessagesToReceiver asSet.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1973
            possibleClassesFromOtherSends := 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1974
                Smalltalk allClassesForWhich:
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1975
                            [:cls |
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1976
                                cls isLoaded 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1977
                                and:[ otherMessagesToReceiver 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1978
                                        conform:[:eachSelectorSent | cls includesSelector: "canUnderstand:" eachSelectorSent]]
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1979
                            ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1980
            possibleClasses := possibleClasses , possibleClassesFromOtherSends.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1981
        ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1982
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1983
        "/ if the receiver is a class/classInstVar,
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1984
        "/ include the class of its current value and UndefinedObject. 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1985
        "/ This helps to complete class methods and (lazy) initializer code.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1986
        (classOrNil notNil) ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1987
            |tryValue currentValue|
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1988
4409
8f05ef5d0e42 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4408
diff changeset
  1989
            tryValue := false.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1990
            (classOrNil theNonMetaclass allClassVarNames includes: nodeReceiver name) ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1991
                tryValue := true.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1992
                currentValue := classOrNil theNonMetaclass classVarAt:nodeReceiver name.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1993
            ] ifFalse:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1994
                (classOrNil isMeta and:[ classOrNil allInstVarNames includes: nodeReceiver name ]) ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1995
                    tryValue := true.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1996
                    currentValue := classOrNil theNonMetaclass instVarNamed:nodeReceiver name.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1997
                ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1998
            ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1999
            tryValue ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2000
                currentValue notNil ifTrue:[ possibleClasses := { UndefinedObject } , possibleClasses ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2001
                possibleClasses := { currentValue class } , possibleClasses.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2002
            ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2003
        ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2004
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2005
        (possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2006
            bestSelectors := Set new.
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2007
            possibleClasses do:[:eachClass |
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2008
                |bestSelectorsForClass|
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2009
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2010
                bestSelectorsForClass := Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true.
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2011
                bestSelectors addAll:bestSelectorsForClass. 
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2012
            ].
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2013
            bestSelectors := bestSelectors asOrderedCollection
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2014
        ].
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2015
    ].
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2016
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2017
    "/ if we are behind a keyword messages colon,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2018
    "/ only look for matching prefix selectors;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2019
    "/ also, a good completion is to insert an argument;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2020
    "/ the name of the variable from the implementation, as comment, and selected might be a good one!!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2021
    selector isKeyword ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2022
        codeView characterBeforeCursor == $: ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2023
            bestSelectors := bestSelectors select:[:sel | sel startsWith:selector].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2024
            bestSelectors isEmpty ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2025
                "/ nothing better around
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2026
                |argIndex argNames impls|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2027
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2028
                argIndex := node selectorParts size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2029
                argNames := Set new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2030
                impls := Smalltalk allImplementorsOf:selector.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2031
                impls size < 10 ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2032
                    impls do:[:eachImplClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2033
                        |mthd argName|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2034
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2035
                        mthd := (eachImplClass compiledMethodAt:selector).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2036
                        argName := mthd methodArgNames at:argIndex.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2037
                        argNames add:(argName,' in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2038
                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2039
                    argNames notEmptyOrNil ifTrue: [
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2040
                        argNames := argNames asOrderedCollection sort.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2041
                        actionBlock 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2042
                            value:argNames
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2043
                            value:[:selIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2044
                                  ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2045
                            value: 'argument name hint'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2046
                        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2047
                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2048
                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2049
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2050
        ].
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2051
    ] ifFalse:[
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2052
        "/ when completing a non-keyword AND the parent is a keyword message,
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2053
        "/ only consider longer keyword messages or unary messages
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2054
        (parentNode notNil and:[ parentNode isMessage and:[parentNode selector isKeywordSelector ]]) ifTrue:[
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2055
            bestSelectors := bestSelectors select:[:sel | sel isUnarySelector ]
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2056
        ]
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2057
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2058
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2059
    bestSelectors := bestSelectors asOrderedCollection sort:[:a :b | a size < b size].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2060
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2061
    (selector isUnarySelector 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2062
    and:[ parentNode notNil 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2063
    and:[ parentNode isMessage ]]) ifTrue:[
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2064
        (selector2 := parentNode selector) isKeywordSelector ifTrue:[
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2065
            "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2066
            "/ i.e. look if there is a longer keyword possible
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2067
            selector2 := selector2,selector.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2068
            bestSelectors2 := findBest value:parentNode receiver value:selector2.
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2069
            bestSelectors2 := bestSelectors2 select:[:sel | sel isKeywordSelector and:[ sel startsWith:selector2]].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2070
            bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2071
            bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2072
        ] ifFalse:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2073
            |kwSels|
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2074
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2075
            "/ if its a unary message AND the parent is a unary or binary node, try again, sending the partial message
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2076
            "/ as a keyword to the parent node.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2077
            "/ this is the case when after "foo binOp bar if", which should include ifTrue: in the result.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2078
            "/ transform from 
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2079
            "/    foo == (shift if)
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2080
            "/        nonKWsel-msg(parent)
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2081
            "/     /         \
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2082
            "/    /           \
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2083
            "/  rcvr         sel-unary(node)
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2084
            "/              /
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2085
            "/             /
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2086
            "/           arg
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2087
            "/
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2088
            "/ into:
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2089
            "/    (foo == shift) if
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2090
            "/ 
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2091
            "/        nonKWsel-msg(parent)
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2092
            "/     /         \
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2093
            "/    /           \
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2094
            "/  rcvr         sel-unary(node)
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2095
            "/              /
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2096
            "/             /
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2097
            "/           arg
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2098
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2099
            kwSels := findBest value:parentNode value:selector.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2100
            kwSels := kwSels select:[:sel | sel isKeywordSelector].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2101
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2102
            kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2103
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2104
            bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2105
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2106
            "/ these need to go to bestSelectors (see editAction)
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2107
            parentNodeClassIfKnown := self classOfNode:parentNode.
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2108
            (parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2109
                "/ this is so common, that it deserves a special case:
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2110
                "/ if we complete an if after some boolean message e.g '(a == b) if'
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2111
                "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2112
                bestSelectors := self 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2113
                                    withoutSelectorsUnlikelyFor:parentNodeClassIfKnown 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2114
                                    from:bestSelectors
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2115
                                    forPartial:selector.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2116
                kwSels := self 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2117
                            withoutSelectorsUnlikelyFor:parentNodeClassIfKnown 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2118
                            from:kwSels
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2119
                            forPartial:selector.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2120
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2121
                "/ put keyword selectors in front, because they are very likely
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2122
                bestSelectors := kwSels , bestSelectors.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2123
            ] ifFalse:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2124
                "/ put them at the end
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2125
                bestSelectors := bestSelectors , kwSels.
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2126
            ].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2127
        ]
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2128
    ].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2129
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2130
    (selector isUnarySelector 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2131
    and:[ node isMessage ]) ifTrue:[
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2132
        receiverNodeClassIfKnown := self classOfNode:nodeReceiver.
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2133
        (receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2134
            "/ this is so common, that it deserves a special case:
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2135
            "/ if we complete an if after some boolean message e.g '(a == b) if'
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2136
            "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2137
            bestSelectors := self 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2138
                                withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2139
                                from:bestSelectors
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2140
                                forPartial:selector.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2141
        ].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2142
    ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2143
    (selector isUnarySelector 
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2144
    and:[ parentNode notNil
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2145
    and:[ parentNode isMessage
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2146
    and:[ parentNode selector isKeyword ]]]) ifTrue:[
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2147
        "/ completing an already existing keyword message with somthing starting with
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2148
        "/ if, and, or or while.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2149
        "/ here, offer a special completion which inserts parenthesis / brackets around the already
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2150
        "/ existing message. Do this only, if the existing message makes sense.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2151
        ((
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2152
            #( 'ifTrue' 'ifFalse' 'and' 'or' 'whileTrue' 'whileFalse' )
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2153
        ) contains:[:part | part startsWith:selector]) ifTrue:[
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2154
            (Smalltalk allImplementorsOf:parentNode selector) notEmpty ifTrue:[
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2155
                |selsP selsB|
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2156
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2157
                selsP := #( 'ifTrue:' 'ifFalse:'  ) 
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2158
                            select:[:sel | sel startsWith:selector]
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2159
                            thenCollect:[:sel | '() ',sel].
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2160
                selsB := #( 'whileTrue:' 'whileFalse:' ) 
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2161
                            select:[:sel | sel startsWith:selector]
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2162
                            thenCollect:[:sel | '[] ',sel].
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2163
                bestSelectors3 := selsP , selsB.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2164
            ].
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2165
        ].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2166
    ] ifFalse:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2167
        "/ also offer adding brackets around a while expression
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2168
        (node receiver isBlock) ifFalse:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2169
            |sels|
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2170
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2171
            sels := #( 'whileTrue:' 'whileFalse:' ) 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2172
                        select:[:sel | sel startsWith:selector]
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2173
                        thenCollect:[:sel | '[] ',sel].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2174
            bestSelectors3 := sels.
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2175
        ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2176
    ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2177
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2178
    allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()).
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2179
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2180
    split := 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2181
        [:list :splitHow |
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2182
            |part1 part2 all|
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2183
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2184
            part1 := list select:splitHow.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2185
            part2 := list reject:splitHow.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2186
            part1 isEmpty ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2187
                all := part2.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2188
            ] ifFalse:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2189
                part2 isEmpty ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2190
                    all := part1.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2191
                ] ifFalse:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2192
                    all := part1 , part2.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2193
                ]
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2194
            ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2195
            all
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2196
        ].
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2197
    "/ sort: prefixes first.
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2198
    selector2 notNil ifTrue:[
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2199
        allBest := split value:allBest value:[:sel | (sel startsWith:selector) or:[sel startsWith:selector2]]. 
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2200
    ].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2201
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2202
    "/ if receiver is super, always include the method's own selector
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2203
    nodeReceiver isSuper ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2204
        (tree isMethod) ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2205
            |mSel|
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2206
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2207
            mSel := tree selector.
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2208
            mSel notNil ifTrue:[
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2209
                (mSel startsWith:selector) ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2210
                    "/ already the word before the cursor?
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2211
                    (mSel ~= selector) ifTrue:[
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2212
                        allBest remove:mSel ifAbsent:[].
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2213
                        allBest addFirst:mSel.
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2214
                    ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2215
                ]
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2216
            ]
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2217
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2218
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2219
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2220
    allBest := (bestSelectors3 ? #()) , allBest.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2221
    allBest isEmptyOrNil ifTrue:[ ^ self ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2222
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2223
    selectorsSentInCode notNil ifTrue:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2224
        "/ the one's already sent in the code are moved to the top of the list.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2225
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2226
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2227
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2228
    "/ the on'es which are a prefix are moved towards the top of the list
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2229
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2230
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2231
false ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2232
    srchClass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2233
        implClass := srchClass whichClassIncludesSelector:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2234
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2235
        implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2236
        implClass size == 1 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2237
            implClass := implClass first.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2238
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2239
            implClass := nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2240
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2241
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2242
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2243
    info := best storeString.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2244
    implClass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2245
        info := implClass name , ' >> ' , info.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2246
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2247
    self information:info.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2248
].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2249
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2250
    editAction := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2251
        [:index |
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2252
            |chosen parentsToInsert|
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2253
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2254
            chosen := allBest at:index.
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2255
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2256
            chosen ~= selector ifTrue:[
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2257
                (bestSelectors3 notNil and:[bestSelectors3 includes:chosen]) ifTrue:[
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2258
                    parentsToInsert := chosen copyTo:2.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2259
                    chosen := chosen copyFrom:4.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2260
                ].
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2261
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2262
                numArgs := chosen numArgs.
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2263
                (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2264
                    selectorParts := parentNode selectorParts , node selectorParts.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2265
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2266
                    selectorParts := node selectorParts.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2267
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2268
                nSelParts := selectorParts size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2269
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2270
                newParts := chosen asCollectionOfSubstringsSeparatedBy:$:.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2271
                newParts := newParts select:[:part | part size > 0].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2272
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2273
                codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2274
                    undoableDo:[
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2275
                        |newCursorPosition stop checkForArgumentTemplates|
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2276
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2277
                        checkForArgumentTemplates := false.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2278
                        (selector isUnarySelector and:[chosen isKeywordSelector]) ifTrue:[ checkForArgumentTemplates := true ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2279
                        numArgs > nSelParts ifTrue:[
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2280
                            "/ new selector has more arguments; append them
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2281
                            stop := selectorParts last stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2282
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2283
                            "/ append the rest ...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2284
                            numArgs downTo:nSelParts+1 do:[:idx |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2285
                                |newPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2286
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2287
                                newPart := newParts at:idx.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2288
                                (chosen endsWith:$:) ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2289
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2290
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2291
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2292
                                (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2293
                                    newPart := ':' , newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2294
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2295
                                newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2296
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2297
                                codeView replaceFromCharacterPosition:stop to:stop with:newPart.
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2298
                                "/ remember the last replacement's end as new cursor position
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2299
                                newCursorPosition isNil ifTrue:[ newCursorPosition := stop + newPart size ].
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2300
                            ].
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2301
                            checkForArgumentTemplates := true.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2302
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2303
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2304
                        "/ replace existing parts
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2305
                        (nSelParts min:newParts size) downTo:1 do:[:idx |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2306
                            |newPart oldPartialToken start stop|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2307
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2308
                            newPart := newParts at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2309
                            oldPartialToken := selectorParts at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2310
                            start := oldPartialToken start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2311
                            stop := oldPartialToken stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2312
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2313
                            (chosen endsWith:$:) ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2314
                                (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2315
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2316
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2317
                            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2318
                                (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2319
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2320
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2321
                                    (codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2322
                                        newPart := newPart , ' '
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2323
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2324
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2325
        "/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2326
        "/                        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2327
        "/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2328
                            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2329
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2330
                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2331
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2332
                            oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2333
                            newLen := newPart size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2334
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2335
                            "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2336
                            "/ remember the last replacement's end as new cursor position
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2337
                            newCursorPosition isNil ifTrue:[ newCursorPosition := stop + (newLen-oldLen) ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2338
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2339
                        codeView cursorToCharacterPosition:newCursorPosition.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2340
                        codeView cursorRight.  "/ avoid going to the next line !!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2341
                        codeView dontReplaceSelectionOnInput.
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2342
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2343
                        checkForArgumentTemplates ifTrue:[
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2344
                            "/ add opening brackets, etc.
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2345
                            self insertAdditonalStuffAfterSelector:chosen.
4372
30090fbaec0a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4371
diff changeset
  2346
                        ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2347
                        parentsToInsert notNil ifTrue:[
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2348
                            |sav|
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2349
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2350
                            sav := codeView characterPositionOfCursor-1.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2351
                            codeView insertString:(parentsToInsert copyLast:1) atCharacterPosition:node receiver stop+1.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2352
                            codeView insertString:(parentsToInsert copyFirst:1) atCharacterPosition:parentNode start.
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2353
                            codeView cursorToCharacterPosition:sav+2; cursorRight
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2354
                        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2355
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2356
                info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2357
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2358
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2359
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2360
    actionBlock value:allBest value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2361
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2362
    "Created: / 10-11-2006 / 13:18:27 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2363
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4311
9ff3061bd3b4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4310
diff changeset
  2364
    "Modified: / 27-07-2013 / 16:34:10 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2365
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2366
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2367
codeCompletionForMethodSpec:node 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2368
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2369
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2370
    self 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2371
        codeCompletionForMethodSpec:node
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2372
        into:
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2373
            [:suggestions :action :whatIsIt |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2374
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2375
            |chosen|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2376
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2377
            chosen := self askUserForCompletion:whatIsIt for:codeView at:node start from:suggestions.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2378
            chosen notNil ifTrue:[
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2379
                action value:(suggestions indexOf:chosen)
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2380
            ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2381
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2382
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2383
"/    |crsrPos
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2384
"/     selectorSoFar matchingSelectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2385
"/     selectors distances best rest 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2386
"/     allExistingMethods nameBag namesByCount selectors1 selectors2|  
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2387
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2388
"/    crsrPos := codeView characterPositionOfCursor - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2389
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2390
"/    selectorSoFar := ''.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2391
"/    node selectorParts doWithIndex:[:partToken :argNr|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2392
"/        |part|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2393
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2394
"/        part := partToken value.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2395
"/        selectorSoFar := selectorSoFar , part.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2396
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2397
"/        (crsrPos >= partToken start
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2398
"/        and:[crsrPos <= partToken stop]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2399
"/            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2400
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2401
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2402
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2403
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2404
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2405
"/                                        md := eachClass theMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2406
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2407
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2408
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2409
"/                "/ dont forget the stuff in the class-line
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2410
"/                Metaclass withAllSuperclassesDo:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2411
"/                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2412
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2413
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2414
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2415
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2416
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2417
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2418
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2419
"/                                        md := eachClass theNonMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2420
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2421
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2422
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2423
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2424
"/            selectors := matchingSelectors asOrderedCollection.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2425
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2426
"/            "/ if there is only one, and user has already entered it, he might want to complete the argument-name    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2427
"/            (selectors size == 1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2428
"/            and:[selectors first = selectorSoFar]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2429
"/                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2430
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2431
"/                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2432
"/                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2433
"/                nameBag := Bag new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2434
"/                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2435
"/                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2436
"/                "/ take the one which occurs most often     
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2437
"/                best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2438
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2439
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2440
"/                    undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2441
"/                        (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2442
"/                            codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2443
"/                        ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2444
"/                            codeView insertString:best atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2445
"/                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2446
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2447
"/                    info:'completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2448
"/                codeView cursorToCharacterPosition:(crsrPos + best size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2449
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2450
"/                "the ones implemented in superclasses are shown first"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2451
"/                classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2452
"/                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2453
"/                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2454
"/                ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2455
"/                    selectors1 := selectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2456
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2457
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2458
"/                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2459
"/                distances sortWith:selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2460
"/                selectors1 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2461
"/                selectors := selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2462
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2463
"/                selectors2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2464
"/                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2465
"/                    distances sortWith:selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2466
"/                    selectors2 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2467
"/                    selectors1 := selectors1 collect:[:sel | sel allBold].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2468
"/                    selectors := selectors1,selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2469
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2470
"/                
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2471
"/                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2472
"/                best isNil ifTrue:[^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2473
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2474
"/                rest := best copyFrom:selectorSoFar size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2475
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2476
"/                    undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2477
"/                        codeView 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2478
"/                            replaceFromCharacterPosition:crsrPos+1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2479
"/                            to:crsrPos+1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2480
"/                            with:rest 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2481
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2482
"/                    info:'Completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2483
"/                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2484
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2485
"/            codeView cursorRight. "/ kludge to make it visible   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2486
"/        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2487
"/    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2488
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2489
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2490
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2491
    "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2492
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2493
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2494
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2495
codeCompletionForMethodSpec:node into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2496
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2497
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2498
    |crsrPos crsrLine crsrCol
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2499
     selectorSoFar matchingSelectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2500
     selectors distances best rest 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2501
     allExistingMethods nameBag namesByCount selectors1 selectors2 
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2502
     editAction argNames selectorsForVars|  
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2503
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2504
    "/ Transcript showCR:'m'.   
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2505
    crsrLine := codeView cursorLine.
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2506
    crsrCol := codeView cursorCol.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2507
    crsrPos := codeView characterPositionOfCursor - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2508
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2509
    node selector isUnarySelector ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2510
        "/ user has just begun to edit a selector.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2511
        "/ often, a good completion are the names of instVars for which no corresponding getter/setter exists
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2512
        classOrNil notNil ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2513
            selectorsForVars := OrderedCollection new.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2514
            classOrNil instVarNames do:[:nm | 
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2515
                (nm startsWith:node selector) ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2516
                    (classOrNil implements:nm asSymbol) ifFalse:[ selectorsForVars add:nm].               
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2517
                    (classOrNil implements:(nm,':') asSymbol) ifFalse:[ selectorsForVars add:(nm,':')].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2518
                 ]
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2519
            ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2520
            classOrNil isMeta ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2521
                classOrNil theNonMetaclass classVarNames do:[:nm |
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2522
                    |nmSel|
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2523
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2524
                    nmSel := nm asLowercaseFirst.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2525
                    (nmSel startsWith:node selector) ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2526
                        (classOrNil implements:nmSel asSymbol) ifFalse:[ selectorsForVars add:nmSel].               
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2527
                        (classOrNil implements:(nmSel,':') asSymbol) ifFalse:[ selectorsForVars add:(nmSel,':')].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2528
                     ]
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2529
                ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2530
            ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2531
        ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2532
    ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2533
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2534
    selectorSoFar := ''.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2535
    node selectorParts doWithIndex:[:partToken :argNr|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2536
        |part|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2537
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2538
        part := partToken value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2539
        selectorSoFar := selectorSoFar , part.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2540
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2541
        (crsrPos >= partToken start
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2542
        and:[crsrPos <= partToken stop]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2543
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2544
                matchingSelectors := Smalltalk allClasses
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2545
                                    inject:(Set new)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2546
                                    into:[:theSet :eachClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2547
                                        |md|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2548
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2549
                                        md := eachClass theMetaclass methodDictionary.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2550
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2551
                                        theSet.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2552
                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2553
                "/ dont forget the stuff in the class-line
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2554
                Metaclass withAllSuperclassesDo:[:cls |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2555
                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2556
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2557
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2558
                matchingSelectors := Smalltalk allClasses
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2559
                                    inject:(Set new)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2560
                                    into:[:theSet :eachClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2561
                                        |md|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2562
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2563
                                        md := eachClass theNonMetaclass methodDictionary.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2564
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2565
                                        theSet.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2566
                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2567
            ].
4353
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2568
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2569
            selectors := matchingSelectors asOrderedCollection.
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2570
            selectorsForVars notNil ifTrue:[ selectors addAll:selectorsForVars ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2571
4353
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2572
            selectors := selectors sort:[:a :b | a size < b size].
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2573
            selectors size > 100 ifTrue:[
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2574
                selectors := selectors copyTo:100.
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2575
            ].
b04d3b1d44ac class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4352
diff changeset
  2576
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2577
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2578
            "/ if there is only one, and user has already entered it, he might want to complete the argument-name    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2579
            (selectors size == 1 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2580
            and:[selectors first = selectorSoFar]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2581
                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2582
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2583
                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2584
                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2585
                nameBag := Bag new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2586
                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2587
                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2588
                "/ take the one which occurs most often     
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2589
                "/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2590
                argNames := (namesByCount collect:[:a | a key]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2591
                editAction :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2592
                        [:chosenIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2593
                            |chosenName|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2594
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2595
                            chosenName := argNames at:chosenIndex.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2596
                            codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2597
                                undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2598
                                    (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2599
                                        codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2600
                                    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2601
                                        codeView insertString:chosenName atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2602
                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2603
                                    codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2604
                                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2605
                                info:'completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2606
                        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2607
                actionBlock 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2608
                    value:argNames 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2609
                    value:editAction
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2610
                    value:'argument'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2611
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2612
                ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2613
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2614
            ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2615
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2616
            "the ones implemented in superclasses are shown first"
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2617
            classOrNil notNil ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2618
                selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2619
                selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2620
            ] ifFalse:[
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2621
                selectors1 := selectors
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2622
            ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2623
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2624
            distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2625
            distances sortWith:selectors1.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2626
            selectors1 reverse.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2627
            selectors := selectors1.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2628
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2629
            selectors2 notEmptyOrNil ifTrue:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2630
                distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2631
                distances sortWith:selectors2.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2632
                selectors2 reverse.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2633
                selectors1 := selectors1 collect:[:sel | sel allBold].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2634
                selectors := selectors1,selectors2.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2635
            ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2636
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2637
            editAction := 
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2638
                [:selectedCompletionIndex |
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2639
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2640
                    best := selectors at:selectedCompletionIndex.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2641
                    rest := best copyFrom:selectorSoFar size + 1.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2642
                    codeView
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2643
                        undoableDo:[
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2644
                            codeView insertString:rest atLine:crsrLine col:crsrCol.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2645
                        ]
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2646
                        info:'Completion'.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2647
                    codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2648
                    codeView cursorRight. "/ kludge to make it visible   
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2649
                ].
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2650
            
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2651
            "/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2652
            actionBlock 
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2653
                value:selectors 
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2654
                value:editAction
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2655
                value:'selector'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2656
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2657
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2658
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2659
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2660
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2661
    "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2662
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2663
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2664
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2665
codeCompletionForVariable:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2666
    |nonMetaClass crsrPos nm parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2667
     allVariables allDistances variablesAlreadyAdded nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2668
     char oldLen newLen 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2669
     getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2670
     globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2671
     editAction suggestions nameIsOK longerNames setOfNames|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2672
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  2673
    "/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2674
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2675
        nonMetaClass := classOrNil theNonMetaclass.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2676
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2677
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2678
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2679
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2680
    "/ if we are behind the variable and a space has already been entered,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2681
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2682
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2683
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2684
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2685
    char isSeparator ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2686
        nm knownAsSymbol ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2687
            classOrNil isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2688
                nodeVal := Smalltalk at:nm asSymbol.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2689
            ] ifFalse:[ 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2690
                nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2691
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2692
            nodeVal isBehavior ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2693
                |methods menu exitKey idx|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2694
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2695
                methods := nodeVal class methodDictionary values
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2696
                                select:[:m | |cat|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2697
                                    cat := m category asLowercase.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2698
                                    cat = 'instance creation'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2699
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2700
                editAction :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2701
                    [:answer |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2702
                        codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2703
                            undoableDo:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2704
                                codeView insertString:answer atCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2705
                                codeView cursorToCharacterPosition:crsrPos+answer size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2706
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2707
                            info:'completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2708
                    ].
4387
306eac46bcb1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  2709
                actionBlock 
306eac46bcb1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  2710
                    value:(methods collect:[:each | each selector]) 
306eac46bcb1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  2711
                    value:editAction
306eac46bcb1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
  2712
                    value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2713
                ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2714
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2715
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2716
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2717
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2718
    parent := node parent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2719
    (parent notNil and:[parent isMessage]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2720
        node == parent receiver ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2721
            selectorOfMessageToNode := parent selector
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2722
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2723
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2724
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2725
    "/ this is pure voodoo magic (tries to make a good spelling weight,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2726
    "/ by weighting the number of startsWith characters into the spelling distance...)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2727
    getDistanceComputeBlockWithWeight :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2728
        [:weight |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2729
            [:each |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2730
                |dist factor|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2731
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2732
                dist := each spellAgainst:nm.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2733
                factor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2734
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2735
                (each startsWith:nm) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2736
                    factor := 6 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2737
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2738
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2739
                        factor := 4 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2740
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2741
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2742
                dist := dist + (weight*factor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2743
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2744
                each -> (dist * weight)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2745
             ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2746
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2747
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2748
    nameIsOK := false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2749
    addWithFactorBlock :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2750
        [:names :factor | |namesToAdd|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2751
            (names includes:nm) ifTrue:[nameIsOK := true].
4376
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2752
            names do:[:nameToAdd |
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2753
                (nameToAdd ~= nm) ifTrue:[  "/ not again
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2754
                    (variablesAlreadyAdded includes:nameToAdd) ifFalse:[  "/ not again 
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2755
                        variablesAlreadyAdded add:nameToAdd.
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2756
                        allVariables add:nameToAdd.
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2757
                        allDistances add:((getDistanceComputeBlockWithWeight value:factor) value:nameToAdd).
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2758
                    ]
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2759
                ]
5706e5655937 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4375
diff changeset
  2760
            ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2761
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2762
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2763
    nm isUppercaseFirst ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2764
        globalFactor := 2.    "/ favour globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2765
        localFactor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2766
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2767
        globalFactor := 1.    "/ favour locals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2768
        localFactor := 2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2769
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2770
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2771
    variablesAlreadyAdded := Set new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2772
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2773
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2774
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2775
    "/ are we in the method's selector spec ?
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2776
    (parent notNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2777
    and:[parent isMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2778
    and:[parent arguments includes:node]]) ifTrue:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2779
        "/ now thats cool: look how the name of this argument is in other implementations
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2780
        "/ of this method, and take that as a basis of the selection
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2781
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2782
        implementors := SystemBrowser 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2783
                            findImplementorsOf:(parent selector) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2784
                            in:(Smalltalk allClasses)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2785
                            ignoreCase:false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2786
        "/ which argument is it
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2787
        argIdx := parent arguments indexOf:node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2788
        implementors size > 50 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2789
            implementors := implementors asOrderedCollection copyTo:50.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2790
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2791
        namesUsed := implementors 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2792
                        collect:[:eachImplementor |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2793
                            |parseTree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2794
                            parseTree := eachImplementor parseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2795
                            (parseTree notNil and:[parseTree arguments size > 0]) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2796
                                ifFalse:nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2797
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2798
                        thenSelect:[:a | a notNil].  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2799
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2800
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2801
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2802
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2803
            "/ also, look for the keyword before the argument, 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2804
            "/ and see if there is such an instVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2805
            "/ if so, add it with -Arg
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2806
            parent selector isKeyword ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2807
                kwPart := parent selector keywords at:argIdx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2808
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2809
                    addWithFactorBlock 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2810
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2811
                        value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2812
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2813
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2814
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2815
    ] ifFalse:[
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2816
        "/ locals in the block/method
4365
fda4ed5a9772 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4364
diff changeset
  2817
        names := OrderedCollection withAll:node allVariablesOnScope.
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2818
        setOfNames := Set withAll:names.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2819
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2820
        rememberedScopeNodes notNil ifTrue:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2821
            "/ notNil when a parseError occurred.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2822
            rememberedScopeNodes do:[:eachScope |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2823
                (eachScope isMethod or:[eachScope isBlock]) ifTrue:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2824
                    eachScope argumentNames do:[:eachName |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2825
                        (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2826
                    ]
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2827
                ] ifFalse:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2828
                    eachScope isSequence ifTrue:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2829
                        eachScope temporaryNames do:[:eachName |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2830
                            (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2831
                        ]
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2832
                    ] ifFalse:[
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2833
                    ]
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2834
                ].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2835
                "/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2836
            ].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2837
            rememberedScopeNodes do:[:eachScope |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2838
                eachScope variableNodesDo:[:var |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2839
                    (setOfNames includes:var name) ifFalse:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2840
                        names add:var name. setOfNames add:var name
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  2841
                    ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2842
                ]
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2843
            ]
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2844
        ] ifFalse:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2845
            "/ tree must be there
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2846
            tree variableNodesDo:[:var |
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2847
                (setOfNames includes:var name) ifFalse:[
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2848
                    names add:var name. setOfNames add:var name
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2849
                ]
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2850
            ]
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2851
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2852
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2853
        addWithFactorBlock value:names value:(4 * localFactor).
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2854
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2855
        classOrNil notNil ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2856
            "/ instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2857
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2858
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2859
            "/ inherited instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2860
            classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2861
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2862
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2863
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2864
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2865
        "/ magic:
4364
c258f0fea7e0 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4363
diff changeset
  2866
        "/ if the node to be expanded is the receiver in a message, look for the selector sent to it
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2867
        "/ give names which respond to those messages a higher weight
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2868
        selectorOfMessageToNode notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2869
            |names responders nonResponders|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2870
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2871
            "/ responding to that messsage
4365
fda4ed5a9772 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4364
diff changeset
  2872
"/ self halt.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2873
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2874
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2875
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2876
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2877
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2878
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2879
                names := nonMetaClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2880
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2881
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2882
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2883
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2884
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2885
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2886
                "/ superclass var names
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2887
                nonMetaClass allSuperclassesDo:[:superClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2888
                    names := superClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2889
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2890
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2891
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2892
                    addWithFactorBlock value:responders value:(1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2893
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2894
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2895
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2896
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2897
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2898
                    names := classOrNil topNameSpace keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2899
                    names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2900
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2901
                    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2902
                    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2903
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2904
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2905
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2906
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2907
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2908
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2909
            names := Smalltalk keys.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2910
            names := names reject:
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2911
                            [:nm | 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2912
                                (nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2913
                            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2914
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2915
            names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2916
            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2917
            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2918
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2919
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2920
4314
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2921
            classOrNil notNil ifTrue:[
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2922
                "/ pool variables
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2923
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2924
                    |pool names|
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2925
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2926
                    pool := Smalltalk at:poolName.
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2927
                    names := pool classVarNames.
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2928
                    names := names select:[:nm | nm isUppercaseFirst ].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2929
                    responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2930
                    nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2931
                    addWithFactorBlock value:responders value:(2.5 * globalFactor).
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2932
                    addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2933
                ].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2934
            ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2935
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2936
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2937
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2938
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2939
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2940
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2941
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2942
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2943
                classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2944
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2945
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2946
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2947
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2948
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2949
                    names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2950
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2951
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2952
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2953
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2954
                "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2955
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2956
                    |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2957
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2958
                    pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2959
                    names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2960
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2961
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2962
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2963
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2964
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2965
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2966
            names := names select:[:nm | nm isUppercaseFirst ].
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2967
            "/ only consider all globals, if the first char of the completed name is uppercase;
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2968
            "/ otherwise, only consider names with a caseInsensitve prefix match
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2969
            nm first isUppercase ifTrue:[
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2970
                
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2971
            ] ifFalse:[
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2972
                names := names select:[:globalName | globalName asLowercase startsWith: nm].
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2973
            ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2974
            addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2975
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2976
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2977
        "/ pseudos - assuming that thisContext is seldom used.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2978
        "/ also assuming, that nil is short so its usually typed in.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2979
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2980
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2981
        addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2982
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2983
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2984
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2985
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2986
4410
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2987
"/ nope (foo := foo + 1) should be possible!!
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2988
"/    (parent notNil and:[parent isAssignment]) ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2989
"/        "/ remove the left side of the assignment (to avoid foo := foo suggestions)
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2990
"/        |i|
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2991
"/
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2992
"/        i := allDistances findFirst:[:entry | entry key = parent variable name].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2993
"/        i ~~ 0 ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2994
"/            allDistances removeAtIndex:i
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2995
"/        ].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  2996
"/    ].
4385
d3381caeb327 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
  2997
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2998
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2999
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3000
                                                           ifTrue:[el]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3001
                                                           ifFalse:[best]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3002
                                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3003
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3004
    allDistances sort:[:a :b | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3005
                                a value > b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3006
                                    true
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3007
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3008
                                    a value = b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3009
                                        a key < b key
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3010
                                    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3011
                                        false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3012
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3013
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3014
                      ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3015
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3016
    allTheBest := allDistances.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3017
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3018
    nameIsOK ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3019
        "/ if the name already exists, only allow longer names, if there are
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3020
        longerNames := allTheBest select:[:assoc | assoc key startsWith:nm].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3021
        longerNames notEmpty ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3022
            allTheBest := longerNames.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3023
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3024
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3025
    allTheBest size > 15 ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3026
        "/ remove all those which are below some threshold
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3027
        0.4 to:0.8 by:0.1 do:[:delta |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3028
            "/ if still too many, remove more and more
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3029
            allTheBest size > 15 ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3030
                allTheBest := allDistances select:[:entry | (entry key startsWith:nm) or:[ entry value >= (bestAssoc value * delta) ]].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3031
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3032
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3033
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3034
    suggestions := allTheBest collect:[:assoc | assoc key].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3035
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3036
    "/ finally, the trick is to bring them into a reasonable order...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3037
    "/ sort the prefix matchers by length, the others by spelling distance
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3038
    "/ and bring the prefix-matchers towards the beginning
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3039
    suggestions := ((suggestions select:[:s | s startsWith:nm]) sort:[:a :b | a size < b size ])
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3040
                   ,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3041
                   (suggestions reject:[:s | s startsWith:nm]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3042
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3043
    "/ if super is among them, add a full call to the completions
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3044
    (suggestions includes:'super') ifTrue:[
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3045
        (tree notNil
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3046
        and:[ tree isMethod ]) ifTrue:[
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3047
            suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.').
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3048
        ].
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3049
    ].
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3050
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3051
    editAction :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3052
        [:index |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3053
            |answer start stop oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3054
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3055
            answer := suggestions at:index.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3056
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3057
            start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3058
            stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3059
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3060
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3061
            oldLen := stop - start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3062
            newLen := answer size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3063
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3064
            codeView
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3065
                undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3066
                    codeView replaceFromCharacterPosition:start to:stop with:(answer).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3067
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3068
                    (answer startsWith:oldVar) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3069
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3070
                    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3071
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3072
                    ].
4378
02f4888b809a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4377
diff changeset
  3073
                    codeView dontReplaceSelectionOnInput
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3074
                ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3075
                info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3076
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3077
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3078
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3079
    actionBlock value:suggestions value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3080
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3081
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3082
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4314
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  3083
    "Modified: / 30-07-2013 / 08:36:11 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3084
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3085
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3086
findNodeForInterval:interval in:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3087
    |tree node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3088
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3089
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3090
    RBParser isNil ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3091
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3092
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3093
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3094
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3095
        tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3096
                parseMethod:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3097
                onError: 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3098
                    [:str :err ":nodesSoFar" | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3099
                        "Transcript showCR:'Parse-Error: ',str." 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3100
                        nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3101
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3102
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3103
        tree isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3104
            "/ try to parse as an expression
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3105
            tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3106
                    parseExpression:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3107
                    onError: 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3108
                        [:str :err ":nodesSoFar" | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3109
                            "Transcript showCR:'Parse-Error: ',str." 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3110
                            nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3111
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3112
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3113
            tree isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3114
                ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3115
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3116
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3117
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3118
        LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3119
        LastParseTree := tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3120
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3121
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3122
    node := tree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3123
    node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3124
        node := tree bestNodeFor: interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3125
        node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3126
            node := self findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3127
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3128
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3129
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3130
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3131
    "Modified: / 06-07-2011 / 12:42:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3132
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3133
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3134
findNodeForInterval:interval in:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3135
    ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3136
        findNodeForInterval:interval in:source allowErrors:allowErrors  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3137
        mustBeMethod:false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3138
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3139
    "Modified: / 16-09-2011 / 14:52:28 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3140
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3141
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3142
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3143
    "if mustBeMethod is true, do not try a regular expression (as in a workspace)."
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3144
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3145
    ^ self
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3146
        findNodeForInterval:interval in:source allowErrors:allowErrors 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3147
        mustBeMethod:mustBeMethod mustBeExpression:false
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3148
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3149
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3150
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3151
    "parse it as expression or method;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3152
     if mustBeMethod is true, do not try a regular expressions (as in a workspace);
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3153
     if mustBeExpression is true, do not try method"
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3154
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3155
    |intersectingNodes smallestIntersectingNode firstIntersectingNode 
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3156
     lastIntersectingNode onErrorBlock 
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3157
     nodeGenerationHook parserClass parser currentScopeNodes bestNode|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3158
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3159
    interval isEmpty ifTrue: [^ nil].
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3160
    languageOrNil notNil ifTrue:[
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3161
        parserClass := languageOrNil parserClass.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3162
    ] ifFalse:[
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3163
        classOrNil notNil ifTrue:[
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3164
            parserClass := classOrNil programmingLanguage parserClass.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3165
        ]
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3166
    ].
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3167
    parserClass notNil ifTrue:[    
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3168
        "/ hack
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3169
        parserClass == Parser ifTrue: [
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3170
            parserClass := RBParser.
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3171
        ].
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3172
    ] ifFalse:[
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3173
        parserClass := RBParser.
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3174
    ].
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3175
    parserClass isNil ifTrue: [^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3176
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3177
    rememberedScopeNodes := nil.
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3178
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3179
    "/ LastSource := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3180
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3181
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3182
        tokens := LastScanTokens.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3183
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3184
        intersectingNodes := OrderedCollection new.
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3185
        currentScopeNodes := IdentitySet new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3186
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3187
        onErrorBlock := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3188
            [:str :err :nodesSoFar |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3189
                |nodes|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3190
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3191
                allowErrors ifTrue:[
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3192
                    rememberedScopeNodes := currentScopeNodes.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  3193
                    firstIntersectingNode notNil ifTrue:[
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  3194
                        ^ firstIntersectingNode
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  3195
                    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3196
                    nodesSoFar notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3197
                        nodes := nodesSoFar asOrderedCollection
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3198
                                    collect:[:nd | nd whichNodeIntersects:interval]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3199
                                    thenSelect:[:nd | nd notNil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3200
                        nodes size == 1 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3201
                            ^ nodes first
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3202
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3203
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3204
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3205
                nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3206
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3207
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3208
        self debuggingCodeFor:#cg is:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3209
            Transcript show:'looking for: '; showCR:interval.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3210
        ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3211
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3212
        nodeGenerationHook := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3213
            [:node |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3214
                "/ we would like to return here as soon as the node has been created by the parser;
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3215
                "/ however, at that time, its parent(chain) is not yet created and so we might not know
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3216
                "/ what the semantic interpretation (especially: scope of variable) will be.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3217
                "/ therefore, we parse all, and return the found node at the end.
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3218
                (node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3219
                    currentScopeNodes add:node.
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3220
                ] ifFalse:[
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3221
                    self debuggingCodeFor:#cg is:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3222
                        Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3223
                    ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3224
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3225
                    (node intersectsInterval:interval) ifTrue:[
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3226
                        self debuggingCodeFor:#cg is:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3227
                            Transcript showCR:'yes'.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3228
                        ].
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3229
                        intersectingNodes add:node.
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3230
                        firstIntersectingNode isNil ifTrue:[
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3231
                            firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3232
                        ] ifFalse:[
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3233
                            |lenNode lenSmallest|
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3234
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3235
                            lenNode := (node stop - node start).
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3236
                            lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start).
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3237
                            lenNode < lenSmallest ifTrue:[
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3238
                                smallestIntersectingNode := node.
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3239
                            ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3240
                            node start > lastIntersectingNode start ifTrue:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3241
                                lastIntersectingNode := node.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3242
                            ].
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3243
                        ].
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3244
                    ].   
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3245
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3246
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3247
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3248
        "/ one of the big problems when using the RBParser here is
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3249
        "/ that it behaves badly when a syntax error is encountered;
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3250
        "/ for example, a node's parent is usually set AFTER the children are
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3251
        "/ completely parsed (for example, a blockNode gets the parent-method only
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3252
        "/ after parsing). Thus, when an error is encountered, we cannot walk
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3253
        "/ the parent chain, and therefore will not see the outer locals/args of
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3254
        "/ an inner scope (allVariablesOnScope returns only a partial set).
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3255
        "/ A walkaround is to remember Method/Block nodes as created in the above node generation.
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3256
        "/ The disadvantage of it is that we do not have correct scope information, until the nodes
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3257
        "/ parent gets set eventually, this we might consider locals from sibling blocks. 
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3258
        "/ See rememberedScopeNodes handling above.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3259
        "/ Those other nodes are only remembered for failed parses;
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3260
        "/ if the parse is ok, rememberedScopeNodes will be nil.
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3261
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3262
        mustBeExpression ifFalse:[
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3263
            tree := parserClass
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3264
                        parseMethod: source 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3265
                        setup:[:p | 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3266
                            parser := p.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3267
                            p rememberNodes:true.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3268
                            p rememberTokens:true.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3269
                            p nodeGenerationCallback:nodeGenerationHook
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3270
                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3271
                        onError: onErrorBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3272
            parser notNil ifTrue:[ tokens := parser rememberedTokens ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3273
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3274
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3275
        mustBeMethod ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3276
            "/ only cache parsed methods
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3277
            tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3278
                LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3279
                LastParseTree := tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3280
                LastScanTokens := tokens.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3281
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3282
        ] ifFalse:[    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3283
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3284
                "/ try as an expression
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3285
                tree := parserClass
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3286
                            parseExpression: source 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3287
                            setup:[:p |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3288
                                parser := p.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3289
                                p rememberNodes:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3290
                                p rememberTokens:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3291
                                p nodeGenerationCallback:nodeGenerationHook
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3292
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3293
                            onError: onErrorBlock.
4276
5f4dca44baed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
  3294
                parser notNil ifTrue:[ tokens := parser rememberedTokens ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3295
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3296
        ].
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3297
        lastIntersectingNode notNil ifTrue:[ 
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3298
            self debuggingCodeFor:#cg is:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3299
                Transcript show:'last: '; showCR:lastIntersectingNode.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3300
            ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3301
            ^ lastIntersectingNode 
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3302
        ].   
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3303
        "/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3304
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3305
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3306
    bestNode := self findNodeForInterval:interval inParseTree:tree.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3307
    self debuggingCodeFor:#cg is:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3308
        Transcript show:'best: '; showCR:bestNode.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3309
    ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3310
    ^ bestNode
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3311
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3312
    "Created: / 16-09-2011 / 14:52:08 / cg"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3313
    "Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3314
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3315
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3316
findNodeForInterval:interval inParseTree:parseTree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3317
    |node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3318
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3319
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3320
    parseTree isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3321
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3322
    node := parseTree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3323
    node isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3324
        node := parseTree whichNodeIntersects:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3325
        node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3326
            node := self findNodeIn:parseTree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3327
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3328
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3329
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3330
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3331
    "Modified: / 10-11-2006 / 13:13:58 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3332
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3333
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3334
findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3335
    |nodeFound wouldReturn|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3336
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3337
    nodeFound := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3338
    tree nodesDo:[:eachNode |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3339
        (eachNode intersectsInterval:interval) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3340
            (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3341
                nodeFound := eachNode
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3342
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3343
                (nodeFound parent == eachNode parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3344
                and:[ eachNode start >= nodeFound start
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3345
                      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3346
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3347
                    (nodeFound parent notNil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3348
                    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3349
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3350
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3351
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3352
            nodeFound notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3353
                "/ already found one - beyond that one; leave
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3354
                wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3355
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3356
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3357
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3358
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3359
    ^ nodeFound
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3360
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3361
    "Modified: / 20-11-2006 / 12:31:12 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3362
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3363
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3364
insertAdditonalStuffAfterSelector:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3365
    |optionalExtraSpace|
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3366
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3367
    optionalExtraSpace := (codeView characterAfterCursor isSeparator) 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3368
                            ifTrue:[''] 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3369
                            ifFalse:[' '].  
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3370
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3371
    (
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3372
        #(
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3373
            'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:' 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3374
            'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:'
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3375
        ) includes:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3376
    ) ifTrue:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3377
        codeView insertStringAtCursor:('[',optionalExtraSpace).
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3378
        "/ codeView cursorLeft:1+extra size. 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3379
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3380
    (
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3381
        #(
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3382
            'collect:' 'select:' 'reject:' 'do:'
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3383
        ) includes:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3384
    ) ifTrue:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3385
        codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace).
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3386
        codeView cursorLeft:1+optionalExtraSpace size. 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3387
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3388
    (
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3389
        #(
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3390
            'contains:' 'findFirst:' 'detect:'
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3391
        ) includes:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3392
    ) ifTrue:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3393
        codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace).
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3394
        codeView cursorLeft:1+optionalExtraSpace size. 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3395
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3396
    (
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3397
        #(
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3398
            'remove:ifAbsent:' 'detect:ifNone:' 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3399
        ) includes:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3400
    ) ifTrue:[
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3401
        codeView insertStringAtCursor:('[]',optionalExtraSpace).
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3402
        codeView cursorLeft:1+optionalExtraSpace size. 
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3403
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3404
!
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3405
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3406
old_askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3407
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3408
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3409
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3410
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3411
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3412
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3413
    LastChoices notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3414
        lastChoice := LastChoices at:what ifAbsent:nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3415
        lastChoice notNil ifTrue:[
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3416
            "/ move tha last choice to the top of the list, if it is in.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3417
            (list includes: lastChoice) ifTrue:[
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3418
                (list indexOf: lastChoice) < 10 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3419
                    list := {lastChoice allBold } , (list copyWithout:lastChoice).
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3420
                ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3421
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3422
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3423
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3424
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3425
    list size < 30 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3426
        |menu idx exitKey|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3427
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3428
        menu := PopUpMenu labels:list.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3429
        menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3430
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3431
                hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3432
                    exitKey := key.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3433
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3434
                hide].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3435
        menu memorizeLastSelection:3 "sigh, not 1 because of heading!!".
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3436
        idx := menu startUpWithHeading:'Choose ',what.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3437
        idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3438
            exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3439
                codeView keyPress:exitKey x:0 y:0.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3440
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3441
            ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3442
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3443
        choice := list at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3444
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3445
        resources := codeView application isNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3446
                        ifTrue:[ codeView resources]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3447
                        ifFalse:[ codeView application resources ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3448
                    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3449
        choice := Dialog
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3450
           choose:(resources string:'Choose ',what)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3451
           fromList:list
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3452
           lines:20
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3453
           initialSelection:(list firstIfEmpty:nil)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3454
           title:(resources string:'Code completion').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3455
        choice isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3456
    ].
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  3457
    choice := choice string.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3458
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3459
    LastChoices isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3460
        LastChoices := Dictionary new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3461
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3462
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3463
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3464
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3465
    "Created: / 16-02-2010 / 09:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3466
    "Modified: / 28-08-2013 / 15:28:01 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3467
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3468
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3469
treeForCode:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3470
    |tree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3471
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3472
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3473
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3474
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3475
        tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3476
                parseMethod:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3477
                onError: [:str :err :nodesSoFar :parserOrNil|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3478
                        allowErrors ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3479
                            "/ parserOrNil isNil if raised by the scanner
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3480
                            parserOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3481
                                ^ parserOrNil currentMethodNode
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3482
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3483
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3484
                        ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3485
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3486
                proceedAfterError:false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3487
                rememberNodes:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3488
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3489
        tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3490
            LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3491
            LastParseTree := tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3492
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3493
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3494
    ^ tree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3495
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3496
    "Modified: / 13-01-2012 / 11:54:30 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3497
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3498
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3499
tryCodeCompletionWithSource:source nodeInterval:interval into:actionBlock
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3500
    "this is tried twice; first with the source copied up to the cursor position,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3501
     then with the full source.
4381
43de05e6af6c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  3502
     Either one may give better results (for example, when completing
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3503
     after a keyword selector, and the remaining code would lead to a syntactically
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3504
     legal, but stupid message send to be parsed...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3505
     (which happens often after inserting)"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3506
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3507
    |node checkedNode characterPositionOfCursor characterBeforeCursor nodeIsInTemporaries|
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3508
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3509
    characterPositionOfCursor := codeView characterPositionOfCursor.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3510
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3511
    "/ this is too naive and stupid; if there is a syntactic error,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3512
    "/ we will not find a node for a long time (stepping back more and more,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3513
    "/ until reaching the beginning). This leads to a thousand and more times reparsing
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3514
    "/ without any progress.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3515
    "/ TODO: do it vice-versa, in that the parser does a callOut for every node generated
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3516
    "/ as it parses the code. Stop, when the interval is hit.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3517
    "/ that will also work for syntactic incorrect source code.
4356
e0baa28be88f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4353
diff changeset
  3518
    (methodOrNil notNil or:[classOrNil notNil]) ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3519
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3520
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3521
    node isNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3522
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true.   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3523
        node isNil ifTrue:[
4374
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3524
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
c2c87c8465cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3525
            self information:'No parseNode found (syntax error before or in comment?)'.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3526
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3527
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3528
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3529
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3530
    (node isVariable
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3531
    and:[ node parent notNil
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3532
    and:[ node parent isMessage
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3533
    and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3534
        node := node parent.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3535
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3536
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3537
    characterBeforeCursor := codeView characterBeforeCursor.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3538
    characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  3539
    characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3540
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3541
    node isVariable ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3542
        nodeIsInTemporaries :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3543
            node parent notNil 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3544
            and:[ node parent isSequence 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3545
            and:[ node parent temporaries notEmptyOrNil
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3546
            and:[ node stop <= node parent temporaries last stop ]]].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3547
        nodeIsInTemporaries ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3548
            "/ cursor must be right after the variable
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3549
            characterPositionOfCursor == (node stop + 1) ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3550
                self codeCompletionForVariable:node into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3551
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3552
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3553
        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3554
    ].
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3555
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3556
    node isLiteral ifTrue:[
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3557
        "/ however, user may want to complete a symbol inside a literal array!!
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3558
        node value isArray ifTrue:[
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3559
            node token isLiteralArray ifTrue:[
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3560
                |elementBeforeCursor|
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3561
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3562
                elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil.
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3563
                (elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  3564
                    self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock.
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3565
                    ^ self.
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3566
                ].
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3567
            ].
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3568
        ].
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3569
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3570
        "/ cursor must be right after the literal
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3571
        characterPositionOfCursor == (node stop + 1) ifFalse:[
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3572
            ^ self
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3573
        ].
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3574
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3575
        node value isSymbol ifTrue:[
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  3576
            self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock.
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3577
            ^ self.
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3578
        ].
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3579
        
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3580
        "/ huh - completing strings, numbers or what?
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3581
        (node parent notNil
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3582
            and:[ node parent isMessage
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3583
            and:[ node parent isKeyword ]]) 
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3584
        ifFalse:[
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3585
            ^ self
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3586
        ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3587
        "/ no, move up and try completing the outer keyword message (next arg)
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3588
        node := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3589
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3590
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3591
    checkedNode := node.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3592
    [checkedNode notNil] whileTrue:[
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3593
        (characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3594
            self information:'Inside a message node'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3595
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3596
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3597
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3598
        checkedNode isMessage ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3599
            "/ completion in a message-send
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3600
            self codeCompletionForMessage:checkedNode into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3601
            ^ self
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3602
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3603
        checkedNode isMethod ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3604
            "/ completion in a method's selector pattern
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3605
            self codeCompletionForMethodSpec:checkedNode into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3606
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3607
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3608
        checkedNode := checkedNode parent.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3609
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3610
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3611
    self information:'Node is neither variable nor message.'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3612
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3613
    "Modified: / 04-07-2006 / 18:48:26 / fm"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3614
    "Modified: / 16-09-2011 / 14:54:47 / cg"
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3615
!
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3616
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3617
valueOfNode:aNode
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3618
    "when showing possible completions for a message, 
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3619
     it is a good idea to know what the reveiver's value is.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3620
     Sigh - returns nil both if unknown AND if a real nil is there."
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3621
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3622
    |nm nodeVal nodeSelector nodeReceiver isNonDestructive receiverValue method|
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3623
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3624
    aNode isLiteral ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3625
        ^ aNode value
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3626
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3627
    aNode isVariable ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3628
        nm := aNode name.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3629
        nm isUppercaseFirst ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3630
            "/ simply 'evaluate' the variable (like in a browser's codeView)
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3631
            "/ mhmh - will we catch workspace vars then?
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3632
            Error handle:[:ex |
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3633
            ] do:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3634
                nodeVal := Parser new evaluate:nm in:nil receiver:classOrNil.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3635
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3636
            nodeVal notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3637
                ^ nodeVal
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3638
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3639
            (classOrNil notNil and:[classOrNil theNonMetaclass classVarNames includes:aNode name]) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3640
                nodeVal := classOrNil theNonMetaclass classVarAt:aNode name.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3641
                ^ nodeVal.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3642
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3643
            ^ nil
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3644
        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3645
        nm = 'self' ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3646
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[^ classOrNil theNonMetaclass].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3647
            contextOrNil notNil ifTrue:[^ contextOrNil receiver].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3648
            ^ nil
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3649
        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3650
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3651
        contextOrNil notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3652
            "/ a local in the context?
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3653
            (contextOrNil argAndVarNames includes:nm) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3654
                nodeVal := contextOrNil argsAndVars at:(contextOrNil argAndVarNames indexOf:nm).
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3655
                nodeVal notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3656
                    ^ nodeVal
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3657
                ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3658
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3659
            "/ an instvar
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3660
            (contextOrNil receiver class allInstVarNames includes:nm) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3661
                nodeVal := contextOrNil receiver instVarNamed:nm.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3662
                nodeVal notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3663
                    ^ nodeVal
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3664
                ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3665
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3666
        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3667
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3668
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3669
    aNode isMessage ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3670
        nodeSelector := aNode selector.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3671
        nodeReceiver := aNode receiver.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3672
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3673
        "/ some hardwired knowlegde here
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3674
        classOrNil notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3675
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3676
                ^ classOrNil
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3677
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3678
        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3679
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3680
        isNonDestructive := false.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3681
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3682
        ( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3683
            isNonDestructive := true.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3684
        ] ifFalse:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3685
            "/ follow non-destructive accessors
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3686
            receiverValue := self valueOfNode:nodeReceiver.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3687
            receiverValue notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3688
                method := receiverValue class lookupMethodFor:nodeSelector.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3689
                method notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3690
                    (ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3691
                        "/ we can savely call that method to get the current value
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3692
                        ^ receiverValue perform: nodeSelector.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3693
                    ]
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3694
                ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3695
            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3696
        ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3697
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3698
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3699
    ^ nil
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3700
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3701
    "Created: / 28-08-2013 / 16:34:53 / cg"
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3702
!
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3703
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3704
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3705
    |selectors noNilChecks noIsXXXChecks noNoXXXChecks|
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3706
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3707
    aClass isNil ifTrue:[ ^ selectorsArg ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3708
4419
633a3beef0b3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  3709
    noNilChecks := noIsXXXChecks := noNoXXXChecks := false.
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3710
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3711
    selectors := (selectorsArg ? #()) asOrderedCollection. 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3712
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3713
    self tracePoint:#cg message:aClass.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3714
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3715
    "/ using True, but actually meaning Boolean here
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3716
    aClass == True ifTrue:[
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3717
        noNilChecks := true.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3718
        (partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ].
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3719
        (partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3720
    ].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3721
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3722
    (aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ].
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3723
    (aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := true ].
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3724
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3725
    (aClass isMeta) ifTrue:[ 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3726
        noNilChecks := true.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3727
        "/ remove messages which are only defined in Object and non-meta classes.
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3728
        selectors := selectors reject:
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3729
            [:sel |
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3730
                (Object implements:sel) 
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3731
                and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]]
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3732
            ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3733
    ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3734
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3735
    noNilChecks ifTrue:[
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3736
        selectors removeAllFoundIn:#( 
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3737
                    'isNil' 'notNil'
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3738
                    'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:' 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3739
                    'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:' 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3740
                    'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:' 
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3741
                  ).
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3742
    ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3743
    noIsXXXChecks ifTrue:[
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3744
        "/ get rid of all isXXX selectors
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3745
        selectors := selectors reject:[:sel | sel startsWith:'is'].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3746
    ].
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3747
    noNoXXXChecks ifTrue:[
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3748
        "/ get rid of all notXXX selectors
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3749
        selectors := selectors reject:[:sel | sel startsWith:'no'].
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3750
    ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3751
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3752
    "/ actually: directly implemented selectors are more likely, so move them to top
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3753
    selectors := (selectors select:[:sel | aClass implements:sel])
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3754
                 ,
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3755
                 (selectors reject:[:sel | aClass implements:sel]).
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  3756
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3757
    ^ selectors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3758
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3759
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3760
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3761
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3762
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3763
    |sym possibleCompletions best start stop oldLen newLen oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3764
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3765
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3766
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3767
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3768
    Symbol allInstancesDo:[:existingSym |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3769
        (existingSym startsWith:sym) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3770
            (existingSym = sym) ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3771
                possibleCompletions add:existingSym
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3772
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3773
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3774
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3775
    possibleCompletions sort.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3776
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3777
    best := possibleCompletions longestCommonPrefix.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3778
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3779
        best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3780
        best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3781
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3782
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3783
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3784
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3785
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3786
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3787
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3788
        start := start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3789
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3790
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3791
        start := start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3792
        stop := stop - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3793
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3794
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3795
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3796
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3797
    codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3798
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3799
        info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3800
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3801
    (best startsWith:oldVar) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3802
        oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3803
        newLen := best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3804
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3805
        codeView dontReplaceSelectionOnInput
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3806
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3807
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3808
    "Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3809
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3810
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3811
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3812
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3813
    |selector srchClass implClass 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3814
     bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best info numArgs
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3815
     newParts nSelParts oldLen newLen selectorParts 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3816
     findBest parentNode selectorInBest selector2InBest2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3817
     parser selectorsSentInCode selectorsImplementedInClass split 
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3818
     varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3819
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3820
    RefactoryTyper notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3821
        "/ refactory package also provides a (very limited) typer;
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3822
        "/ ask it for its oppinion as well (temporary - will vanish, once we have a better typer)
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3823
        (node receiver isVariable) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3824
            varName := node receiver name.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3825
            varName isUppercaseFirst ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3826
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3827
                tree := RBParser 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3828
                            parseMethod:codeView contents string
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3829
                            onError:[:aString :pos | nil].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3830
                tree notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3831
                    rbTypes := RefactoryTyper 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3832
                                classesFor: varName
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3833
                                in: tree
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3834
                                model: nil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3835
                                ignoredSelectors:(Array with:node selector).     
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3836
                    rbTypes size > 0 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3837
                        rbTypes size > 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3838
                            rbTypes remove:ProtoObject ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3839
                            rbTypes remove:Autoload ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3840
                            rbTypes remove:ObsoleteObject ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3841
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3842
                        rbTypes size == 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3843
                            rbType := rbTypes first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3844
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3845
                            rbType := Class commonSuperclassOf:rbTypes
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3846
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3847
                        (rbType notNil "and:[rbType ~= Object]") ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3848
                            bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3849
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3850
                    ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3851
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3852
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3853
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3854
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3855
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3856
    classOrNil notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3857
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3858
        selectorsSentInCode := parser messagesSent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3859
    ].                                  
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3860
    classOrNil notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3861
        selectorsImplementedInClass := classOrNil selectors.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3862
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3863
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3864
    findBest := [:node :selector |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3865
        |srchClass bestSelectors bestPrefixes|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3866
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3867
        codeView topView withCursor:(Cursor questionMark) do:[
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  3868
            srchClass := self classOfNode:node receiver.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3869
            srchClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3870
                bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3871
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3872
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3873
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3874
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3875
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3876
        (bestSelectors includes:selector) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3877
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3878
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3879
        bestSelectors
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3880
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3881
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3882
    selector := node selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3883
    bestSelectors := findBest value:node value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3884
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3885
    parentNode := node parent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3886
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3887
    parentIsKeywordMessage :=
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3888
        (parentNode notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3889
            and:[ parentNode isMessage 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3890
            and:[ parentNode selector isKeywordSelector]]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3891
    parentIsBinaryMessage :=
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3892
        (parentNode notNil 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3893
            and:[ parentNode isMessage 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3894
            and:[ parentNode selector isBinarySelector]]).
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3895
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3896
    tryParent := false.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3897
    "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3898
    (node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[ 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3899
        tryParent := true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3900
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3901
        "/ if the parent is an instance creation message, take that as lookup class.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3902
        (node isMessage
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3903
        and:[ node receiver isMessage 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3904
        and:[ node receiver receiver isVariable 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3905
        and:[ node receiver receiver name isUppercaseFirst 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3906
        and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3907
            rcvrClass := Smalltalk classNamed:(node receiver receiver name).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3908
            "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3909
            bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3910
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3911
            "/ also, if nothing was found
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3912
            (bestSelectors isEmpty 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3913
            and:[ parentNode notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3914
            and:[ parentNode isMessage ]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3915
                "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3916
                "/ selector2 := parentNode selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3917
                "/ selector2 := selector2,selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3918
                bestSelectors := findBest value:parentNode value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3919
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3920
        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3921
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3922
    tryParent ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3923
        selector2 := parentNode selector,selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3924
        bestSelectors2 := findBest value:parentNode value:selector2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3925
    ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3926
    bestSelectorsFromRB notEmptyOrNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3927
        bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3928
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3929
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3930
    "/ if the parent is a keyword selector, the child cannot
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3931
    (parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3932
        bestSelectors := bestSelectors reject:[:sel | sel isKeywordSelector]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3933
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3934
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3935
    bestSelectors2 isEmptyOrNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3936
        allBest := bestSelectors.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3937
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3938
        bestSelectors isEmptyOrNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3939
            allBest := bestSelectors2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3940
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3941
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3942
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3943
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3944
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3945
                "/ selector2 is more likely
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3946
                allBest := bestSelectors2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3947
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3948
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3949
                    "/ selector more likely
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3950
                    allBest := bestSelectors
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3951
                ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3952
                    "/ assume same likelyness
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3953
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3954
                    allBest := bestSelectors isEmpty 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3955
                                ifTrue:[ bestSelectors2 ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3956
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3957
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3958
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3959
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3960
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3961
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3962
    allBest isEmptyOrNil ifTrue:[ ^ self ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3963
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3964
    split := 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3965
        [:list :splitHow |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3966
            |part1 part2 all|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3967
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3968
            part1 := list select:splitHow.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3969
            part2 := list reject:splitHow.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3970
            part1 isEmpty ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3971
                all := part2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3972
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3973
                part2 isEmpty ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3974
                    all := part1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3975
                ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3976
                    all := part1 , part2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3977
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3978
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3979
            all
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3980
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3981
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3982
    selectorsImplementedInClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3983
        "/ the ones implemented in the receiver class are moved to the top of the list.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3984
        allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3985
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3986
    selectorsSentInCode notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3987
        "/ the ones already sent in the code are moved to the top of the list.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3988
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3989
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3990
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3991
    "/ the ones which are a prefix are moved towards the top of the list
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3992
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3993
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3994
    best := allBest first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3995
    allBest size > 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3996
        "allBest size < 20 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3997
            |idx|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3998
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3999
            idx := (PopUpMenu labels:allBest) startUp.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4000
            idx == 0 ifTrue:[ ^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4001
            best := allBest at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4002
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4003
            allBest remove:nil ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4004
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4005
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4006
        ]."
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4007
        allBest remove:nil ifAbsent:[].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4008
        best := self askUserForCompletion:('Selector for "%1"' bindWith:selector) for:codeView at: node selectorParts first start from:allBest.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4009
        best isEmptyOrNil ifTrue:[^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4010
        best = '-' ifTrue:[^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4011
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4012
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4013
false ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4014
    srchClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4015
        implClass := srchClass whichClassIncludesSelector:best.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4016
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4017
        implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4018
        implClass size == 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4019
            implClass := implClass first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4020
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4021
            implClass := nil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4022
        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4023
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4024
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4025
    info := best storeString.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4026
    implClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4027
        info := implClass name , ' >> ' , info.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4028
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4029
    self information:info.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4030
].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4031
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4032
    best ~= selector ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4033
        numArgs := best numArgs.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4034
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4035
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4036
            selectorParts := parentNode selectorParts , node selectorParts.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4037
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4038
            selectorParts := node selectorParts.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4039
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4040
        nSelParts := selectorParts size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4041
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4042
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4043
        newParts := newParts select:[:part | part size > 0].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4044
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4045
        codeView
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4046
            undoableDo:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4047
                |newCursorPosition stop|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4048
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4049
                numArgs > nSelParts ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4050
                    stop := selectorParts last stop.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4051
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4052
                    "/ append the rest ...
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4053
                    numArgs downTo:nSelParts+1 do:[:idx |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4054
                        |newPart|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4055
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4056
                        newPart := newParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4057
                        (best endsWith:$:) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4058
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4059
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4060
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4061
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4062
                            newPart := ':' , newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4063
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4064
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4065
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4066
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4067
                        newCursorPosition := stop + newPart size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4068
                    ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4069
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4070
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4071
                (nSelParts min:newParts size) downTo:1 do:[:idx |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4072
                    |newPart oldPartialToken start stop|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4073
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4074
                    newPart := newParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4075
                    oldPartialToken := selectorParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4076
                    start := oldPartialToken start.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4077
                    stop := oldPartialToken stop.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4078
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4079
                    (best isKeywordSelector) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4080
                        (oldPartialToken value endsWith:$:) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4081
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4082
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4083
                            (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4084
                                newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4085
                            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4086
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4087
                    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4088
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4089
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4090
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4091
                            (codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4092
                                (').' includes:(codeView characterAtCharacterPosition:stop+1)) ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4093
                                    newPart := newPart , ' '
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4094
                                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4095
                            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4096
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4097
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4098
"/                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4099
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4100
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4101
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4102
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4103
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4104
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4105
                    newCursorPosition isNil ifTrue:[ 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4106
                        oldLen := stop - start + 1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4107
                        newLen := newPart size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4108
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4109
                        newCursorPosition := stop + (newLen-oldLen) 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4110
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4111
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4112
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4113
                codeView cursorToCharacterPosition:newCursorPosition.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4114
                codeView cursorRight.  "/ avoid going to the next line !!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4115
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4116
                ((best endsWith:':') and:[numArgs == 1]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4117
                    |impls impl|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4118
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4119
                    "/ see if it expects a block argument (heuristic)
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4120
                    best := best asSymbol.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4121
                    (node notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4122
                    and:[classOrNil notNil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4123
                    and:[node receiver isSelf]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4124
                        (impl := classOrNil whichClassImplements:best) isNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4125
                            impls := #().
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4126
                            Screen current beep.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4127
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4128
                            impls := { impl }
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4129
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4130
                    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4131
                        impls := Smalltalk allImplementorsOf:best.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4132
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4133
                    (impls contains:[:cls | 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4134
                        |argName|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4135
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4136
                        argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4137
                        (argName includesString:'block') or:[ (argName includesString:'action')]]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4138
                    ) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4139
                        codeView insertStringAtCursor:'['
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4140
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4141
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4142
                codeView dontReplaceSelectionOnInput.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4143
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4144
        info:'Completion'.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4145
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4146
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4147
    "Created: / 10-11-2006 / 13:18:27 / cg"
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4148
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4149
    "Modified: / 28-08-2013 / 15:27:32 / cg"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4150
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4151
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4152
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4153
    |parent nonMetaClass crsrPos nm
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4154
     allVariables allDistances best nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4155
     char start stop oldLen newLen oldVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4156
     getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4157
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4158
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4159
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4160
        nonMetaClass := classOrNil theNonMetaclass.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4161
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4162
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4163
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4164
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4165
    "/ if we are behind the variable and a space has already been entered,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4166
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4167
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4168
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4169
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4170
    char isSeparator ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4171
        classOrNil isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4172
            nodeVal := Smalltalk at:nm asSymbol.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4173
        ] ifFalse:[ 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4174
            nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4175
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4176
        nodeVal isBehavior ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4177
            |methods menu exitKey idx|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4178
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4179
            methods := nodeVal class methodDictionary values
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4180
                            select:[:m | |cat|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4181
                                cat := m category asLowercase.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4182
                                cat = 'instance creation'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4183
                            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4184
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4185
            menu := PopUpMenu labels:(methods collect:[:each | each selector]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4186
            menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4187
                    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4188
                    hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4189
                        exitKey := key.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4190
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4191
                    hide].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4192
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4193
            idx := menu startUp.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4194
            idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4195
                exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4196
                    codeView keyPress:exitKey x:0 y:0.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4197
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4198
                ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4199
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4200
            best := (methods at:idx) selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4201
            codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4202
                undoableDo:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4203
                    codeView insertString:best atCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4204
                    codeView cursorToCharacterPosition:crsrPos+best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4205
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4206
                info:'completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4207
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4208
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4209
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4210
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4211
    ((parent := node parent) notNil and:[parent isMessage]) ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4212
        node == parent receiver ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4213
            selectorOfMessageToNode := parent selector
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4214
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4215
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4216
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4217
    getDistanceComputeBlockWithWeight :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4218
        [:weight |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4219
            [:each |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4220
                |dist factor|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4221
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4222
                dist := each spellAgainst:nm.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4223
                factor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4224
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4225
                (each startsWith:nm) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4226
                    factor := 6 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4227
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4228
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4229
                        factor := 4 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4230
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4231
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4232
                dist := dist + (weight*factor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4233
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4234
                each -> (dist * weight)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4235
             ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4236
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4237
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4238
    addWithFactorBlock :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4239
        [:names :factor | |namesToAdd|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4240
            namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4241
            namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4242
            allVariables addAll:namesToAdd.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4243
            allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4244
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4245
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4246
    nm isUppercaseFirst ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4247
        globalFactor := 2.    "/ favour globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4248
        localFactor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4249
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4250
        globalFactor := 1.    "/ favour locals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4251
        localFactor := 2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4252
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4253
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4254
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4255
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4256
4308
f1c31624744d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4304
diff changeset
  4257
    "/ are we in the method's selector spec ?
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4258
    ((parent := node parent) notNil 
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4259
    and:[parent isMethod
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4260
    and:[parent arguments includes:node]]) ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4261
        "/ now thats cool: look how the naem of this argument is in other implementations
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4262
        "/ of this method, and take that as a basis of the selection
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4263
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4264
        implementors := SystemBrowser 
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4265
                            findImplementorsOf:(parent selector) 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4266
                            in:(Smalltalk allClasses)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4267
                            ignoreCase:false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4268
        "/ which argument is it
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4269
        argIdx := parent arguments indexOf:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4270
        implementors size > 50 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4271
            implementors := implementors asOrderedCollection copyTo:50.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4272
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4273
        namesUsed := implementors 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4274
                        collect:[:eachImplementor |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4275
                            |parseTree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4276
                            parseTree := eachImplementor parseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4277
                            (parseTree notNil and:[parseTree arguments size > 0]) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4278
                                ifFalse:nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4279
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4280
                        thenSelect:[:a | a notNil] as:Set.  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4281
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4282
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4283
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4284
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4285
            "/ also, look for the keyword before the argument, 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4286
            "/ and see if there is such an instVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4287
            "/ if so, add it with -Arg
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4288
            parent selector isKeyword ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4289
                kwPart := parent selector keywords at:argIdx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4290
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4291
                    addWithFactorBlock 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4292
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4293
                        value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4294
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4295
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4296
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4297
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4298
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4299
            "/ locals in the block/method
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4300
            names := node allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4301
            "/ if there were no variables (due to a parse error)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4302
            "/ do another parse and see what we have
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4303
            names isEmpty ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4304
                tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4305
                "/ better if we already have a body (include locals then)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4306
                "/ otherwise, only the arguments are considered
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4307
                tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4308
                    names := (tree body ? tree) allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4309
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4310
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4311
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4312
            addWithFactorBlock value:names value:(4 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4313
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4314
            "/ instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4315
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4316
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4317
            "/ inherited instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4318
            classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4319
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4320
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4321
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4322
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4323
        selectorOfMessageToNode notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4324
            |names responders nonResponders|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4325
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4326
            "/ responding to that messsage
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4327
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4328
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4329
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4330
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4331
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4332
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4333
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4334
                names := nonMetaClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4335
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4336
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4337
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4338
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4339
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4340
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4341
                "/ superclass var names
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4342
                nonMetaClass allSuperclassesDo:[:superClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4343
                    names := superClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4344
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4345
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4346
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4347
                    addWithFactorBlock value:responders value:(1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4348
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4349
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4350
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4351
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4352
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4353
                    names := classOrNil topNameSpace keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4354
                    names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4355
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4356
                    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4357
                    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4358
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4359
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4360
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4361
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4362
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4363
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4364
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4365
            "/ names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4366
            names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4367
            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4368
            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4369
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4370
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4371
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4372
            "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4373
            classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4374
                |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4375
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4376
                pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4377
                names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4378
                names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4379
                responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4380
                nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4381
                addWithFactorBlock value:responders value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4382
                addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4383
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4384
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4385
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4386
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4387
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4388
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4389
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4390
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4391
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4392
                classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4393
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4394
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4395
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4396
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4397
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4398
                    names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4399
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4400
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4401
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4402
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4403
                "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4404
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4405
                    |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4406
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4407
                    pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4408
                    names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4409
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4410
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4411
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4412
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4413
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4414
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4415
            names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4416
            addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4417
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4418
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4419
        "/ pseudos - assuming that thisContext is seldom used.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4420
        "/ also assuming, that nil is short so its usually typed in.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4421
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4422
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4423
        addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4424
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4425
        addWithFactorBlock value:#('true') value:(1 * localFactor).
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4426
        addWithFactorBlock value:#('false') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4427
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4428
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4429
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4430
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4431
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4432
                                                           ifTrue:[el]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4433
                                                           ifFalse:[best]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4434
                                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4435
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4436
    allDistances sort:[:a :b | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4437
                                a value > b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4438
                                    true
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4439
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4440
                                    a value = b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4441
                                        a key < b key
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4442
                                    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4443
                                        false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4444
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4445
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4446
                      ].
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4447
    ((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4448
        allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4449
        allTheBest size > 15 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4450
            allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4451
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4452
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4453
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4454
    best := self askUserForCompletion:('Variable for "%1"' bindWith:node name) for:codeView at: node start from:(allTheBest collect:[:assoc | assoc key]).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4455
    best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4456
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4457
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4458
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4459
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4460
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4461
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4462
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4463
    codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4464
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4465
        info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4466
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4467
    (best startsWith:oldVar) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4468
        oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4469
        newLen := best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4470
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4471
        codeView dontReplaceSelectionOnInput
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4472
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4473
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4474
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4475
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4476
    "Modified: / 28-08-2013 / 15:37:28 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4477
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4478
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4479
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4480
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4481
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4482
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4483
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4484
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4485
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4486
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4487
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4488
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4489
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4490
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4491
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4492
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4493
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4494
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4495
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4496
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4497
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4498
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4499
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4500
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4501
version
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  4502
    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.176 2013-09-27 09:28:05 vrany Exp $'
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4503
!
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4504
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  4505
version_CVS
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  4506
    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.176 2013-09-27 09:28:05 vrany Exp $'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4507
! !
4194
e677aae984be Refactoring:
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
  4508