DoWhatIMeanSupport.st
author Claus Gittinger <cg@exept.de>
Sat, 31 Aug 2013 00:54:03 +0200
changeset 4352 8e3e22043a75
parent 4350 8771e73d16bb
child 4353 b04d3b1d44ac
permissions -rw-r--r--
class: DoWhatIMeanSupport class definition added: #codeCompletionForMethodSpec: #codeCompletionForMethodSpec:into: #findNodeForInterval:in:allowErrors:mustBeMethod:mustBeExpression: #tryCodeCompletionWithSource:nodeInterval:into: removed:5 methods comment/format in: #documentation #lookupClassForMessage:inClass:instance: changed:8 methods category of: #codeCompletionForMethod:orClass:context:codeView:into: #tryCodeCompletionWithSource:context:nodeInterval:into:
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
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    15
	instanceVariableNames:'tree tokens classOrNil methodOrNil contextOrNil instanceOrNil
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    16
		codeView'
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
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    67
codeCompletionForClass:classOrNil codeView:codeView
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    68
    self codeCompletionForClass:classOrNil context:nil codeView:codeView
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    69
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    70
    "Modified (format): / 03-07-2011 / 15:49:49 / cg"
3557
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    71
!
a001bf3df400 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3554
diff changeset
    72
4044
1ad77f8196e3 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
    73
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    74
    "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
    75
     nil, if called from the browser.
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    76
     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
    77
     This is not yet done, sigh"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    78
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    79
    ^ self new 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    80
        codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    81
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    82
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    83
codeCompletionForMethod:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    84
    "contextOrNil is the current context, if this is called from the debugger;
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    85
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    86
     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
    87
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    88
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    89
    ^ self new
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    90
        codeCompletionForMethod:methodOrNil orClass:classOrNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    91
        context:contextOrNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    92
        codeView:codeView into:actionBlock
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    93
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    94
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    95
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    96
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
    97
findNodeForInterval:interval in:source
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    98
    ^ self new findNodeForInterval:interval in:source
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
    99
!
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   100
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   101
findNodeForInterval:interval in:source allowErrors:allowErrors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   102
    ^ self new findNodeForInterval:interval in:source allowErrors:allowErrors
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   103
!
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   104
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   105
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   106
    "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
   107
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   108
    ^ self new
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   109
        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
   110
!
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   111
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   112
findNodeForInterval:interval inParseTree:parseTree
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   113
    ^ 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
   114
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   115
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   116
findNodeIn:tree forInterval:interval
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   117
    ^ self new findNodeIn:tree forInterval:interval
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   120
!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
   121
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   122
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   123
    "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
   124
     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
   125
                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
   126
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   127
    |matches best lcName|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   128
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   129
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   130
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   131
    "/ search for exact match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   132
    anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   133
        |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   134
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   135
        category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   136
        (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
   137
            matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   138
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   139
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   140
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   141
        "/ search for case-ignoring match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   142
        lcName := aPartialCategory asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   143
        anEnvironment allClassesDo:[:aClass |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   144
            |category|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   145
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   146
            category := aClass category.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   147
            (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
   148
                matches add:category
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   149
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   150
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   151
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   152
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   153
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   154
        ^ 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
   155
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   156
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   157
        ^ 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
   158
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   159
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   160
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   161
    ^ 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
   162
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
     Smalltalk classCategoryCompletion:'Sys'    
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   165
     Smalltalk classCategoryCompletion:'System'              
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   166
     Smalltalk classCategoryCompletion:'System-BinaryStorage' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   167
    "
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   168
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   169
    "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
   170
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   171
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   172
classNameEntryCompletionBlock
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   173
    "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
   174
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   175
    ^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:'
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   176
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   177
    "Modified: / 10-08-2006 / 13:22:02 / cg"
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   178
!
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   179
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   180
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
   181
    "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
   182
     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
   183
                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
   184
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   185
    |searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix 
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   186
     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
   187
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   188
    aPartialClassName isEmpty ifTrue:[
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   189
        matches := Smalltalk allClassesForWhich:filterBlock.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   190
        ^ InputCompletionResult bestName:aPartialClassName matchingNames:#()
2661
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
    (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
   194
        w1 := words first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   195
        w2 := words second.
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   196
        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
   197
        bestMatch := rslt first.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   198
        matches := rslt second.
3549
c7c19ab7e225 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3547
diff changeset
   199
        ('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
   200
            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
   201
            bestMatch := bestMatch , ' class'.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   202
        ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   203
        ^ 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
   204
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   205
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   206
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   207
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   208
        nsPrefix := 'Smalltalk::'.
4214
f7cb4aea81db refactored
Claus Gittinger <cg@exept.de>
parents: 4210
diff changeset
   209
        searchName := aPartialClassName withoutPrefix:'Smalltalk::'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   210
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   211
        nsPrefix := ''.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   212
        searchName := aPartialClassName.
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
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   215
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   216
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   217
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   218
    isMatchString := searchName includesMatchCharacters.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   219
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   220
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   221
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   222
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   223
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   224
    tryToMatch := 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   225
        [:className :fullClassName|
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   226
            |addIt|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   227
"/ (className startsWith:'JavaScript') ifTrue:[self halt].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   228
            isMatchString ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   229
                addIt := searchName match:className
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   230
            ] ifFalse:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   231
                addIt := className startsWith:searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   232
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   233
            addIt ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   234
                matches add:(nsPrefix , fullClassName).
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   235
                matchedNamesWithoutPrefix add:className.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   236
            ] ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   237
                "/ try ignoring case
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   238
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   239
                isMatchString ifTrue:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   240
                    addIt := searchName match:className ignoreCase:true
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   241
                ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   242
                    addIt := className asLowercase startsWith:lcSearchName.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   243
                    addIt ifFalse:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   244
                        others add:className 
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   245
                    ]
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   246
                ].
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   247
                addIt ifTrue:[
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   248
                    ignCaseMatches add:(nsPrefix , fullClassName).
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   249
                    matchedNamesWithoutPrefix add:className.
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   250
                ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   251
            ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   252
            addIt
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   253
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   254
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   255
    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
   256
        |addIt fullClassName classNameWithoutPrefix|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   257
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   258
        aClass isMeta ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   259
            fullClassName := aClass name.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   260
            classNameWithoutPrefix := aClass nameWithoutPrefix.
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 := tryToMatch value:fullClassName value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   263
            addIt ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   264
                classNameWithoutPrefix ~~ fullClassName ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   265
                    tryToMatch value:classNameWithoutPrefix value:fullClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   266
                ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   267
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   268
        ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   269
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   270
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   271
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   272
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   273
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   274
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   275
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   276
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   277
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   278
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   279
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   280
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   281
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   282
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   283
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   284
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   285
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   286
"/"/            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
   287
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   288
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   289
"/"/            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
   290
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   291
"/"/            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
   292
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   293
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   294
"/"/            ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   295
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   296
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   297
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   298
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   299
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
        ^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   302
    ].                           
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   303
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   304
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   305
        best := matches first.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   306
        ^ 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
   307
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   308
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   309
    matches 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   310
        sort:[:name1 :name2 |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   311
            "name1 comes before:name2 iff"
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   312
            ((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
   313
            or:[ ((name1 includes:$:) == (name2 includes:$:))
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   314
                  and:[ (name1 size < name2 size) 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   315
                        or: [ name1 < name2 ]]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   316
               ]
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   317
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   318
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   319
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   320
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   321
    ] ifFalse:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   322
        matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   323
        best := ignCaseMatches isEmpty
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   324
                    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   325
                    ifFalse:[ matchesForLongestPrefix longestCommonPrefixIgnoreCase:true ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   326
3198
fea29ae859c9 classnamecompletion fixed when namespace is involved
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   327
        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
   328
            best := matchedNamesWithoutPrefix longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   329
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   330
        best size == 0 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   331
            "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
   332
            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
   333
            idx ~~ 1 ifTrue:[
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   334
                ^ 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
   335
            ].
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
        best size < aPartialClassName size ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   338
            best := aPartialClassName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   339
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   340
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   341
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   342
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   343
    (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
   344
        (matches conform:[:each | each = best
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   345
                                 or:[each startsWith:(best , '::')]])
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   346
        ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   347
            best := best , '::'
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   348
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   349
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   350
    ^ 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
   351
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   352
    "
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   353
     Smalltalk classnameCompletion:'Arr'    
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   354
     Smalltalk classnameCompletion:'Arra' 
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   355
     Smalltalk classnameCompletion:'arra'  
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   356
     Smalltalk classnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   357
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   358
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   359
    "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
   360
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   361
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   362
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   363
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   364
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   365
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   366
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   367
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   368
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   369
        filter:[:cls | true] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   370
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   371
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   372
    "
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   373
     self classnameCompletion:'Arr'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   374
     self classnameCompletion:'Arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   375
     self classnameCompletion:'arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   376
     self classnameCompletion:'*rray' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   377
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   378
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   379
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   380
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   381
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   382
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   383
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   384
    "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
   385
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   386
    ^ [:contents :field  |
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   387
          |s what m|
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   388
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   389
          s := contents withoutSpaces.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   390
          field topView withCursor:(Cursor questionMark) do:[  
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   391
              what := self perform:completionSelector with:s with:Smalltalk.
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   392
          ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   393
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   394
          field contents:(what first).
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   395
          (what at:2) size ~~ 1 ifTrue:[
3693
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   396
              UserPreferences current beepInEditor ifTrue:[                
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   397
                field device beep
9d0059e1374b beepInEditor flag
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
   398
              ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   399
          ]
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   400
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   401
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   402
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   403
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   404
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   405
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   406
    "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
   407
     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
   408
                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
   409
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   410
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   411
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   412
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   413
     Smalltalk globalnameCompletion:'Arr' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   414
     Smalltalk globalnameCompletion:'Arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   415
     Smalltalk globalnameCompletion:'arra' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   416
     Smalltalk globalnameCompletion:'*rray' 
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   417
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   418
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   419
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   420
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   421
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   422
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   423
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   424
     2 entries: 1st: the best (longest) match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   425
                2nd: collection consisting of matching names"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   426
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   427
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   428
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   429
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   430
    searchName isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   431
        ^ Array with:searchName with:#()
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   432
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   433
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   434
    (searchName at:1) isLowercase ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   435
        searchName := searchName copy asUppercaseFirst
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   436
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   437
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   438
    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
   439
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   440
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   441
    anEnvironment keysDo:[:aGlobalName |
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   442
        | addIt|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   443
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   444
        isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   445
            addIt := searchName match:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   446
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   447
            addIt := aGlobalName startsWith:searchName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   448
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   449
        addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   450
            matches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   451
        ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   452
            "/ try ignoring case
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   453
            isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   454
                addIt := searchName match:aGlobalName ignoreCase:true
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   455
            ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   456
                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
   457
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   458
            addIt ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   459
                ignCaseMatches add:aGlobalName
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   460
            ]
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
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   464
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   465
        matches := ignCaseMatches
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   466
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   467
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   468
    matches isEmpty ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   469
        ^ 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
   470
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   471
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   472
        ^ 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
   473
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   474
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   475
    isMatchString ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   476
        best := searchName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   477
    ] ifFalse:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   478
        best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   479
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   480
    ^ 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
   481
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   482
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   483
     Smalltalk globalnameCompletion:'Arr' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   484
     Smalltalk globalnameCompletion:'Arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   485
     Smalltalk globalnameCompletion:'arra' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   486
     Smalltalk globalnameCompletion:'*rray' 
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   487
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   488
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   489
    "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
   490
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   491
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   492
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   493
    "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
   494
     2 entries: 1st: the best (longest) match 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   495
                2nd: collection consisting of matching protocols"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   496
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   497
    |matches best lcName|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   498
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   499
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   500
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   501
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   502
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   503
        |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   504
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   505
        protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   506
        (protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   507
            matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   508
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   509
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   510
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   511
        "/ search for case-ignoring match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   512
        lcName := aPartialProtocolName asLowercase.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   513
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   514
            |protocol|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   515
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   516
            protocol := eachMethod category.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   517
            (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   518
                matches add:protocol
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   519
            ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   520
        ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   521
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   522
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   523
    matches isEmpty ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   524
        ^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
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 size == 1 ifTrue:[
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   527
        ^ Array with:matches first with:(matches asArray)
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   528
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   529
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   530
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   531
    ^ Array with:best with:matches asArray
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   532
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
     Smalltalk methodProtocolCompletion:'doc'
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   535
     Smalltalk methodProtocolCompletion:'docu' 
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   536
     Smalltalk methodProtocolCompletion:'documenta' 
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
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   540
    "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
   541
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   542
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   543
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   544
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   545
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   546
                2nd: collection consisting of matching names"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   547
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   548
    ^ self
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   549
        classnameCompletion:aPartialClassName 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   550
        filter:[:cls | cls isNameSpace] 
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   551
        inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   552
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   553
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   554
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk  
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   555
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   556
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   557
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   558
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   559
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   560
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   561
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   562
     2 entries: 1st: the best (longest) match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   563
                2nd: collection consisting of matching packages"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   564
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   565
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   566
4195
f154f90d39a6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
   567
    matches := Smalltalk allProjectIDs
f154f90d39a6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
   568
        select:[:package | package startsWith:aPartialPackage].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   569
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   570
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   571
        "/ search for case-ignoring match
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   572
        lcName := aPartialPackage asLowercase.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   573
        anEnvironment allClassesDo:[:aClass |
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   574
            |package|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   575
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   576
            package := aClass package.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   577
            (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   578
                matches add:package
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   579
            ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   580
        ].
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
    matches isEmpty ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   584
        ^ Array with:aPartialPackage with:(Array with:aPartialPackage)
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
    matches size == 1 ifTrue:[
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   587
        ^ Array with:matches first with:(matches asArray)
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
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   590
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   591
    ^ Array with:best with:matches asArray
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   592
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
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk   
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   595
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk                
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   596
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   597
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   598
    "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
   599
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   600
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   601
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   602
    "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
   603
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   604
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   605
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   606
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   607
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   608
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   609
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   610
    "given a partial poolname, return an array consisting of
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   611
     2 entries: 1st: the best (longest) match
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   612
                2nd: collection consisting of matching names"
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   613
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   614
    ^ self
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   615
        classnameCompletion:aPartialClassName 
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   616
        filter:[:cls | cls isSharedPool] 
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   617
        inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   618
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   619
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   620
     self poolnameCompletion:'Win' inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   621
     self poolnameCompletion:'Z'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   622
     self poolnameCompletion:'a'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   623
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   624
!
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   625
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   626
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   627
    "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
   628
     2 entries: 1st: the longest match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   629
                2nd: collection consisting of matching defined resources"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   630
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   631
    |matches best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   632
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   633
    matches := IdentitySet new.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   634
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   635
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   636
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   637
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   638
        eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   639
            eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   640
                (isMatch 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   641
                    ifTrue:[ (aPartialResourceName match:eachResourceName ignoreCase:ignoreCase) ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   642
                    ifFalse:[ ignoreCase 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   643
                                ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ]  
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   644
                                ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   645
                ) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   646
                    matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   647
                ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   648
            ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   649
        ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   650
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   651
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   652
        "/ search for case-ignoring match
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   653
        lcSym := aPartialResourceName asLowercase.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   654
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   655
            eachMethod hasResource ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   656
                eachMethod resources keysDo:[:eachResourceName |
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   657
                    (isMatch 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   658
                        ifTrue:[ (aPartialResourceName match:eachResourceName ignoreCase:true) ]
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   659
                        ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ])
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   660
                     ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   661
                        matches add:eachResourceName
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   662
                    ].
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
            ].
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
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   667
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   668
    matches isEmpty ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   669
        ^ Array with:aPartialResourceName with:#() 
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   670
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   671
    matches size == 1 ifTrue:[
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   672
        ^ Array with:matches first with:(matches asArray)
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   673
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   674
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   675
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   676
    ^ Array with:best with:matches asArray
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
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   680
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   681
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   682
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   683
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   684
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   685
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   686
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   687
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   688
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   689
    "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
   690
     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
   691
                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
   692
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   693
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   694
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   695
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   696
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   697
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   698
     2 entries: 1st: the longest match
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   699
                2nd: collection consisting of matching implemented selectors"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   700
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   701
    ^ self 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   702
        selectorCompletion:aPartialSymbolName 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   703
        inEnvironment:anEnvironment 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   704
        match:doMatch 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   705
        ignoreCase:false
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   706
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   707
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   708
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   709
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   710
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   711
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   712
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   713
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   714
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   715
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   716
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   717
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   718
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   719
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   720
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   721
     2 entries: 1st: the longest match
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   722
                2nd: collection consisting of matching implemented selectors"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   723
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   724
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   725
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   726
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   727
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   728
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   729
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   730
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   731
        (isMatch 
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   732
            ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:ignoreCase) ]
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   733
            ifFalse:[ ignoreCase 
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   734
                        ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ]  
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   735
                        ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ])
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   736
         ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   737
            matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   738
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   739
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   740
    (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
   741
        "/ search for case-ignoring match
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   742
        lcSym := aPartialSymbolName asLowercase.
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   743
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   744
            (isMatch 
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   745
                ifTrue:[ (aPartialSymbolName match:eachSelector ignoreCase:true) ]
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   746
                ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ])
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   747
             ifTrue:[
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   748
                matches add:eachSelector
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   749
            ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   750
        ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   751
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   752
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   753
    matches isEmpty ifTrue:[
3864
10c7db09a580 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
   754
        ^ 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
   755
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   756
    matches size == 1 ifTrue:[
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   757
        ^ 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
   758
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   759
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   760
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   761
    ^ 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
   762
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   763
    "
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   764
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   765
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   766
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true 
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   767
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   768
     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
   769
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   770
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   771
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   772
    "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
   773
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   774
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   778
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   779
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   780
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   781
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
    (lastNewName endsWith:lastOldName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   789
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   790
            'foo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   791
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   792
            'bar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   793
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
        ^ (prefix , oldName).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
    (lastOldName endsWith:lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   798
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   799
            'Xfoo' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   800
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   801
            'Xbar' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   802
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   804
        (oldName startsWith:prefix) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   805
            ^ (oldName copyFrom:prefix size+1).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   806
        ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   807
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   808
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   809
        (lastOldName first ~= lastNewName first) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   810
            (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   811
                "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   812
                    'xfoo' -> 'Xfoo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   813
                 then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   814
                    'xbar' would be 'Xbar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   815
                "
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   816
                lastOldName first isLowercase ifTrue:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   817
                    ^ oldName first asUppercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   818
                ] ifFalse:[
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   819
                    ^ oldName first asLowercase asString , (oldName copyFrom:2).
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   820
                ]
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   821
            ]
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
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   825
        "last rename was 
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   826
            '  foo   ' -> 'foo'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   827
         then, a good default for
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   828
            '  bar   ' would be 'bar'
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   829
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
        ^ oldName withoutSeparators.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    (lastNewName startsWith:lastOldName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   833
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   834
            'foo' -> 'fooX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   835
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   836
            'bar' would be 'barX'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   837
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
        ^ (oldName , suffix).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
    (lastOldName startsWith:lastNewName) ifTrue:[
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   842
        "last rename was 
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   843
            'fooX' -> 'foo'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   844
         then, a good default for
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   845
            'barX' would be 'bar'
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   846
        "
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
        (oldName endsWith:suffix) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   849
            ^ (oldName copyButLast:suffix size).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
        ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   852
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   853
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   854
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   855
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   856
    (prefix size > 0) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   857
        (suffix size > 0) ifTrue:[
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   858
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   859
            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
   860
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   861
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   862
                'fooR' -> 'fooXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   863
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   864
                'barR' would be 'barXR'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   865
            "
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   866
            left := lastOldName copyTo:prefix size.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   867
            right := lastOldName copyLast:suffix size.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   868
            lastNewSize > lastOldSize ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   869
                inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   870
                inserted size > 0 ifTrue:[
3532
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   871
                    (oldName startsWith:prefix) ifTrue:[
4341
ad65afd01683 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4340
diff changeset
   872
                        ^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
3532
c79c6acf377d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   873
                    ].
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   874
                ].
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   875
            ].
3585
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   876
            (oldName string endsWith:suffix string) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   877
                deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
3585
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   878
                (oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   879
                    ((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
   880
                        "last rename was 
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   881
                            'fooXR' -> 'fooR'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   882
                         then, a good default for
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   883
                            'barXS' would be 'barS'
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   884
                        "
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   885
                        ^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
b127cf1ed41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3557
diff changeset
   886
                    ]
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
            ]
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   889
        ].
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   890
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   891
        (oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   892
            "last rename was 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   893
                'fooX' -> 'fooY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   894
             then, a good default for
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   895
                'barX' would be 'barY'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   896
            "
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   897
            left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   898
            right := lastNewName copyFrom:prefix size+1.
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   899
            ^ left , right
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   900
        ] 
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   901
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   903
    suffix size > 0 ifTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   904
        |prefix2|
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   905
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   906
        "last rename was:
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   907
            'fooSUFF1' -> 'barSUFF1'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   908
         then, a good default for
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   909
            'fooSUFF2' -> 'barSUFF2'
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   910
        "
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   911
        prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   912
        (oldName startsWith:prefix) ifTrue:[    
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   913
            prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   914
            ^ prefix2,(oldName copyFrom:(prefix size+1)).
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   915
        ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   916
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   917
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   918
    "/ was there something stripped at the end?
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   919
    suffix := oldName commonSuffixWith:lastOldName. 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   920
    [suffix size > 0] whileTrue:[
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   921
        tryAgain := self
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   922
                    goodRenameDefaultFor:(oldName copyButLast:suffix size)
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   923
                    lastOld:(lastOldName copyButLast:suffix size)
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   924
                    lastNew:lastNewName.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   925
        tryAgain notNil ifTrue:[^ tryAgain].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   926
        suffix := suffix copyFrom:2.
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   927
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   928
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   929
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   930
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   931
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   932
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   933
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   934
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   935
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   936
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   937
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' 
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   938
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'  
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   939
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   940
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   941
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   942
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'            
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   943
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'          
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   944
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'  
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   945
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   946
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'  
2560
cc5ba9cf02b8 insertion
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   947
     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
   948
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   949
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   950
                       lastOld:'mti.odt2.level1HeadlineMatchPattern' 
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   951
                       lastNew:'Key_odt2_level1HeadlineMatchPattern'  
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   952
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   953
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   954
    "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
   955
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   956
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   957
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   958
    "generate a reasonable default for a file rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   959
     (Try to rename multiple files in the new fileBrowser, 
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   960
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   961
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   962
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   963
     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
   964
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   965
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   966
    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
   967
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   968
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
   969
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
   970
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
   971
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   973
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   974
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   975
        lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   976
            ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   977
        ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   978
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
   979
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   980
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   981
    default notNil ifTrue:[ 
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   982
        lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   983
        lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   984
        oldRest := oldName copyFrom:oldWOSuffix size + 1.
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   985
        
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   986
        ^ default , lastNewRest
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   987
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   988
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
        oldRest := oldWOSuffix copyFrom:prefix size + 1.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
        (lastNewRest endsWith:lastOldRest) ifTrue:[
4210
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
   996
            t := lastNewRest copyButLast:lastOldRest size.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
    suffix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
        "/ last change changed something at the beginning
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
        prefix size > 0 ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
            "/ 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
  1007
            lastRemoved := lastOldWOSuffix copyButLast:suffix size.
5c5f1603748d Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 4195
diff changeset
  1008
            lastInserted := lastNewWOSuffix copyButLast:suffix size.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1009
            (lastRemoved startsWith:lastInserted) ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
                oldWOSuffix size >= lastInserted size ifTrue:[
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1011
                    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
                ]
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
            ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
        ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1018
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1019
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1020
    "Modified: / 07-11-2006 / 13:58:39 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1021
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1023
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1024
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1025
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1026
    "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
  1027
     This is used to specially priorize plausible typing errors of adjacent keys.
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1028
     CAVEAT: hard coded us- and german keyboards here."
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1029
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1030
    ^ 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
  1031
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1032
    "
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1033
     self isKey:$a nextTo:$a   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1034
     self isKey:$a nextTo:$s   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1035
     self isKey:$a nextTo:$q   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1036
     self isKey:$a nextTo:$w   
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
  1037
     self isKey:$a nextTo:$z   
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1038
     self isKey:$a nextTo:$x 
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1039
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1040
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1041
    "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
  1042
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1043
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1044
isKey:k1 nextTo:k2 onKeyboard:keys
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1045
    "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
  1046
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1047
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1048
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1049
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1050
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1051
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1052
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1053
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1054
    ^ (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
  1055
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1056
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1057
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1058
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1059
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1060
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1061
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1062
keyboard
4093
f98873e4d965 comment in: #keyboard
Claus Gittinger <cg@exept.de>
parents: 4087
diff changeset
  1063
    "the keyboard layout (useful to figure out which keys are nearby a key,
f98873e4d965 comment in: #keyboard
Claus Gittinger <cg@exept.de>
parents: 4087
diff changeset
  1064
     to find possible typing errors)"
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1065
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1066
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1067
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1068
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1069
    lang == #de ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1070
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1071
               '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1072
               '*qwertzuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1073
               '**asdfghjkl:'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1074
               '***yxcvbnm' ).
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1075
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1076
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1077
    lang == #fr ifTrue:[
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1078
        ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1079
               '1234567890'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1080
               '*azertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1081
               '**qsdfghjklm'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1082
               '***wxcvbn,' ).
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1083
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1084
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1085
    ^ #( 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1086
           '1234567890-'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1087
           '*qwertyuiop'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1088
           '**asdfghjkl:'
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1089
           '***zxcvbnm' ).
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
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1092
     self keyboard 
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1093
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1094
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1095
    "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
  1096
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1097
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1098
!DoWhatIMeanSupport methodsFor:'code completion'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1099
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1100
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1101
    "OBSOLETE; migrating to use the into protocol.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1102
     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
  1103
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1104
     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
  1105
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1106
    
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1107
    |crsrPos char interval source node parent checkedNode instanceOrNil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1108
     forceNewMessageSend classOfReceiver|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1109
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1110
    classOrNil := classOrNilArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1111
    codeView := codeViewArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1112
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1113
"/    classOrNil isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1114
"/        self information:'No class'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1115
"/        ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1116
"/    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1117
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1118
    crsrPos := codeView characterPositionOfCursor"-1".
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1119
    char := codeView characterAtCharacterPosition:crsrPos.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1120
    "/ Transcript show:crsrPos; show:' '; showCR:char.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1121
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1122
        crsrPos := crsrPos - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1123
        char := codeView characterAtCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1124
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1125
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1126
    interval := codeView selectedInterval.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1127
    "/ Transcript show:'iv: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1128
    interval isEmpty ifTrue:[
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1129
        interval := crsrPos"-1" to:crsrPos.
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1130
        "/ Transcript show:'iv2: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1131
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1132
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1133
    source := codeView contentsAsString string.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1134
    source := source copyTo:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1135
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1136
    "/ this is too naive and stupid; if there is a syntactic error,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1137
    "/ 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
  1138
    "/ 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
  1139
    "/ without any progress.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1140
    "/ 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
  1141
    "/ as it parses the code. Stop, when the interval is hit.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1142
    "/ that will also work for syntactic incorrect source code.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1143
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1144
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.   
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1145
        "/ Transcript show:'nd1: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1146
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1147
    node isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1148
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.   
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1149
        "/ Transcript show:'nd2: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1150
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1151
"/    [node isNil] whileTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1152
"/        "/ expand to the left ...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1153
"/        interval start > 1 ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1154
"/            self information:'No parseNode found'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1155
"/            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1156
"/        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1157
"/        interval start:(interval start - 1).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1158
"/        node := self findNodeForInterval:interval in:source allowErrors:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1159
"/    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1160
    node isNil ifTrue:[
4334
80c903b3a23b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4329
diff changeset
  1161
        Transcript showCR:'No parseNode found (syntax error before?)'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1162
        self breakPoint:#cg.
4334
80c903b3a23b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4329
diff changeset
  1163
        self information:'No parseNode found (syntax error before?)'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1164
        ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1165
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1166
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1167
    forceNewMessageSend := false.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1168
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1169
    "/ 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
  1170
    (codeView characterBeforeCursor isSeparator
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1171
        or:[ ')}]''' includes:codeView characterBeforeCursor ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1172
    ) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1173
        (node isVariable
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1174
            and:[ (parent := node parent) notNil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1175
            and:[ parent isMessage ]]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1176
        ) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1177
            "/ completion after a variable node...
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1178
            parent isKeyword ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1179
                "/ and it is a keyword message, we complete the keyword message instead
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1180
                node := parent.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1181
            ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1182
                "/ 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
  1183
                "/ (however, no character is available to determine what is useful)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1184
                forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1185
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1186
        ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1187
            (node isUnary) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1188
                "/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1189
                "/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1190
                forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1191
"/                "/ can we see what we get from foo?
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1192
"/                classOfReceiver := self 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1193
"/                                    classOfReceiver:node receiver
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1194
"/                                    inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1195
"/                classOfReceiver notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1196
"/                    |mthd|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1197
"/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1198
"/                    mthd := classOfReceiver lookupMethodFor:node selector.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1199
"/                    mthd notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1200
"/                        self halt.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1201
"/                        (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1202
"/                            forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1203
"/                        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1204
"/                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1205
"/                ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1206
            ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1207
        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1208
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1209
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1210
    forceNewMessageSend ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1211
        "/ completion with nothing to start (right after a variable)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1212
        "/ see what the variable can understand and present the most useful stuff (very thin ice here)
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1213
        classOfReceiver := self 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1214
                            classOfReceiver:node 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1215
                            inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1216
        classOfReceiver isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1217
            "/ 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
  1218
            "/ will be...
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1219
            Screen current beep.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1220
        ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1221
            |superClass possible choice|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1222
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1223
            possible := classOfReceiver selectors.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1224
            superClass := classOfReceiver superclass.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1225
            [superClass notNil and:[(possible size + superClass selectors size) < 50]] whileTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1226
                possible := possible,superClass selectors.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1227
                superClass := superClass superclass.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1228
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1229
            possible := possible copy sort.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1230
            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
  1231
            choice isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1232
                Screen current beep. 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1233
                ^ self
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1234
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1235
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1236
            codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1237
                undoableDo:[ 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1238
                    codeView insertStringAtCursor:choice
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1239
                ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1240
                info:'Completion'.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1241
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1242
        ^ self
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1243
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1244
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1245
    node isVariable ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1246
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1247
        ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1248
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1249
    node isLiteral ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1250
        node value isSymbol ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1251
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1252
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1253
        ].
4348
d935a4f7c740 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4346
diff changeset
  1254
        ^ self "/ huh - strings or what?
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1255
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1256
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1257
    checkedNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1258
    [checkedNode notNil] whileTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1259
        checkedNode isMessage ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1260
            "/ completion in a message-send
4326
4dbf9b13bc59 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4314
diff changeset
  1261
            contextOrNil notNil ifTrue:[
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1262
"/                |rcvrNode idx rcvr val|
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1263
"/
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1264
"/                (rcvrNode := checkedNode receiver) isVariable ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1265
"/                    rcvrNode isSelf ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1266
"/                        classOrNil := contextOrNil receiver class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1267
"/                    ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1268
"/                        (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1269
"/                            val := contextOrNil argsAndVars at:idx.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1270
"/                            classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1271
"/                        ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1272
"/                            (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1273
"/                                val := contextOrNil receiver instVarNamed:rcvrNode name.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1274
"/                                classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1275
"/                            ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1276
"/                        ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1277
"/                    ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1278
"/                ].
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1279
                instanceOrNil := contextOrNil receiver
4326
4dbf9b13bc59 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4314
diff changeset
  1280
            ].
4344
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1281
            self 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1282
                codeCompletionForMessage:checkedNode 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1283
                inClass:classOrNil instance:instanceOrNil 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  1284
                context:contextOrNil codeView:codeView.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1285
            ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1286
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1287
        checkedNode isMethod ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1288
            "/ completion in a method's selector pattern
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1289
            self codeCompletionForMethodSpec:checkedNode.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1290
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1291
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1292
        checkedNode := checkedNode parent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1293
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1294
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1295
    self information:'Node is neither variable nor message.'.
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
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1298
    "Modified: / 28-08-2013 / 17:15:25 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1299
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1300
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1301
codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1302
    "contextOrNil is the current context, if this is called from the debugger;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1303
     or nil, if called from the browser.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1304
     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
  1305
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1306
    |crsrPos char interval source partialSource suggestions1 suggestions2 actions1 actions2 title1 title2|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1307
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1308
    methodOrNil := methodOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1309
    classOrNil := classOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1310
    codeView := codeViewArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1311
    contextOrNil := contextOrNilArg.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1312
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1313
"/    classOrNil isNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1314
"/        self information:'No class'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1315
"/        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1316
"/    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1317
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1318
    crsrPos := codeView characterPositionOfCursor"-1".
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1319
    char := codeView characterAtCharacterPosition:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1320
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1321
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1322
        crsrPos := crsrPos - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1323
        char := codeView characterAtCharacterPosition:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1324
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1325
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1326
    interval := crsrPos-1 to:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1327
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1328
    source := codeView contentsAsString string.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1329
    partialSource := source copyTo:crsrPos.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1330
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1331
    self 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1332
        tryCodeCompletionWithSource:partialSource nodeInterval:interval 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1333
        into:[:listOfSuggestions :listOfActions :titleWhenAsking |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1334
            suggestions1 := listOfSuggestions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1335
            actions1 := listOfActions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1336
            title1 := titleWhenAsking.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1337
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1338
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1339
    self 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1340
        tryCodeCompletionWithSource:source nodeInterval:interval 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1341
        into:[:listOfSuggestions :listOfActions :titleWhenAsking |  
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1342
            suggestions2 := listOfSuggestions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1343
            actions2 := listOfActions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1344
            title2 := titleWhenAsking.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1345
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1346
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1347
    suggestions1 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1348
        actionBlock value:suggestions1 value:actions1 value:title1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1349
    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1350
        suggestions2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1351
            actionBlock value:suggestions2 value:actions2 value:title2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1352
        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1353
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1354
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1355
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1356
!DoWhatIMeanSupport methodsFor:'code completion-helpers'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1357
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1358
askUserForCompletion:what for:codeView at:position from:allTheBest 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1359
    |list choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1360
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1361
    "/ cg: until the new stuff works,...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1362
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1363
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1364
"/    allTheBest isEmpty ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1365
"/        ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1366
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1367
"/    allTheBest size == 1 ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1368
"/        ^ allTheBest first
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1369
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1370
"/    list := allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1371
"/    LastChoices notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1372
"/        lastChoice := LastChoices at:what ifAbsent:nil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1373
"/        lastChoice notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1374
"/            list := { lastChoice allBold } , (list copyWithout:lastChoice).
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
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1377
"/    choice := Tools::CodeCompletionMenu 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1378
"/                openFor:codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1379
"/                at:position
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1380
"/                with:allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1381
"/    LastChoices isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1382
"/        LastChoices := Dictionary new.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1383
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1384
"/    LastChoices at:what put:choice.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1385
"/    ^ choice string
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1386
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1387
    "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
  1388
    "Modified: / 28-08-2013 / 16:41:35 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1389
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1390
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1391
askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1392
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1393
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1394
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1395
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
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
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1398
    LastChoices notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1399
        lastChoice := LastChoices at:what ifAbsent:nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1400
        lastChoice notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1401
            list := {lastChoice. nil. } , (list copyWithout:lastChoice).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1402
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1403
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1404
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1405
    list size < 30 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1406
        |menu idx exitKey|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1407
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1408
        menu := PopUpMenu labels:list.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1409
        menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1410
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1411
                hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1412
                    exitKey := key.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1413
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1414
                hide].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1415
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1416
        idx := menu startUp.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1417
        idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1418
            exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1419
                codeView keyPress:exitKey x:0 y:0.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1420
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1421
            ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1422
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1423
        choice := list at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1424
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1425
        resources := codeView application isNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1426
                        ifTrue:[ codeView resources]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1427
                        ifFalse:[ codeView application resources ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1428
                    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1429
        choice := Dialog
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1430
           choose:(resources string:'Choose ',what)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1431
           fromList:list
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1432
           lines:20
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1433
           title:(resources string:'Code completion').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1434
        choice isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1435
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1436
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1437
    LastChoices isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1438
        LastChoices := Dictionary new.
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
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1441
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1442
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1443
    "Created: / 10-11-2006 / 14:00:53 / cg"
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
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1446
classOfReceiver:receiver inClass:classProvidingNamespaceOrNil instance:instanceOrNil context:contextOrNil
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1447
    "when showing possible completions for a message, it is a good idea to know what the reveiver
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1448
     is."
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1449
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1450
    | nm nodeVal receiverClass|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1451
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1452
    receiver isLiteral ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1453
        ^ receiver value class
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1454
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1455
    receiver isVariable ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1456
        nm := receiver name.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1457
        nm = 'self' ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1458
            classProvidingNamespaceOrNil isNil ifTrue:[^ UndefinedObject].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1459
            ^ classProvidingNamespaceOrNil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1460
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1461
        nm = 'super' ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1462
            classProvidingNamespaceOrNil isNil ifTrue:[^ Object].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1463
            ^ classProvidingNamespaceOrNil superclass
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1464
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1465
        nm isUppercaseFirst ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1466
            "/ wouldn't it be better to simply 'evaluate' the variable ?
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1467
            Error handle:[:ex |
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1468
            ] do:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1469
                |dummyReceiver|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1470
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1471
                dummyReceiver := classProvidingNamespaceOrNil notNil ifTrue:[classProvidingNamespaceOrNil basicNew] ifFalse:[nil].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1472
                nodeVal := Parser new evaluate:nm in:nil receiver:dummyReceiver.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1473
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1474
"/            (Smalltalk includesKey:nm asSymbol) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1475
"/                nodeVal := Smalltalk at:nm asSymbol.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1476
"/            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1477
            nodeVal notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1478
                ^ nodeVal class
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1479
            ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1480
        ] ifFalse:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1481
            contextOrNil notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1482
                "/ a local in the context?
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1483
                (contextOrNil argAndVarNames includes:nm) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1484
                    nodeVal := contextOrNil argsAndVars at:(contextOrNil argAndVarNames indexOf:nm).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1485
                    nodeVal notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1486
                        ^ nodeVal class
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1487
                    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1488
                ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1489
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1490
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1491
            classProvidingNamespaceOrNil notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1492
                (classProvidingNamespaceOrNil allInstVarNames includes:nm) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1493
                    instanceOrNil notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1494
                        ^ (instanceOrNil instVarNamed:nm) class
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1495
                    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1496
                ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1497
            ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1498
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1499
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1500
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1501
    receiver isMessage ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1502
        "/ some hardwired knowlegde here
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1503
        (receiver selector = #'new'
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1504
        or:[ receiver selector = #'new:' ]) ifTrue:[
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1505
            receiverClass := self lookupClassForMessage:receiver inClass:classProvidingNamespaceOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1506
            receiverClass notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1507
                receiverClass isBehavior ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1508
                    receiverClass isMeta ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1509
                        ^ receiverClass theNonMetaclass
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1510
                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1511
                ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1512
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1513
        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1514
        classProvidingNamespaceOrNil notNil ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1515
            (receiver receiver isSelf and:[receiver selector = #'class']) ifTrue:[
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1516
                ^ classProvidingNamespaceOrNil class
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1517
            ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1518
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1519
        (receiver selector = #'size') ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1520
            ^ SmallInteger
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1521
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1522
        (#( isNil notNil not emptyOrNil notEmptyOrNil notEmpty isEmpty 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1523
            = ~= == ~~ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1524
            includes: contains: ) includes:receiver selector ) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1525
            ^ Boolean
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1526
        ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1527
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1528
    ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1529
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1530
    "Created: / 28-08-2013 / 16:34:53 / cg"
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1531
!
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1532
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1533
codeCompletionForLiteralSymbol:node into:actionBlock
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1534
    "looking for all symbols is way too much and inprecise;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1535
     experiment: only present symbols which are used by the class,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1536
     and classes in that class category. We'll see..."
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1537
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1538
    |sym possibleCompletions longest editAction start stop addSymbol|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1539
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1540
    "/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1541
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1542
    start := node start.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1543
    stop := node stop.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1544
    (codeView characterAtCharacterPosition:stop) == $' ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1545
        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1546
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1547
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1548
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1549
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1550
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1551
    addSymbol :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1552
        [:aSymbol |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1553
            (aSymbol startsWith:sym) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1554
                (aSymbol = sym) ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1555
                    possibleCompletions add:aSymbol
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1556
                ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1557
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1558
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1559
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1560
    classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1561
        Smalltalk allClassesInCategory:classOrNil do:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1562
            cls theNonMetaclass instAndClassMethodsDo:[:mthd |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1563
                mthd usedSymbols do:addSymbol
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1564
            ]
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
    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1567
        Symbol allInstancesDo:addSymbol.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1568
    ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1569
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1570
    possibleCompletions sort.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1571
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1572
    longest := possibleCompletions longestCommonPrefix.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1573
    possibleCompletions remove:longest ifAbsent:[].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1574
    possibleCompletions addFirst: longest.
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
    editAction :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1577
        [:chosenIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1578
            |chosen oldSym oldLen newLen|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1579
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1580
            chosen := possibleCompletions at:chosenIndex.
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
            (codeView characterAtCharacterPosition:start) == $# ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1583
                start := start + 1.
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
            (codeView characterAtCharacterPosition:start) == $' ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1586
                start := start + 1.
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
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1589
            oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1590
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1591
            codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1592
                undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1593
                    codeView replaceFromCharacterPosition:start to:stop with:chosen 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1594
                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1595
                info:'Completion'.
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
            (chosen startsWith:oldSym) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1598
                oldLen := stop - start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1599
                newLen := chosen size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1600
                codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1601
                codeView dontReplaceSelectionOnInput
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1602
            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1603
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1604
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1605
    actionBlock value:possibleCompletions value:editAction value:'symbol'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1606
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1607
    "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
  1608
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1609
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1610
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1611
codeCompletionForMessage:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1612
    |selector srchClass implClass 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1613
     bestSelectors selector2 bestSelectors2 allBest best info numArgs
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1614
     newParts nSelParts oldLen newLen selectorParts 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1615
     findBest parentNode selectorInBest selector2InBest2
4311
9ff3061bd3b4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4310
diff changeset
  1616
     parser selectorsSentInCode split editAction cls|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1617
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1618
    "/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1619
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1620
"/    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1621
"/        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1622
"/        selectorsSentInCode := parser messagesSent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1623
"/    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1624
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1625
    findBest := [:node :selector |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1626
        |srchClass bestSelectors bestPrefixes|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1627
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1628
        codeView topView withCursor:(Cursor questionMark) do:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1629
            srchClass := self lookupClassForMessage:node inClass:classOrNil.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1630
            bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1631
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1632
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1633
        (bestSelectors includes:selector) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1634
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1635
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1636
        bestSelectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1637
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1638
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1639
    selector := node selector.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1640
    parentNode := node parent.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1641
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1642
    "/ if there is already space before the cursor, do not attempty to complete the
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1643
    "/ current message. Instead, look for a parent keyword message.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1644
    "/ is this a good idea? (could be that we want to see possible arguments for the kw message)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1645
    (codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1646
        (parentNode notNil and:[ parentNode isMessage ]) ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1647
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1648
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1649
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1650
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1651
    bestSelectors := findBest value:node value:selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1652
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1653
    "/ if we are behind a keyword messages colon,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1654
    "/ only look for matching prefix selectors;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1655
    "/ also, a good completion is to insert an argument;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1656
    "/ 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
  1657
    selector isKeyword ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1658
        codeView characterBeforeCursor == $: ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1659
            bestSelectors := bestSelectors select:[:sel | sel startsWith:selector].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1660
            bestSelectors isEmpty ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1661
                "/ nothing better around
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1662
                |argIndex argNames impls|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1663
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1664
                argIndex := node selectorParts size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1665
                argNames := Set new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1666
                impls := Smalltalk allImplementorsOf:selector.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1667
                impls size < 10 ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1668
                    impls do:[:eachImplClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1669
                        |mthd argName|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1670
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1671
                        mthd := (eachImplClass compiledMethodAt:selector).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1672
                        argName := mthd methodArgNames at:argIndex.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1673
                        argNames add:(argName,' in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1674
                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1675
                    argNames notEmptyOrNil ifTrue: [
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1676
                        argNames := argNames asOrderedCollection sort.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1677
                        actionBlock 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1678
                            value:argNames
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1679
                            value:[:selIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1680
                                  ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1681
                            value: 'argument name hint'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1682
                        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1683
                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1684
                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1685
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1686
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1687
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1688
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1689
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1690
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1691
    "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1692
    (node selector isUnarySelector 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1693
    and:[ parentNode notNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1694
    and:[ parentNode isMessage 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1695
    and:[ (selector2 := parentNode selector) isKeywordSelector ]]]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1696
        "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1697
        selector2 := selector2,selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1698
        bestSelectors2 := findBest value:parentNode value:selector2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1699
    ].
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
    bestSelectors2 isEmptyOrNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1702
        allBest := bestSelectors.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1703
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1704
        bestSelectors isEmptyOrNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1705
            allBest := bestSelectors2
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1706
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1707
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1708
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1709
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1710
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1711
                "/ selector2 is more likely
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1712
                allBest := bestSelectors2
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1713
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1714
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1715
                    "/ selector more likely
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1716
                    allBest := bestSelectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1717
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1718
                    "/ assume same likelyness
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1719
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1720
                    allBest := bestSelectors isEmpty 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1721
                                ifTrue:[ bestSelectors2 ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1722
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1723
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1724
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1725
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1726
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1727
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1728
    allBest isEmptyOrNil ifTrue:[ ^ self ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1729
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1730
    split := [:list :splitHow |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1731
        |part1 part2 all|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1732
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1733
        part1 := list select:splitHow.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1734
        part2 := list reject:splitHow.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1735
        part1 isEmpty ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1736
            all := part2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1737
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1738
            part2 isEmpty ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1739
                all := part1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1740
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1741
                all := part1 , part2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1742
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1743
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1744
        all
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1745
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1746
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1747
    selectorsSentInCode notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1748
        "/ the ones already sent in the code are moved to the top of the list.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1749
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1750
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1751
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1752
    "/ the ones which are a prefix are moved towards the top of the list
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1753
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1754
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1755
false ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1756
    srchClass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1757
        implClass := srchClass whichClassIncludesSelector:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1758
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1759
        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
  1760
        implClass size == 1 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1761
            implClass := implClass first.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1762
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1763
            implClass := nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1764
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1765
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1766
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1767
    info := best storeString.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1768
    implClass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1769
        info := implClass name , ' >> ' , info.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1770
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1771
    self information:info.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1772
].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1773
    editAction := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1774
        [:index |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1775
            |best|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1776
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1777
            best := allBest at:index.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1778
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1779
            best ~= selector ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1780
                numArgs := best numArgs.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1781
                (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1782
                    selectorParts := parentNode selectorParts , node selectorParts.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1783
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1784
                    selectorParts := node selectorParts.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1785
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1786
                nSelParts := selectorParts size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1787
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1788
                newParts := best asCollectionOfSubstringsSeparatedBy:$:.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1789
                newParts := newParts select:[:part | part size > 0].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1790
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1791
                codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1792
                    undoableDo:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1793
                        |newCursorPosition stop|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1794
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1795
                        numArgs > nSelParts ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1796
                            stop := selectorParts last stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1797
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1798
                            "/ append the rest ...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1799
                            numArgs downTo:nSelParts+1 do:[:idx |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1800
                                |newPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1801
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1802
                                newPart := newParts at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1803
                                (best endsWith:$:) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1804
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1805
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1806
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1807
                                (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1808
                                    newPart := ':' , newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1809
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1810
                                newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1811
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1812
                                codeView replaceFromCharacterPosition:stop to:stop with:newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1813
                                newCursorPosition := stop + newPart size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1814
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1815
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1816
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1817
                        (nSelParts min:newParts size) downTo:1 do:[:idx |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1818
                            |newPart oldPartialToken start stop|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1819
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1820
                            newPart := newParts at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1821
                            oldPartialToken := selectorParts at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1822
                            start := oldPartialToken start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1823
                            stop := oldPartialToken stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1824
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1825
                            (best endsWith:$:) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1826
                                (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1827
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1828
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1829
                            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1830
                                (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1831
                                    newPart := newPart , ':'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1832
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1833
                                    (codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1834
                                        newPart := newPart , ' '
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1835
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1836
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1837
        "/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1838
        "/                        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1839
        "/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1840
                            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1841
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1842
                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1843
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1844
                            oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1845
                            newLen := newPart size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1846
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1847
                            "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1848
                            newCursorPosition := stop + (newLen-oldLen).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1849
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1850
                        codeView cursorToCharacterPosition:newCursorPosition.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1851
                        codeView cursorRight.  "/ avoid going to the next line !!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1852
                        codeView dontReplaceSelectionOnInput.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1853
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1854
                info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1855
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1856
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1857
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1858
    actionBlock value:allBest value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1859
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1860
    "Created: / 10-11-2006 / 13:18:27 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1861
    "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
  1862
    "Modified: / 27-07-2013 / 16:34:10 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1863
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1864
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1865
codeCompletionForMethodSpec:node 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1866
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1867
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1868
    self 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1869
        codeCompletionForMethodSpec:node
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1870
        into:
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1871
            [:suggestions :action :whatIsIt |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1872
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1873
            |chosen|
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
            chosen := self askUserForCompletion:whatIsIt for:codeView at:node start from:suggestions.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1876
            action value:(suggestions indexOf:chosen)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1877
        ].
4352
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
"/    |crsrPos
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1880
"/     selectorSoFar matchingSelectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1881
"/     selectors distances best rest 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1882
"/     allExistingMethods nameBag namesByCount selectors1 selectors2|  
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1883
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1884
"/    crsrPos := codeView characterPositionOfCursor - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1885
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1886
"/    selectorSoFar := ''.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1887
"/    node selectorParts doWithIndex:[:partToken :argNr|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1888
"/        |part|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1889
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1890
"/        part := partToken value.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1891
"/        selectorSoFar := selectorSoFar , part.
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
"/        (crsrPos >= partToken start
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1894
"/        and:[crsrPos <= partToken stop]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1895
"/            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1896
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1897
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1898
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1899
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1900
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1901
"/                                        md := eachClass theMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1902
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1903
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1904
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1905
"/                "/ dont forget the stuff in the class-line
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1906
"/                Metaclass withAllSuperclassesDo:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1907
"/                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1908
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1909
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1910
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1911
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1912
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1913
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1914
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1915
"/                                        md := eachClass theNonMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1916
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1917
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1918
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1919
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1920
"/            selectors := matchingSelectors asOrderedCollection.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1921
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1922
"/            "/ 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
  1923
"/            (selectors size == 1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1924
"/            and:[selectors first = selectorSoFar]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1925
"/                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1926
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1927
"/                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1928
"/                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1929
"/                nameBag := Bag new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1930
"/                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1931
"/                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1932
"/                "/ take the one which occurs most often     
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1933
"/                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
  1934
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1935
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1936
"/                    undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1937
"/                        (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1938
"/                            codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1939
"/                        ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1940
"/                            codeView insertString:best atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1941
"/                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1942
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1943
"/                    info:'completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1944
"/                codeView cursorToCharacterPosition:(crsrPos + best size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1945
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1946
"/                "the ones implemented in superclasses are shown first"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1947
"/                classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1948
"/                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1949
"/                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1950
"/                ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1951
"/                    selectors1 := selectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1952
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1953
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1954
"/                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1955
"/                distances sortWith:selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1956
"/                selectors1 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1957
"/                selectors := selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1958
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1959
"/                selectors2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1960
"/                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1961
"/                    distances sortWith:selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1962
"/                    selectors2 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1963
"/                    selectors1 := selectors1 collect:[:sel | sel allBold].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1964
"/                    selectors := selectors1,selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1965
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1966
"/                
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1967
"/                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1968
"/                best isNil ifTrue:[^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1969
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1970
"/                rest := best copyFrom:selectorSoFar size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1971
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1972
"/                    undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1973
"/                        codeView 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1974
"/                            replaceFromCharacterPosition:crsrPos+1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1975
"/                            to:crsrPos+1 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1976
"/                            with:rest 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1977
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1978
"/                    info:'Completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1979
"/                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1980
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1981
"/            codeView cursorRight. "/ kludge to make it visible   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1982
"/        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1983
"/    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1984
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1985
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1986
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1987
    "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
  1988
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1989
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1990
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1991
codeCompletionForMethodSpec:node into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1992
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1993
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1994
    |crsrPos
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1995
     selectorSoFar matchingSelectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1996
     selectors distances best rest 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1997
     allExistingMethods nameBag namesByCount selectors1 selectors2 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1998
     editAction argNames|  
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1999
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  2000
    "/ Transcript showCR:'m'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2001
    crsrPos := codeView characterPositionOfCursor - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2002
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2003
    selectorSoFar := ''.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2004
    node selectorParts doWithIndex:[:partToken :argNr|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2005
        |part|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2006
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2007
        part := partToken value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2008
        selectorSoFar := selectorSoFar , part.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2009
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2010
        (crsrPos >= partToken start
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2011
        and:[crsrPos <= partToken stop]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2012
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2013
                matchingSelectors := Smalltalk allClasses
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2014
                                    inject:(Set new)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2015
                                    into:[:theSet :eachClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2016
                                        |md|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2017
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2018
                                        md := eachClass theMetaclass methodDictionary.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2019
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2020
                                        theSet.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2021
                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2022
                "/ dont forget the stuff in the class-line
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2023
                Metaclass withAllSuperclassesDo:[:cls |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2024
                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2025
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2026
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2027
                matchingSelectors := Smalltalk allClasses
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2028
                                    inject:(Set new)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2029
                                    into:[:theSet :eachClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2030
                                        |md|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2031
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2032
                                        md := eachClass theNonMetaclass methodDictionary.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2033
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2034
                                        theSet.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2035
                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2036
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2037
            selectors := matchingSelectors asOrderedCollection.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2038
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2039
            "/ 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
  2040
            (selectors size == 1 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2041
            and:[selectors first = selectorSoFar]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2042
                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2043
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2044
                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2045
                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2046
                nameBag := Bag new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2047
                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2048
                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2049
                "/ take the one which occurs most often     
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2050
                "/ 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
  2051
                argNames := (namesByCount collect:[:a | a key]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2052
                editAction :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2053
                        [:chosenIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2054
                            |chosenName|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2055
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2056
                            chosenName := argNames at:chosenIndex.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2057
                            codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2058
                                undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2059
                                    (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2060
                                        codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2061
                                    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2062
                                        codeView insertString:chosenName atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2063
                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2064
                                    codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1).    
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2065
                                ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2066
                                info:'completion'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2067
                        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2068
                actionBlock 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2069
                    value:argNames 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2070
                    value:editAction
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2071
                    value:'argument'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2072
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2073
                ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2074
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2075
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2076
                "the ones implemented in superclasses are shown first"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2077
                classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2078
                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2079
                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2080
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2081
                    selectors1 := selectors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2082
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2083
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2084
                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2085
                distances sortWith:selectors1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2086
                selectors1 reverse.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2087
                selectors := selectors1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2088
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2089
                selectors2 notEmptyOrNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2090
                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2091
                    distances sortWith:selectors2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2092
                    selectors2 reverse.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2093
                    selectors1 := selectors1 collect:[:sel | sel allBold].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2094
                    selectors := selectors1,selectors2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2095
                ].
4350
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2096
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2097
                editAction := 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2098
                    [:selectedCompletionIndex |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2099
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2100
                        best := selectors at:selectedCompletionIndex.
4350
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2101
                        rest := best copyFrom:selectorSoFar size.
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2102
                        codeView
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2103
                            undoableDo:[ 
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2104
                                codeView 
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2105
                                    replaceFromCharacterPosition:crsrPos+1 
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2106
                                    to:crsrPos+1 
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2107
                                    with:rest 
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2108
                            ]
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2109
                            info:'Completion'.
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2110
                        codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2111
                        codeView cursorRight. "/ kludge to make it visible   
8771e73d16bb class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4349
diff changeset
  2112
                    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2113
                
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2114
                "/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2115
                actionBlock 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2116
                    value:selectors 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2117
                    value:editAction
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2118
                    value:'selector'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2119
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2120
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2121
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2122
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2123
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2124
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2125
    "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
  2126
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2127
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2128
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2129
codeCompletionForVariable:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2130
    |nonMetaClass crsrPos nm parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2131
     allVariables allDistances variablesAlreadyAdded nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2132
     char oldLen newLen 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2133
     getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2134
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2135
     editAction suggestions nameIsOK longerNames|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2136
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  2137
    "/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2138
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2139
        nonMetaClass := classOrNil theNonMetaclass.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2140
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2141
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2142
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2143
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2144
    "/ 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
  2145
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2146
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2147
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2148
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2149
    char isSeparator ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2150
        nm knownAsSymbol ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2151
            classOrNil isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2152
                nodeVal := Smalltalk at:nm asSymbol.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2153
            ] ifFalse:[ 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2154
                nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2155
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2156
            nodeVal isBehavior ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2157
                |methods menu exitKey idx|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2158
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2159
                methods := nodeVal class methodDictionary values
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2160
                                select:[:m | |cat|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2161
                                    cat := m category asLowercase.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2162
                                    cat = 'instance creation'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2163
                                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2164
                editAction :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2165
                    [:answer |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2166
                        codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2167
                            undoableDo:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2168
                                codeView insertString:answer atCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2169
                                codeView cursorToCharacterPosition:crsrPos+answer size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2170
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2171
                            info:'completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2172
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2173
                actionBlock value:(methods collect:[:each | each selector]) value:editAction.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2174
                ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2175
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2176
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2177
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2178
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2179
    parent := node parent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2180
    (parent notNil and:[parent isMessage]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2181
        node == parent receiver ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2182
            selectorOfMessageToNode := parent selector
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2183
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2184
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2185
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2186
    "/ this is pure voodoo magic (tries to make a good spelling weight,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2187
    "/ by weighting the number of startsWith characters into the spelling distance...)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2188
    getDistanceComputeBlockWithWeight :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2189
        [:weight |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2190
            [:each |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2191
                |dist factor|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2192
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2193
                dist := each spellAgainst:nm.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2194
                factor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2195
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2196
                (each startsWith:nm) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2197
                    factor := 6 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2198
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2199
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2200
                        factor := 4 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2201
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2202
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2203
                dist := dist + (weight*factor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2204
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2205
                each -> (dist * weight)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2206
             ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2207
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2208
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2209
    nameIsOK := false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2210
    addWithFactorBlock :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2211
        [:names :factor | |namesToAdd|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2212
            (names includes:nm) ifTrue:[nameIsOK := true].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2213
            namesToAdd := names reject:[:nameToAdd | (nameToAdd = nm)].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2214
            namesToAdd := namesToAdd reject:[:each | variablesAlreadyAdded includes:each ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2215
            variablesAlreadyAdded addAll:namesToAdd.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2216
            allVariables addAll:namesToAdd.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2217
            allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2220
    nm isUppercaseFirst ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2221
        globalFactor := 2.    "/ favour globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2222
        localFactor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2223
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2224
        globalFactor := 1.    "/ favour locals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2225
        localFactor := 2.
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2228
    variablesAlreadyAdded := Set new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2229
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2230
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2231
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2232
    "/ are we in the method's selector spec ?
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2233
    (parent notNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2234
    and:[parent isMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2235
    and:[parent arguments includes:node]]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2236
        "/ 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
  2237
        "/ of this method, and take that as a basis of the selection
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2239
        implementors := SystemBrowser 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2240
                            findImplementorsOf:(parent selector) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2241
                            in:(Smalltalk allClasses)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2242
                            ignoreCase:false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2243
        "/ which argument is it
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2244
        argIdx := parent arguments indexOf:node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2245
        implementors size > 50 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2246
            implementors := implementors asOrderedCollection copyTo:50.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2247
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2248
        namesUsed := implementors 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2249
                        collect:[:eachImplementor |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2250
                            |parseTree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2251
                            parseTree := eachImplementor parseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2252
                            (parseTree notNil and:[parseTree arguments size > 0]) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2253
                                ifFalse:nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2254
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2255
                        thenSelect:[:a | a notNil].  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2256
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2257
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2258
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2259
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2260
            "/ also, look for the keyword before the argument, 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2261
            "/ and see if there is such an instVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2262
            "/ if so, add it with -Arg
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2263
            parent selector isKeyword ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2264
                kwPart := parent selector keywords at:argIdx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2265
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2266
                    addWithFactorBlock 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2267
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2268
                        value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2269
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2270
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2271
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2272
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2273
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2274
            "/ locals in the block/method
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2275
            names := node allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2276
            "/ if there were no variables (due to a parse error)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2277
            "/ do another parse and see what we have
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2278
            names isEmpty ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2279
                tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2280
                "/ better if we already have a body (include locals then)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2281
                "/ otherwise, only the arguments are considered
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2282
                tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2283
                    names := (tree body ? tree) allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2284
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2285
            ].
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
            addWithFactorBlock value:names value:(4 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2288
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2289
            "/ instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2290
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
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
            "/ inherited instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2293
            classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2294
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2295
            ].
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2298
        selectorOfMessageToNode notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2299
            |names responders nonResponders|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2300
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2301
            "/ responding to that messsage
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
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2304
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2305
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2306
                                   value:(1.75 * globalFactor).
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
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2309
                names := nonMetaClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2310
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2311
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2312
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2313
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2314
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2315
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2316
                "/ superclass var names
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2317
                nonMetaClass allSuperclassesDo:[:superClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2318
                    names := superClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2319
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2320
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2321
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2322
                    addWithFactorBlock value:responders value:(1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2323
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2326
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2327
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2328
                    names := classOrNil topNameSpace keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2329
                    names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2330
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2331
                    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
  2332
                    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
  2333
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2334
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2335
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2336
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2337
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2338
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2339
            names := Smalltalk keys.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2340
            names := names reject:
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2341
                            [:nm | 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2342
                                (nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2343
                            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2344
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2345
            names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2346
            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
  2347
            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
  2348
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2349
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2350
4314
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2351
            classOrNil notNil ifTrue:[
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2352
                "/ pool variables
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2353
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2354
                    |pool names|
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2355
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2356
                    pool := Smalltalk at:poolName.
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2357
                    names := pool classVarNames.
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2358
                    names := names select:[:nm | nm isUppercaseFirst ].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2359
                    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
  2360
                    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
  2361
                    addWithFactorBlock value:responders value:(2.5 * globalFactor).
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2362
                    addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2363
                ].
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  2364
            ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2365
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2366
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2367
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2368
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2369
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2370
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2371
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2372
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2373
                classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2374
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2375
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2376
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2377
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2378
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2379
                    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
  2380
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2381
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2382
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2383
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2384
                "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2385
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2386
                    |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2387
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2388
                    pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2389
                    names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2390
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2391
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2392
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2393
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2394
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2395
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2396
            names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2397
            addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2398
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2399
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2400
        "/ pseudos - assuming that thisContext is seldom used.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2401
        "/ also assuming, that nil is short so its usually typed in.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2402
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2403
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2404
        addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2405
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2406
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2407
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2408
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2409
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2410
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2411
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2412
                                                           ifTrue:[el]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2413
                                                           ifFalse:[best]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2414
                                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2415
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2416
    allDistances sort:[:a :b | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2417
                                a value > b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2418
                                    true
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2419
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2420
                                    a value = b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2421
                                        a key < b key
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2422
                                    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2423
                                        false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2424
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2425
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2426
                      ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2427
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2428
    allTheBest := allDistances.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2429
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2430
    nameIsOK ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2431
        "/ if the name already exists, only allow longer names, if there are
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2432
        longerNames := allTheBest select:[:assoc | assoc key startsWith:nm].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2433
        longerNames notEmpty ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2434
            allTheBest := longerNames.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2435
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2436
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2437
    allTheBest size > 15 ifTrue:[
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2438
        "/ remove all those which are below some threshold
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2439
        0.4 to:0.8 by:0.1 do:[:delta |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2440
            "/ if still too many, remove more and more
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2441
            allTheBest size > 15 ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2442
                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
  2443
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2444
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2445
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2446
    suggestions := allTheBest collect:[:assoc | assoc key].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2447
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2448
    "/ finally, the trick is to bring them into a reasonable order...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2449
    "/ sort the prefix matchers by length, the others by spelling distance
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2450
    "/ and bring the prefix-matchers towards the beginning
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2451
    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
  2452
                   ,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2453
                   (suggestions reject:[:s | s startsWith:nm]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2454
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2455
    editAction :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2456
        [:index |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2457
            |answer start stop oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2458
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2459
            answer := suggestions at:index.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2460
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2461
            start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2462
            stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2463
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2464
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2465
            oldLen := stop - start + 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2466
            newLen := answer size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2467
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2468
            codeView
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2469
                undoableDo:[ 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2470
                    codeView replaceFromCharacterPosition:start to:stop with:(answer).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2471
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2472
                    (answer startsWith:oldVar) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2473
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2474
                        codeView dontReplaceSelectionOnInput
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2475
                    ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2476
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2477
                        codeView dontReplaceSelectionOnInput
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2478
                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2479
                ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2480
                info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2481
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2482
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2483
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2484
    actionBlock value:suggestions value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2485
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2486
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2487
    "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
  2488
    "Modified: / 30-07-2013 / 08:36:11 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2489
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2490
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2491
findNodeForInterval:interval in:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2492
    |tree node|
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
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2495
    RBParser isNil ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2496
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2497
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2498
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2499
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2500
        tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2501
                parseMethod:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2502
                onError: 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2503
                    [:str :err ":nodesSoFar" | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2504
                        "Transcript showCR:'Parse-Error: ',str." 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2505
                        nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2506
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2507
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2508
        tree isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2509
            "/ try to parse as an expression
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2510
            tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2511
                    parseExpression:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2512
                    onError: 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2513
                        [:str :err ":nodesSoFar" | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2514
                            "Transcript showCR:'Parse-Error: ',str." 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2515
                            nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2516
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2517
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2518
            tree isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2519
                ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2520
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2521
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2522
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2523
        LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2524
        LastParseTree := tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2525
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2526
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2527
    node := tree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2528
    node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2529
        node := tree bestNodeFor: interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2530
        node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2531
            node := self findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2532
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2533
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2534
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2535
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2536
    "Modified: / 06-07-2011 / 12:42:53 / cg"
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2539
findNodeForInterval:interval in:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2540
    ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2541
        findNodeForInterval:interval in:source allowErrors:allowErrors  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2542
        mustBeMethod:false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2543
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2544
    "Modified: / 16-09-2011 / 14:52:28 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2545
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2546
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2547
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2548
    "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
  2549
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2550
    ^ self
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2551
        findNodeForInterval:interval in:source allowErrors:allowErrors 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2552
        mustBeMethod:mustBeMethod mustBeExpression:false
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2553
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2554
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2555
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2556
    "parse it as expression or method;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2557
     if mustBeMethod is true, do not try a regular expressions (as in a workspace);
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2558
     if musBeExpression is true, do not try method"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2559
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2560
    |intersectingNodes smallestIntersectingNode firstIntersectingNode onErrorBlock nodeGenerationHook parser|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2561
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2562
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2563
    RBParser isNil ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2564
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2565
    "/ LastSource := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2566
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2567
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2568
        tokens := LastScanTokens.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2569
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2570
        intersectingNodes := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2571
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2572
        onErrorBlock := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2573
            [:str :err :nodesSoFar |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2574
                |nodes|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2575
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2576
                allowErrors ifTrue:[
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  2577
                    firstIntersectingNode notNil ifTrue:[
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  2578
                        ^ firstIntersectingNode
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  2579
                    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2580
                    nodesSoFar notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2581
                        nodes := nodesSoFar asOrderedCollection
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2582
                                    collect:[:nd | nd whichNodeIntersects:interval]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2583
                                    thenSelect:[:nd | nd notNil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2584
                        nodes size == 1 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2585
                            ^ nodes first
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2586
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2587
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2588
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2589
                nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2590
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2591
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2592
        nodeGenerationHook := 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2593
            [:node |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2594
                "/ 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
  2595
                "/ 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
  2596
                "/ what the semantic interpretation (especially: scope of variable) will be.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2597
                "/ therefore, we parse all, and return the found node at the end.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2598
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2599
                (node intersectsInterval:interval) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2600
                    intersectingNodes add:node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2601
                    firstIntersectingNode isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2602
                        firstIntersectingNode := smallestIntersectingNode := node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2603
                    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2604
                        |lenNode lenSmallest|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2605
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2606
                        lenNode := (node stop - node start).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2607
                        lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2608
                        lenNode < lenSmallest ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2609
                            smallestIntersectingNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2610
                        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2611
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2612
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2613
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2614
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2615
        mustBeExpression ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2616
            tree := RBParser
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2617
                        parseMethod: source 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2618
                        setup:[:p | 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2619
                            parser := p.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2620
                            p rememberNodes:true.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2621
                            p rememberTokens:true.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2622
                            p nodeGenerationCallback:nodeGenerationHook
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2623
                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2624
                        onError: onErrorBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2625
            parser notNil ifTrue:[ tokens := parser rememberedTokens ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2626
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2627
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2628
        mustBeMethod ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2629
            "/ only cache parsed methods
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2630
            tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2631
                LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2632
                LastParseTree := tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2633
                LastScanTokens := tokens.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2634
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2635
        ] ifFalse:[    
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2636
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2637
                "/ try as an expression
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2638
                tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2639
                            parseExpression: source 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2640
                            setup:[:p |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2641
                                parser := p.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2642
                                p rememberNodes:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2643
                                p rememberTokens:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2644
                                p nodeGenerationCallback:nodeGenerationHook
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2645
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2646
                            onError: onErrorBlock.
4276
5f4dca44baed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
  2647
                parser notNil ifTrue:[ tokens := parser rememberedTokens ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2648
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2649
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2650
        firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2651
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2652
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2653
    ^ self findNodeForInterval:interval inParseTree:tree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2654
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2655
    "Created: / 16-09-2011 / 14:52:08 / cg"
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
findNodeForInterval:interval inParseTree:parseTree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2659
    |node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2660
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2661
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2662
    parseTree isNil ifTrue:[^ nil].
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
    node := parseTree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2665
    node isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2666
        node := parseTree whichNodeIntersects:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2667
        node isNil ifTrue: [
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2668
            node := self findNodeIn:parseTree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2669
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2670
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2671
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2672
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2673
    "Modified: / 10-11-2006 / 13:13:58 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2674
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2675
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2676
findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2677
    |nodeFound wouldReturn|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2678
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2679
    nodeFound := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2680
    tree nodesDo:[:eachNode |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2681
        (eachNode intersectsInterval:interval) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2682
            (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2683
                nodeFound := eachNode
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2684
            ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2685
                (nodeFound parent == eachNode parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2686
                and:[ eachNode start >= nodeFound start
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2687
                      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2688
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2689
                    (nodeFound parent notNil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2690
                    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
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
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2693
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2694
            nodeFound notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2695
                "/ already found one - beyond that one; leave
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2696
                wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2697
            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2698
        ].
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
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2701
    ^ nodeFound
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2702
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2703
    "Modified: / 20-11-2006 / 12:31:12 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2704
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2705
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2706
lookupClassForMessage:node inClass:classProvidingNamespaceOrNil
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2707
    ^  self lookupClassForMessage:node inClass:classProvidingNamespaceOrNil instance:nil
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2708
!
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2709
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2710
lookupClassForMessage:node inClass:classProvidingNamespaceOrNil instance:instanceOrNil
4344
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  2711
    ^ self 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2712
        lookupClassForMessage:node inClass:classProvidingNamespaceOrNil instance:instanceOrNil context:nil
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2713
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2714
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2715
lookupClassForMessage:node inClass:classProvidingNamespaceOrNil instance:instanceOrNil context:contextOrNil
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2716
    |receiver|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2717
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2718
    receiver := node receiver.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2719
    ^ self 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2720
        classOfReceiver:receiver 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2721
        inClass:classProvidingNamespaceOrNil instance:instanceOrNil context:contextOrNil
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2722
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2723
    "Modified: / 24-08-2010 / 15:05:49 / sr"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2724
    "Modified: / 28-08-2013 / 16:35:27 / cg"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2725
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2726
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2727
old_askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2728
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2729
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2730
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2731
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2732
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2733
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2734
    LastChoices notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2735
        lastChoice := LastChoices at:what ifAbsent:nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2736
        lastChoice notNil ifTrue:[
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  2737
            "/ 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
  2738
            (list includes: lastChoice) ifTrue:[
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  2739
                (list indexOf: lastChoice) < 10 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  2740
                    list := {lastChoice allBold } , (list copyWithout:lastChoice).
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  2741
                ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2742
            ]
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
    ].
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
    list size < 30 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2747
        |menu idx exitKey|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2748
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2749
        menu := PopUpMenu labels:list.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2750
        menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2751
                hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2752
                hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2753
                    exitKey := key.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2754
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2755
                hide].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2756
        menu memorizeLastSelection:3 "sigh, not 1 because of heading!!".
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2757
        idx := menu startUpWithHeading:'Choose ',what.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2758
        idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2759
            exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2760
                codeView keyPress:exitKey x:0 y:0.
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
            ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2763
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2764
        choice := list at:idx.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2765
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2766
        resources := codeView application isNil 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2767
                        ifTrue:[ codeView resources]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2768
                        ifFalse:[ codeView application resources ].
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
        choice := Dialog
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2771
           choose:(resources string:'Choose ',what)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2772
           fromList:list
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2773
           lines:20
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2774
           initialSelection:(list firstIfEmpty:nil)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2775
           title:(resources string:'Code completion').
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2776
        choice isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2777
    ].
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  2778
    choice := choice string.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2779
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2780
    LastChoices isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2781
        LastChoices := Dictionary new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2782
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2783
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2784
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2785
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2786
    "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
  2787
    "Modified: / 28-08-2013 / 15:28:01 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2788
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2789
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2790
treeForCode:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2791
    |tree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2792
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2793
    source = LastSource ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2794
        tree := LastParseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2795
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2796
        tree := RBParser
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2797
                parseMethod:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2798
                onError: [:str :err :nodesSoFar :parserOrNil|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2799
                        allowErrors ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2800
                            "/ parserOrNil isNil if raised by the scanner
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2801
                            parserOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2802
                                ^ parserOrNil currentMethodNode
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2803
                            ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2804
                        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2805
                        ^ nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2806
                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2807
                proceedAfterError:false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2808
                rememberNodes:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2809
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2810
        tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2811
            LastSource := source.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2812
            LastParseTree := tree.
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
    ^ tree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2816
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2817
    "Modified: / 13-01-2012 / 11:54:30 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2818
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2819
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2820
tryCodeCompletionWithSource:source nodeInterval:interval into:actionBlock
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2821
    "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
  2822
     then with the full source.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2823
     Either one may geive better results (for example, when completing
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2824
     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
  2825
     legal, but stupid message send to be parsed...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2826
     (which happens often after inserting)"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2827
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2828
    |node checkedNode characterBeforeCursor nodeIsInTemporaries|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2829
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2830
    "/ this is too naive and stupid; if there is a syntactic error,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2831
    "/ 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
  2832
    "/ 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
  2833
    "/ without any progress.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2834
    "/ 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
  2835
    "/ as it parses the code. Stop, when the interval is hit.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2836
    "/ that will also work for syntactic incorrect source code.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2837
    classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2838
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2839
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2840
    node isNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2841
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true.   
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2842
        node isNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2843
            Transcript showCR:'No parseNode found (syntax error before?)'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2844
            self information:'No parseNode found (syntax error before?)'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2845
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2846
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2847
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2848
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2849
    (node isVariable
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2850
    and:[ node parent notNil
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2851
    and:[ node parent isMessage
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2852
    and:[ node stop < (codeView characterPositionOfCursor-1) ]]]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2853
        node := node parent.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2854
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2855
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2856
    characterBeforeCursor := codeView characterBeforeCursor.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2857
    characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2858
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2859
    node isVariable ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2860
        nodeIsInTemporaries :=
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2861
            node parent notNil 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2862
            and:[ node parent isSequence 
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2863
            and:[ node parent temporaries notEmptyOrNil
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2864
            and:[ node stop <= node parent temporaries last stop ]]].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2865
        nodeIsInTemporaries ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2866
            "/ cursor must be right after the variable
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2867
            codeView characterPositionOfCursor == (node stop + 1) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2868
                self codeCompletionForVariable:node into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2869
            ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2870
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2871
        ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2872
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2873
    node isLiteral ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2874
        "/ cursor must bew right after the literal
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2875
        codeView characterPositionOfCursor == (node stop + 1) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2876
            node value isSymbol ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2877
                self codeCompletionForLiteralSymbol:node into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2878
                ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2879
            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2880
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2881
        ^ self "/ huh - strings or what?
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2882
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2883
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2884
    checkedNode := node.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2885
    [checkedNode notNil] whileTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2886
        (codeView characterPositionOfCursor < checkedNode stop) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2887
            self information:'Inside a message node'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2888
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2889
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2890
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2891
        checkedNode isMessage ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2892
            "/ completion in a message-send
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2893
            self codeCompletionForMessage:checkedNode into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2894
            ^ self
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2895
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2896
        checkedNode isMethod ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2897
            "/ completion in a method's selector pattern
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2898
            self codeCompletionForMethodSpec:checkedNode into:actionBlock.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2899
            ^ self.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2900
        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2901
        checkedNode := checkedNode parent.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2902
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2903
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2904
    self information:'Node is neither variable nor message.'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2905
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2906
    "Modified: / 04-07-2006 / 18:48:26 / fm"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2907
    "Modified: / 16-09-2011 / 14:54:47 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2908
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2909
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2910
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2911
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2912
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2913
    |sym possibleCompletions best start stop oldLen newLen oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2914
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2915
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2916
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2917
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2918
    Symbol allInstancesDo:[:existingSym |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2919
        (existingSym startsWith:sym) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2920
            (existingSym = sym) ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2921
                possibleCompletions add:existingSym
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2922
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2923
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2924
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2925
    possibleCompletions sort.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2926
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2927
    best := possibleCompletions longestCommonPrefix.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2928
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2929
        best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2930
        best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2931
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2932
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2933
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2934
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2935
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2936
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2937
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2938
        start := start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2939
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2940
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2941
        start := start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2942
        stop := stop - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2943
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2944
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2945
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
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
    codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2948
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2949
        info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2950
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2951
    (best startsWith:oldVar) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2952
        oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2953
        newLen := best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2954
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2955
        codeView dontReplaceSelectionOnInput
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2956
    ].
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
    "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
  2959
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2960
!
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
codeCompletionForMessage:node inClass:classOrNil codeView:codeView
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2963
    ^ self codeCompletionForMessage:node inClass:classOrNil instance:nil codeView:codeView
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2964
!
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2965
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  2966
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil codeView:codeView
4344
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  2967
    ^  self 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  2968
        codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil 
00f41f79e151 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4341
diff changeset
  2969
        context:nil codeView:codeView
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2970
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2971
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2972
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2973
    |selector srchClass implClass 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2974
     bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best info numArgs
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2975
     newParts nSelParts oldLen newLen selectorParts 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2976
     findBest parentNode selectorInBest selector2InBest2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2977
     parser selectorsSentInCode selectorsImplementedInClass split 
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  2978
     varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2979
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2980
    RefactoryTyper notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2981
        "/ refactory package also provides a (very limited) typer;
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2982
        "/ 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
  2983
        (node receiver isVariable) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2984
            varName := node receiver name.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2985
            varName isUppercaseFirst ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2986
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2987
                tree := RBParser 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2988
                            parseMethod:codeView contents string
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2989
                            onError:[:aString :pos | nil].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2990
                tree notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2991
                    rbTypes := RefactoryTyper 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2992
                                classesFor: varName
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2993
                                in: tree
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2994
                                model: nil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2995
                                ignoredSelectors:(Array with:node selector).     
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2996
                    rbTypes size > 0 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2997
                        rbTypes size > 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2998
                            rbTypes remove:ProtoObject ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  2999
                            rbTypes remove:Autoload ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3000
                            rbTypes remove:ObsoleteObject ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3001
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3002
                        rbTypes size == 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3003
                            rbType := rbTypes first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3004
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3005
                            rbType := Class commonSuperclassOf:rbTypes
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3006
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3007
                        (rbType notNil "and:[rbType ~= Object]") ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3008
                            bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3009
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3010
                    ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3011
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3012
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3013
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3014
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3015
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3016
    classOrNil notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3017
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3018
        selectorsSentInCode := parser messagesSent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3019
    ].                                  
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3020
    classOrNil notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3021
        selectorsImplementedInClass := classOrNil selectors.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3022
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3023
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3024
    findBest := [:node :selector |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3025
        |srchClass bestSelectors bestPrefixes|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3026
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3027
        codeView topView withCursor:(Cursor questionMark) do:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3028
            srchClass := self lookupClassForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3029
            srchClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3030
                bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3031
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3032
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3033
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3034
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3035
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3036
        (bestSelectors includes:selector) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3037
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3038
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3039
        bestSelectors
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3040
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3041
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3042
    selector := node selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3043
    bestSelectors := findBest value:node value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3044
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3045
    parentNode := node parent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3046
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3047
    parentIsKeywordMessage :=
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3048
        (parentNode notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3049
            and:[ parentNode isMessage 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3050
            and:[ parentNode selector isKeywordSelector]]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3051
    parentIsBinaryMessage :=
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3052
        (parentNode notNil 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3053
            and:[ parentNode isMessage 
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3054
            and:[ parentNode selector isBinarySelector]]).
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3055
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3056
    tryParent := false.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3057
    "/ 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
  3058
    (node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[ 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3059
        tryParent := true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3060
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3061
        "/ 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
  3062
        (node isMessage
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3063
        and:[ node receiver isMessage 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3064
        and:[ node receiver receiver isVariable 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3065
        and:[ node receiver receiver name isUppercaseFirst 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3066
        and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3067
            rcvrClass := Smalltalk classNamed:(node receiver receiver name).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3068
            "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3069
            bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3070
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3071
            "/ also, if nothing was found
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3072
            (bestSelectors isEmpty 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3073
            and:[ parentNode notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3074
            and:[ parentNode isMessage ]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3075
                "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3076
                "/ selector2 := parentNode selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3077
                "/ selector2 := selector2,selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3078
                bestSelectors := findBest value:parentNode value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3079
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3080
        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3081
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3082
    tryParent ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3083
        selector2 := parentNode selector,selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3084
        bestSelectors2 := findBest value:parentNode value:selector2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3085
    ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3086
    bestSelectorsFromRB notEmptyOrNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3087
        bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3088
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3089
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3090
    "/ if the parent is a keyword selector, the child cannot
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3091
    (parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3092
        bestSelectors := bestSelectors reject:[:sel | sel isKeywordSelector]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3093
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3094
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3095
    bestSelectors2 isEmptyOrNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3096
        allBest := bestSelectors.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3097
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3098
        bestSelectors isEmptyOrNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3099
            allBest := bestSelectors2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3100
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3101
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3102
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3103
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3104
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3105
                "/ selector2 is more likely
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3106
                allBest := bestSelectors2
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3107
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3108
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3109
                    "/ selector more likely
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3110
                    allBest := bestSelectors
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3111
                ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3112
                    "/ assume same likelyness
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3113
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3114
                    allBest := bestSelectors isEmpty 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3115
                                ifTrue:[ bestSelectors2 ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3116
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3117
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3118
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3119
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3120
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3121
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3122
    allBest isEmptyOrNil ifTrue:[ ^ self ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3123
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3124
    split := 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3125
        [:list :splitHow |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3126
            |part1 part2 all|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3127
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3128
            part1 := list select:splitHow.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3129
            part2 := list reject:splitHow.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3130
            part1 isEmpty ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3131
                all := part2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3132
            ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3133
                part2 isEmpty ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3134
                    all := part1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3135
                ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3136
                    all := part1 , part2.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3137
                ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3138
            ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3139
            all
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3140
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3141
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3142
    selectorsImplementedInClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3143
        "/ 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
  3144
        allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3145
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3146
    selectorsSentInCode notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3147
        "/ 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
  3148
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3149
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3150
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3151
    "/ 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
  3152
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3153
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3154
    best := allBest first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3155
    allBest size > 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3156
        "allBest size < 20 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3157
            |idx|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3158
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3159
            idx := (PopUpMenu labels:allBest) startUp.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3160
            idx == 0 ifTrue:[ ^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3161
            best := allBest at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3162
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3163
            allBest remove:nil ifAbsent:[].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3164
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3165
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3166
        ]."
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3167
        allBest remove:nil ifAbsent:[].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3168
        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
  3169
        best isEmptyOrNil ifTrue:[^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3170
        best = '-' ifTrue:[^ self].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3171
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3172
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3173
false ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3174
    srchClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3175
        implClass := srchClass whichClassIncludesSelector:best.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3176
    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3177
        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
  3178
        implClass size == 1 ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3179
            implClass := implClass first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3180
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3181
            implClass := nil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3182
        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3183
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3184
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3185
    info := best storeString.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3186
    implClass notNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3187
        info := implClass name , ' >> ' , info.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3188
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3189
    self information:info.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3190
].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3191
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3192
    best ~= selector ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3193
        numArgs := best numArgs.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3194
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3195
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3196
            selectorParts := parentNode selectorParts , node selectorParts.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3197
        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3198
            selectorParts := node selectorParts.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3199
        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3200
        nSelParts := selectorParts size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3201
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3202
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3203
        newParts := newParts select:[:part | part size > 0].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3204
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3205
        codeView
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3206
            undoableDo:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3207
                |newCursorPosition stop|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3208
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3209
                numArgs > nSelParts ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3210
                    stop := selectorParts last stop.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3211
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3212
                    "/ append the rest ...
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3213
                    numArgs downTo:nSelParts+1 do:[:idx |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3214
                        |newPart|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3215
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3216
                        newPart := newParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3217
                        (best endsWith:$:) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3218
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3219
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3220
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3221
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3222
                            newPart := ':' , newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3223
                        ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3224
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3225
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3226
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3227
                        newCursorPosition := stop + newPart size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3228
                    ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3229
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3230
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3231
                (nSelParts min:newParts size) downTo:1 do:[:idx |
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3232
                    |newPart oldPartialToken start stop|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3233
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3234
                    newPart := newParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3235
                    oldPartialToken := selectorParts at:idx.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3236
                    start := oldPartialToken start.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3237
                    stop := oldPartialToken stop.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3238
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3239
                    (best isKeywordSelector) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3240
                        (oldPartialToken value endsWith:$:) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3241
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3242
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3243
                            (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3244
                                newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3245
                            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3246
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3247
                    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3248
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3249
                            newPart := newPart , ':'
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3250
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3251
                            (codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3252
                                (').' includes:(codeView characterAtCharacterPosition:stop+1)) ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3253
                                    newPart := newPart , ' '
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3254
                                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3255
                            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3256
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3257
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3258
"/                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3259
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3260
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3261
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3262
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3263
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3264
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3265
                    newCursorPosition isNil ifTrue:[ 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3266
                        oldLen := stop - start + 1.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3267
                        newLen := newPart size.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3268
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3269
                        newCursorPosition := stop + (newLen-oldLen) 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3270
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3271
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3272
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3273
                codeView cursorToCharacterPosition:newCursorPosition.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3274
                codeView cursorRight.  "/ avoid going to the next line !!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3275
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3276
                ((best endsWith:':') and:[numArgs == 1]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3277
                    |impls impl|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3278
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3279
                    "/ see if it expects a block argument (heuristic)
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3280
                    best := best asSymbol.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3281
                    (node notNil 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3282
                    and:[classOrNil notNil
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3283
                    and:[node receiver isSelf]]) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3284
                        (impl := classOrNil whichClassImplements:best) isNil ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3285
                            impls := #().
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3286
                            Screen current beep.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3287
                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3288
                            impls := { impl }
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3289
                        ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3290
                    ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3291
                        impls := Smalltalk allImplementorsOf:best.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3292
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3293
                    (impls contains:[:cls | 
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3294
                        |argName|
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3295
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3296
                        argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3297
                        (argName includesString:'block') or:[ (argName includesString:'action')]]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3298
                    ) ifTrue:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3299
                        codeView insertStringAtCursor:'['
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3300
                    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3301
                ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3302
                codeView dontReplaceSelectionOnInput.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3303
            ]
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3304
        info:'Completion'.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3305
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3306
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3307
    "Created: / 10-11-2006 / 13:18:27 / cg"
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3308
    "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
  3309
    "Modified: / 28-08-2013 / 15:27:32 / cg"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3310
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  3311
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3312
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3313
    |parent nonMetaClass crsrPos nm
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3314
     allVariables allDistances best nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3315
     char start stop oldLen newLen oldVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3316
     getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3317
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
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
    classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3320
        nonMetaClass := classOrNil theNonMetaclass.
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3323
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3324
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3325
    "/ 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
  3326
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3327
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3328
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3329
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3330
    char isSeparator ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3331
        classOrNil isNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3332
            nodeVal := Smalltalk at:nm asSymbol.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3333
        ] ifFalse:[ 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3334
            nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3335
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3336
        nodeVal isBehavior ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3337
            |methods menu exitKey idx|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3338
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3339
            methods := nodeVal class methodDictionary values
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3340
                            select:[:m | |cat|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3341
                                cat := m category asLowercase.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3342
                                cat = 'instance creation'
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3343
                            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3344
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3345
            menu := PopUpMenu labels:(methods collect:[:each | each selector]).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3346
            menu hideOnKeyFilter:[:key | |hide|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3347
                    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3348
                    hide ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3349
                        exitKey := key.
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
                    hide].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3352
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3353
            idx := menu startUp.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3354
            idx == 0 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3355
                exitKey notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3356
                    codeView keyPress:exitKey x:0 y:0.
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
                ^ self
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3359
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3360
            best := (methods at:idx) selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3361
            codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3362
                undoableDo:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3363
                    codeView insertString:best atCharacterPosition:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3364
                    codeView cursorToCharacterPosition:crsrPos+best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3365
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3366
                info:'completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3367
            ^ self.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3368
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3369
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3370
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3371
    ((parent := node parent) notNil and:[parent isMessage]) ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3372
        node == parent receiver ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3373
            selectorOfMessageToNode := parent selector
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3374
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3375
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3376
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3377
    getDistanceComputeBlockWithWeight :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3378
        [:weight |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3379
            [:each |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3380
                |dist factor|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3381
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3382
                dist := each spellAgainst:nm.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3383
                factor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3384
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3385
                (each startsWith:nm) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3386
                    factor := 6 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3387
                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3388
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3389
                        factor := 4 * nm size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3390
                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3391
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3392
                dist := dist + (weight*factor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3393
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3394
                each -> (dist * weight)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3395
             ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3396
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3397
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3398
    addWithFactorBlock :=
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3399
        [:names :factor | |namesToAdd|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3400
            namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3401
            namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3402
            allVariables addAll:namesToAdd.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3403
            allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3404
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3405
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3406
    nm isUppercaseFirst ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3407
        globalFactor := 2.    "/ favour globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3408
        localFactor := 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3409
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3410
        globalFactor := 1.    "/ favour locals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3411
        localFactor := 2.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3412
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3413
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3414
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3415
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3416
4308
f1c31624744d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4304
diff changeset
  3417
    "/ are we in the method's selector spec ?
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3418
    ((parent := node parent) notNil 
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3419
    and:[parent isMethod
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3420
    and:[parent arguments includes:node]]) ifTrue:[
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3421
        "/ 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
  3422
        "/ of this method, and take that as a basis of the selection
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
        implementors := SystemBrowser 
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3425
                            findImplementorsOf:(parent selector) 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3426
                            in:(Smalltalk allClasses)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3427
                            ignoreCase:false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3428
        "/ which argument is it
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3429
        argIdx := parent arguments indexOf:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3430
        implementors size > 50 ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3431
            implementors := implementors asOrderedCollection copyTo:50.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3432
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3433
        namesUsed := implementors 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3434
                        collect:[:eachImplementor |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3435
                            |parseTree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3436
                            parseTree := eachImplementor parseTree.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3437
                            (parseTree notNil and:[parseTree arguments size > 0]) 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3438
                                ifFalse:nil
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3439
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3440
                        thenSelect:[:a | a notNil] as:Set.  
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3441
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3442
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3443
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3444
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3445
            "/ also, look for the keyword before the argument, 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3446
            "/ and see if there is such an instVar
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3447
            "/ if so, add it with -Arg
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3448
            parent selector isKeyword ifTrue:[
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3449
                kwPart := parent selector keywords at:argIdx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3450
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3451
                    addWithFactorBlock 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3452
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3453
                        value:(1 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3454
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3455
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3456
        ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3457
    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3458
        classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3459
            "/ locals in the block/method
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3460
            names := node allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3461
            "/ if there were no variables (due to a parse error)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3462
            "/ do another parse and see what we have
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3463
            names isEmpty ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3464
                tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3465
                "/ better if we already have a body (include locals then)
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3466
                "/ otherwise, only the arguments are considered
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3467
                tree notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3468
                    names := (tree body ? tree) allVariablesOnScope.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3469
                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3470
            ].
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
            addWithFactorBlock value:names value:(4 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3473
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3474
            "/ instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3475
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3476
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3477
            "/ inherited instance variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3478
            classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3479
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3480
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3481
        ].
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
        selectorOfMessageToNode notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3484
            |names responders nonResponders|
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
            "/ responding to that messsage
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3487
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3488
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3489
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3490
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3491
                                   value:(1.75 * globalFactor).
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
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3494
                names := nonMetaClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3495
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3496
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3497
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3498
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3499
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3500
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3501
                "/ superclass var names
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3502
                nonMetaClass allSuperclassesDo:[:superClass |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3503
                    names := superClass classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3504
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3505
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3506
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3507
                    addWithFactorBlock value:responders value:(1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3508
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3509
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3510
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3511
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3512
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3513
                    names := classOrNil topNameSpace keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3514
                    names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3515
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3516
                    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
  3517
                    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
  3518
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3519
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3520
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3521
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3522
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3523
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3524
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3525
            "/ names := names reject:[:nm | nm includes:$:].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3526
            names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3527
            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
  3528
            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
  3529
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3530
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3531
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3532
            "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3533
            classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3534
                |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3535
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3536
                pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3537
                names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3538
                names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3539
                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
  3540
                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
  3541
                addWithFactorBlock value:responders value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3542
                addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3543
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3544
        ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3545
            classOrNil notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3546
                "/ private classes
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3547
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3548
                                   value:(1.75 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3549
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3550
                "/ class variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3551
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3552
                classOrNil superclass notNil ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3553
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3554
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3555
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3556
                "/ namespace vars
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3557
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3558
                    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
  3559
                    names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3560
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3561
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3562
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3563
                "/ pool variables
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3564
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3565
                    |pool names|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3566
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3567
                    pool := Smalltalk at:poolName.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3568
                    names := pool classVarNames.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3569
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3570
                ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3571
            ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3572
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3573
            "/ globals
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3574
            names := Smalltalk keys.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3575
            names := names select:[:nm | nm isUppercaseFirst ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3576
            addWithFactorBlock value:names value:(1.5 * globalFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3577
        ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3578
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3579
        "/ pseudos - assuming that thisContext is seldom used.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3580
        "/ also assuming, that nil is short so its usually typed in.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3581
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3582
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3583
        addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3584
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3585
        addWithFactorBlock value:#('true') value:(1 * localFactor).
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3586
        addWithFactorBlock value:#('false') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3587
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3588
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3589
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3590
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3591
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3592
                                                           ifTrue:[el]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3593
                                                           ifFalse:[best]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3594
                                                    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3595
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3596
    allDistances sort:[:a :b | 
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3597
                                a value > b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3598
                                    true
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3599
                                ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3600
                                    a value = b value ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3601
                                        a key < b key
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3602
                                    ] ifFalse:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3603
                                        false
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3604
                                    ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3605
                                ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3606
                      ].
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3607
    ((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3608
        allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3609
        allTheBest size > 15 ifTrue:[
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3610
            allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  3611
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3612
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3613
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  3614
    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
  3615
    best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3616
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3617
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3618
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3619
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3620
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3621
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3622
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3623
    codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3624
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3625
        info:'Completion'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3626
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3627
    (best startsWith:oldVar) ifTrue:[
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3628
        oldLen := stop - start + 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3629
        newLen := best size.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3630
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3631
        codeView dontReplaceSelectionOnInput
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3632
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3633
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3634
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3635
    "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
  3636
    "Modified: / 28-08-2013 / 15:37:28 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3637
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3638
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3639
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3640
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3641
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3642
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3643
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3644
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3645
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3646
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3647
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3648
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3649
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3650
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3651
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3652
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3653
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3654
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3655
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3656
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3657
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  3658
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3659
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3660
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  3661
version
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3662
    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.129 2013-08-30 22:54:03 cg Exp $'
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  3663
!
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  3664
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  3665
version_CVS
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3666
    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.129 2013-08-30 22:54:03 cg Exp $'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  3667
! !
4194
e677aae984be Refactoring:
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
  3668