DoWhatIMeanSupport.st
author Claus Gittinger <cg@exept.de>
Mon, 16 May 2016 14:00:00 +0200
changeset 5109 18c01df208c2
parent 5106 5303d78eb69a
child 5112 a25d288252f4
permissions -rw-r--r--
#UI_ENHANCEMENT by cg class: DoWhatIMeanSupport added: #addClassesFromMessagesSentTo:in:to: #addClassesOfBlockVarForWellknownBlocks:inScope:to: removed: #addClassesOfBlockVar:inScope:to: changed:5 methods category of:12 methods
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
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
     3
	      All Rights Reserved
2376
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
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
    14
"{ NameSpace: Smalltalk }"
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
    15
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Object subclass:#DoWhatIMeanSupport
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
    17
	instanceVariableNames:'tree tokens languageOrNil classOrNil methodOrNil contextOrNil
4434
b15ce7d47dd8 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
    18
		instanceOrNil codeView rememberedScopeNodes rememberedNodes
b15ce7d47dd8 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
    19
		codeAspect'
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
    20
	classVariableNames:'LastSource LastParseTree LastScanTokens LastChoices
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
    21
		LastCompletedSelectors Verbose'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	category:'System-Support'
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    26
Array variableSubclass:#InputCompletionResult
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    27
	instanceVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    28
	classVariableNames:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    29
	poolDictionaries:''
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    30
	privateIn:DoWhatIMeanSupport
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    31
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    32
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
copyright
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 COPYRIGHT (c) 2002 by eXept Software AG
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    38
	      All Rights Reserved
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
documentation
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    51
    Attention: this is currently being rewritten and refactored.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    52
    Don't get mad at the ugly (and duplicate) code.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    53
    Will cleanup when finished.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    54
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    misc collected UI support (functional)
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    56
    These used to be in the Smalltalk and SystemBrowser class;
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    57
    however, they are only needed for programmers, and some of the stuff is useful in multiple
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    58
    places.
3667
acb358ca4b0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3660
diff changeset
    59
    Therefore it is:
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    60
	1) not needed for standalone executables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    61
	2) published here to avoid multiple implementations
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    [author:]
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    64
	Claus Gittinger (cg@exept.de)
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    66
"
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    67
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    68
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    69
!DoWhatIMeanSupport class methodsFor:'code completion'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    70
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    71
codeCompletionFor: aspect language: languageOrNil method:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    72
    "aspect is so-called code-aspect symbol saying what's edited - #method, #expression, #classDefinition...
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    73
     contextOrNil is the current context, if this is called from the debugger;
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    74
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    75
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    76
     because we actually know what a variable's type is."
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    77
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    78
    ^ self new
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    79
        codeCompletionFor: aspect
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    80
        language: languageOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    81
        method:methodOrNil orClass:classOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    82
        context:contextOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    83
        codeView:codeView into:actionBlock
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    84
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    85
    "Created: / 27-09-2013 / 10:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    86
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    87
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    88
codeCompletionForLanguage: languageOrNil class: classOrNil context:contextOrNil codeView:codeView
3900
82fa031be815 comment/format in: #codeCompletionForClass:context:codeView:
Claus Gittinger <cg@exept.de>
parents: 3896
diff changeset
    89
    "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
    90
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    91
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    92
     because we actually know what a variable's type is."
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
    93
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    94
    ^ self new
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    95
        codeCompletionForLanguage: languageOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    96
        class:classOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    97
        context:contextOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    98
        codeView:codeView
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    99
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   100
    "Created: / 18-09-2013 / 13:34:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   101
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   102
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   103
!DoWhatIMeanSupport class methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   104
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   105
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   106
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   107
    "contextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   108
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   109
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   110
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   111
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   112
    ^ self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   113
	codeCompletionForLanguage: nil class:classOrNil context:contextOrNil codeView:codeView
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   114
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   115
    "Modified: / 18-09-2013 / 13:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   116
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   117
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   118
codeCompletionForMethod:methodOrNil orClass:classOrNil context:contextOrNil codeView:codeView into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   119
    <resource: #obsolete>
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   120
    "contextOrNil is the current context, if this is called from the debugger;
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   121
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   122
     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
   123
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   124
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   125
    ^ self new
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   126
	codeCompletionForMethod:methodOrNil orClass:classOrNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   127
	context:contextOrNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   128
	codeView:codeView into:actionBlock
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   129
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   130
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   131
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   132
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   133
findNodeForInterval:interval in:source
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   134
    ^ self new findNodeForInterval:interval in:source
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   135
!
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   136
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   137
findNodeForInterval:interval in:source allowErrors:allowErrors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   138
    ^ self new findNodeForInterval:interval in:source allowErrors:allowErrors
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   139
!
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   140
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   141
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   142
    "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
   143
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   144
    ^ self new
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   145
	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
   146
!
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   147
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   148
findNodeForInterval:interval inParseTree:parseTree
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   149
    ^ 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
   150
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   151
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   152
findNodeIn:tree forInterval:interval
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   153
    ^ self new findNodeIn:tree forInterval:interval
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   156
!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
   157
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   158
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   159
    "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
   160
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   161
		2nd: collection consisting of matching categories"
2661
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
    |matches best lcName|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   164
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   165
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   166
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   167
    "/ search for exact match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   168
    anEnvironment allClassesDo:[:aClass |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   169
	|category|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   170
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   171
	category := aClass category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   172
	(category notNil and:[category startsWith:aPartialCategory]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   173
	    matches add:category
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   174
	]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   175
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   176
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   177
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   178
	lcName := aPartialCategory asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   179
	anEnvironment allClassesDo:[:aClass |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   180
	    |category|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   181
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   182
	    category := aClass category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   183
	    (category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   184
		matches add:category
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   185
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   186
	].
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
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   189
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   190
	^ Array with:aPartialCategory with:(Array with:aPartialCategory)
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
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   193
	^ Array with:matches first with:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   194
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   195
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   196
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   197
    ^ 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
   198
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   199
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   200
     Smalltalk classCategoryCompletion:'Sys'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   201
     Smalltalk classCategoryCompletion:'System'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   202
     Smalltalk classCategoryCompletion:'System-BinaryStorage'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   203
    "
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   204
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   205
    "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
   206
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   207
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   208
classNameEntryCompletionBlock
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   209
    "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
   210
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   211
    ^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:'
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   212
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   213
    "Modified: / 10-08-2006 / 13:22:02 / cg"
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   214
!
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   215
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   216
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
   217
    "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
   218
     2 entries: 1st: the best (longest) match
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   219
                2nd: collection consisting of matching names"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   220
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   221
    |searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   222
     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
   223
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   224
    (words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   225
        w1 := words first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   226
        w2 := words second.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   227
        rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   228
        bestMatch := rslt first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   229
        matches := rslt second.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   230
        ('class' copyTo:(w2 size min:5)) = w2 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   231
            matches := matches collect:[:m | m , ' class'].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   232
            bestMatch := bestMatch , ' class'.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   233
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   234
        ^ InputCompletionResult bestName:bestMatch matchingNames:matches
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   235
    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   236
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   237
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   238
        nsPrefix := 'Smalltalk::'.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   239
        searchName := aPartialClassName withoutPrefix:'Smalltalk::'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   240
    ] ifFalse:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   241
        nsPrefix := ''.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   242
        searchName := aPartialClassName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   243
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   244
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   245
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   246
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   247
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   248
    isMatchString := searchName includesMatchCharacters.
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   249
    (searchName size > 2 
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   250
        and:[ searchName first = $* 
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   251
        and:[ searchName last = $* ]]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   252
    ) ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   253
        isMatchString := false.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   254
        searchName := searchName unquote:$*.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   255
    ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   256
    
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   257
    searchName isEmpty ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   258
        matches := Smalltalk allClassesForWhich:filterBlock.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   259
        ^ InputCompletionResult bestName:searchName matchingNames:#()
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   260
    ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   261
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   262
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   263
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   264
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   265
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   266
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   267
    tryToMatch :=
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   268
        [:className :fullClassName|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   269
            |addIt|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   270
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   271
            isMatchString ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   272
                addIt := searchName match:className
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   273
            ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   274
                addIt := className includesString:searchName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   275
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   276
            addIt ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   277
                matches add:(nsPrefix , fullClassName).
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   278
                matchedNamesWithoutPrefix add:className.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   279
            ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   280
                "/ try ignoring case
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   281
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   282
                isMatchString ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   283
                    addIt := searchName match:className caseSensitive:false
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   284
                ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   285
                    addIt := className includesString:lcSearchName caseSensitive:false.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   286
                    addIt ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   287
                        others add:className
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   288
                    ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   289
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   290
                addIt ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   291
                    ignCaseMatches add:(nsPrefix , fullClassName).
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   292
                    matchedNamesWithoutPrefix add:className.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   293
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   294
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   295
            addIt
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   296
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   297
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   298
    anEnvironment allClassesForWhich:filterBlock do:[:aClass |
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   299
        |addIt fullClassName classNameWithoutPrefix|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   300
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   301
        aClass isMeta ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   302
            fullClassName := aClass name.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   303
            classNameWithoutPrefix := aClass nameWithoutPrefix.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   304
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   305
            addIt := tryToMatch value:fullClassName value:fullClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   306
            addIt ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   307
                classNameWithoutPrefix ~~ fullClassName ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   308
                    tryToMatch value:classNameWithoutPrefix value:fullClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   309
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   310
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   311
        ]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   312
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   313
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   314
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   315
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   316
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   317
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   318
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   319
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   320
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   321
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   322
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   323
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   324
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   325
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   326
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   327
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   328
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   329
"/"/            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
   330
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   331
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   332
"/"/            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
   333
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   334
"/"/            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
   335
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   336
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   337
"/"/            ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   338
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   339
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   340
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   341
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   342
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   343
    matches isEmpty ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   344
        ^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   345
    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   346
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   347
    matches size == 1 ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   348
        best := matches first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   349
        ^ 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
   350
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   351
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   352
    matches
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   353
        sort:[:name1 :name2 |
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   354
            "name1 comes before:name2 iff"
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   355
            ((name2 includes:$:) and:[(name1 includes:$:) not])
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   356
            or:[ ((name1 includes:$:) == (name2 includes:$:))
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   357
                  and:[ (name1 size < name2 size)
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   358
                        or: [ name1 < name2 ]]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   359
               ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   360
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   361
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   362
    isMatchString ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   363
        best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   364
    ] ifFalse:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   365
        matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   366
        best := ignCaseMatches isEmpty
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   367
                    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   368
                    ifFalse:[ matchesForLongestPrefix longestCommonPrefixCaseSensitive:false ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   369
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   370
        best size < aPartialClassName size "best size == 0" ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   371
            best := matchedNamesWithoutPrefix longestCommonPrefix.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   372
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   373
        best size == 0 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   374
            "if tried again, return next match"
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   375
            idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   376
            idx ~~ 1 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   377
                ^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray)
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   378
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   379
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   380
        best size < aPartialClassName size ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   381
            best := aPartialClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   382
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   383
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   384
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   385
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   386
    (cls isBehavior and:[cls isNameSpace]) ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   387
        (matches conform:[:each | each = best
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   388
                                 or:[each startsWith:(best , '::')]])
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   389
        ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   390
            best := best , '::'
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   391
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   392
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   393
    ^ 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
   394
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   395
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   396
     Smalltalk classnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   397
     Smalltalk classnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   398
     Smalltalk classnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   399
     Smalltalk classnameCompletion:'*rray'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   400
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   401
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   402
    "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
   403
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   404
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   405
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   406
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   407
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   408
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   409
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   410
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   411
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   412
	filter:[:cls | true]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   413
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   414
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   415
    "
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   416
     self classnameCompletion:'Arr'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   417
     self classnameCompletion:'Arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   418
     self classnameCompletion:'arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   419
     self classnameCompletion:'*rray' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   420
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   421
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   422
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   423
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   424
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   425
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   426
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   427
    "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
   428
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   429
    ^ [:contents :field  |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   430
	  |s what m|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   431
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   432
	  s := contents withoutSpaces.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   433
	  field topView withCursor:(Cursor questionMark) do:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   434
	      what := self perform:completionSelector with:s with:Smalltalk.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   435
	  ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   436
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   437
	  field contents:(what first).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   438
	  (what at:2) size ~~ 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   439
	      UserPreferences current beepInEditor ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   440
		field device beep
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   441
	      ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   442
	  ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   443
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   444
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   445
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   446
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   447
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   448
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   449
    "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
   450
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   451
		2nd: collection consisting of matching names"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   452
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   453
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   454
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   455
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   456
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   457
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   458
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   459
     Smalltalk globalnameCompletion:'*rray'
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   460
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   461
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   462
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   463
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   464
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   465
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   466
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   467
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   468
		2nd: collection consisting of matching names"
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   469
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   470
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   471
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   472
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   473
    searchName isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   474
	^ Array with:searchName with:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   475
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   476
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   477
    (searchName at:1) isLowercase ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   478
	searchName := searchName copy asUppercaseFirst
2661
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
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   481
    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
   482
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   483
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   484
    anEnvironment keysDo:[:aGlobalName |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   485
	| addIt|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   486
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   487
	isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   488
	    addIt := searchName match:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   489
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   490
	    addIt := aGlobalName startsWith:searchName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   491
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   492
	addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   493
	    matches add:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   494
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   495
	    "/ try ignoring case
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   496
	    isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   497
		addIt := searchName match:aGlobalName caseSensitive:false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   498
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   499
		addIt := aGlobalName asLowercase startsWith:searchName asLowercase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   500
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   501
	    addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   502
		ignCaseMatches add:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   503
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   504
	]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   505
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   506
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   507
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   508
	matches := ignCaseMatches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   509
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   510
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   511
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   512
	^ Array with:searchName with:(Array with:searchName)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   513
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   514
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   515
	^ Array with:matches first with:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   516
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   517
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   518
    isMatchString ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   519
	best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   520
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   521
	best := matches longestCommonPrefix.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   522
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   523
    ^ 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
   524
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   525
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   526
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   527
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   528
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   529
     Smalltalk globalnameCompletion:'*rray'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   530
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   531
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   532
    "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
   533
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   534
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   535
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   536
    "given a partial method protocol name, return an array consisting of
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   537
     2 entries: 1st: the best (longest) match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   538
		2nd: collection consisting of matching protocols"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   539
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   540
    |matches best lcName|
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
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   543
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   544
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   545
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   546
	|protocol|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   547
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   548
	protocol := eachMethod category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   549
	(protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   550
	    matches add:protocol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   551
	].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   552
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   553
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   554
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   555
	lcName := aPartialProtocolName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   556
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   557
	    |protocol|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   558
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   559
	    protocol := eachMethod category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   560
	    (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   561
		matches add:protocol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   562
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   563
	].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   564
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   565
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   566
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   567
	^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   568
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   569
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   570
	^ Array with:matches first with:(matches asArray)
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   571
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   572
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   573
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   574
    ^ Array with:best with:matches asArray
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   575
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   576
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   577
     Smalltalk methodProtocolCompletion:'doc'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   578
     Smalltalk methodProtocolCompletion:'docu'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   579
     Smalltalk methodProtocolCompletion:'documenta'
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   580
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   581
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   582
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   583
    "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
   584
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   585
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   586
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   587
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   588
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   589
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   590
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   591
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   592
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   593
	filter:[:cls | cls isNameSpace]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   594
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   595
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   596
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   597
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   598
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   599
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   600
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   601
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   602
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   603
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   604
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   605
     2 entries: 1st: the best (longest) match
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   606
                2nd: collection consisting of matching packages"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   607
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   608
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   609
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   610
    matches := Smalltalk allPackageIDs
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   611
        select:[:package | package startsWith:aPartialPackage].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   612
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   613
    matches isEmpty ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   614
        "/ search for case-ignoring match
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   615
        lcName := aPartialPackage asLowercase.
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   616
        anEnvironment allClassesDo:[:aClass |
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   617
            |package|
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   618
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   619
            package := aClass package.
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   620
            (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   621
                matches add:package
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   622
            ].
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   623
        ].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   624
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   625
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   626
    matches isEmpty ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   627
        ^ Array with:aPartialPackage with:(Array with:aPartialPackage)
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   628
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   629
    matches size == 1 ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   630
        ^ Array with:matches first with:(matches asArray)
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   631
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   632
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   633
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   634
    ^ Array with:best with:matches asArray
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   635
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   636
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   637
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   638
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   639
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   640
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   641
    "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
   642
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   643
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   644
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   645
    "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
   646
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   647
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   648
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   649
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   650
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   651
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   652
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   653
    "given a partial poolname, return an array consisting of
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   654
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   655
		2nd: collection consisting of matching names"
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   656
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   657
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   658
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   659
	filter:[:cls | cls isSharedPool]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   660
	inEnvironment:anEnvironment
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   661
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   662
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   663
     self poolnameCompletion:'Win' inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   664
     self poolnameCompletion:'Z'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   665
     self poolnameCompletion:'a'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   666
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   667
!
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   668
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   669
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   670
    "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
   671
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   672
		2nd: collection consisting of matching defined resources"
4049
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 best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   675
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   676
    matches := IdentitySet new.
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
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   679
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   680
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   681
	eachMethod hasResource ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   682
	    eachMethod resources keysDo:[:eachResourceName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   683
		(isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   684
		    ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:ignoreCase not) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   685
		    ifFalse:[ ignoreCase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   686
				ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   687
				ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   688
		) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   689
		    matches add:eachResourceName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   690
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   691
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   692
	].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   693
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   694
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   695
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   696
	lcSym := aPartialResourceName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   697
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   698
	    eachMethod hasResource ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   699
		eachMethod resources keysDo:[:eachResourceName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   700
		    (isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   701
			ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:false) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   702
			ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   703
		     ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   704
			matches add:eachResourceName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   705
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   706
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   707
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   708
	].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   709
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   710
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   711
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   712
	^ Array with:aPartialResourceName with:#()
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   713
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   714
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   715
	^ Array with:matches first with:(matches asArray)
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   716
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   717
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   718
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   719
    ^ Array with:best with:matches asArray
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   720
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   721
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   722
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   723
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   724
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   725
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   726
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   727
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   728
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   729
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   730
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   731
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   732
    "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
   733
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   734
		2nd: collection consisting of matching implemented selectors"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   735
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   736
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   737
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   738
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   739
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   740
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   741
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   742
		2nd: collection consisting of matching implemented selectors"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   743
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   744
    ^ self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   745
	selectorCompletion:aPartialSymbolName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   746
	inEnvironment:anEnvironment
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   747
	match:doMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   748
	ignoreCase:false
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   749
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   750
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   751
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   752
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   753
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   754
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   755
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   756
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   757
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   758
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   759
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   760
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   761
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   762
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   763
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   764
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   765
		2nd: collection consisting of matching implemented selectors"
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   766
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   767
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   768
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   769
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   770
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   771
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   772
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   773
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   774
	(isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   775
	    ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:ignoreCase not) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   776
	    ifFalse:[ ignoreCase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   777
			ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   778
			ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   779
	 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   780
	    matches add:eachSelector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   781
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   782
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   783
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   784
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   785
	lcSym := aPartialSymbolName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   786
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   787
	    (isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   788
		ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:false) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   789
		ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   790
	     ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   791
		matches add:eachSelector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   792
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   793
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   794
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   795
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   796
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   797
	^ 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
   798
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   799
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   800
	^ Array with:matches first with:(matches asArray)
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   801
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   802
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   803
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   804
    ^ 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
   805
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   806
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   807
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   808
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   809
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   810
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   811
     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
   812
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   813
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   814
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   815
    "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
   816
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   817
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   821
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   822
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   823
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   824
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
    (lastNewName endsWith:lastOldName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   832
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   833
	    'foo' -> 'Xfoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   834
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   835
	    'bar' would be 'Xbar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   836
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   837
	prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   838
	^ (prefix , oldName).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
    (lastOldName endsWith:lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   841
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   842
	    'Xfoo' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   843
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   844
	    'Xbar' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   845
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   846
	prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   847
	(oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   848
	    ^ (oldName copyFrom:prefix size+1).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   849
	]
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   850
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   851
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   852
	(lastOldName first ~= lastNewName first) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   853
	    (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   854
		"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   855
		    'xfoo' -> 'Xfoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   856
		 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   857
		    'xbar' would be 'Xbar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   858
		"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   859
		lastOldName first isLowercase ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   860
		    ^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   861
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   862
		    ^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   863
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   864
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   865
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   868
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   869
	    '  foo   ' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   870
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   871
	    '  bar   ' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   872
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   873
	^ oldName withoutSeparators.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
    (lastNewName startsWith:lastOldName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   876
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   877
	    'foo' -> 'fooX'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   878
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   879
	    'bar' would be 'barX'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   880
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   881
	suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   882
	^ (oldName , suffix).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
    (lastOldName startsWith:lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   885
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   886
	    'fooX' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   887
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   888
	    'barX' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   889
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   890
	suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   891
	(oldName endsWith:suffix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   892
	    ^ (oldName copyButLast:suffix size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   893
	]
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   895
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   896
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   897
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   898
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   899
    (prefix size > 0) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   900
	(suffix size > 0) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   901
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   902
	    prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   903
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   904
	    "last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   905
		'fooR' -> 'fooXR'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   906
	     then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   907
		'barR' would be 'barXR'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   908
	    "
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   909
	    left := lastOldName copyTo:prefix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   910
	    right := lastOldName copyLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   911
	    lastNewSize > lastOldSize ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   912
		inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   913
		inserted size > 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   914
		    (oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   915
			^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   916
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   917
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   918
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   919
	    (oldName string endsWith:suffix string) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   920
		deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   921
		(oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   922
		    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   923
			"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   924
			    'fooXR' -> 'fooR'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   925
			 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   926
			    'barXS' would be 'barS'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   927
			"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   928
			^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   929
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   930
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   931
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   932
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   933
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   934
	(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   935
	    "last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   936
		'fooX' -> 'fooY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   937
	     then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   938
		'barX' would be 'barY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   939
	    "
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   940
	    left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   941
	    right := lastNewName copyFrom:prefix size+1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   942
	    ^ left , right
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   943
	]
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   944
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   946
    suffix size > 0 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   947
	|prefix2|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   948
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   949
	"last rename was:
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   950
	    'fooSUFF1' -> 'barSUFF1'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   951
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   952
	    'fooSUFF2' -> 'barSUFF2'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   953
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   954
	prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   955
	(oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   956
	    prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   957
	    ^ prefix2,(oldName copyFrom:(prefix size+1)).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   958
	].
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   959
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   960
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   961
    "/ was there something stripped at the end?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   962
    suffix := oldName commonSuffixWith:lastOldName.
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   963
    [suffix size > 0] whileTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   964
	tryAgain := self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   965
		    goodRenameDefaultFor:(oldName copyButLast:suffix size)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   966
		    lastOld:(lastOldName copyButLast:suffix size)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   967
		    lastNew:lastNewName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   968
	tryAgain notNil ifTrue:[^ tryAgain].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   969
	suffix := suffix copyFrom:2.
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   970
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   971
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   972
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   973
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   974
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   975
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   976
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   977
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo'
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   978
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   979
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   980
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   981
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   982
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   983
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   984
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   985
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   986
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   987
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   988
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   989
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   990
     self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   991
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   992
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   993
		       lastOld:'mti.odt2.level1HeadlineMatchPattern'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   994
		       lastNew:'Key_odt2_level1HeadlineMatchPattern'
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   995
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   996
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   997
    "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
   998
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   999
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1000
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1001
    "generate a reasonable default for a file rename operation.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1002
     (Try to rename multiple files in the new fileBrowser,
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1003
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
  1004
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1005
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1006
     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
  1007
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1008
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1009
    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
  1010
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1011
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1012
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1013
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1014
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1016
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1017
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1018
	lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1019
	    ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1020
	].
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1021
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1022
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1023
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1024
    default notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1025
	lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1026
	lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1027
	oldRest := oldName copyFrom:oldWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1028
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1029
	^ default , lastNewRest
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1030
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1031
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1032
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1034
	lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1035
	lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1036
	oldRest := oldWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1037
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1038
	(lastNewRest endsWith:lastOldRest) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1039
	    t := lastNewRest copyButLast:lastOldRest size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1040
	    ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1041
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
    suffix size > 0 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1046
	"/ last change changed something at the beginning
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1047
	prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1048
	prefix size > 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1049
	    "/ this name starts with the same characters
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1050
	    lastRemoved := lastOldWOSuffix copyButLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1051
	    lastInserted := lastNewWOSuffix copyButLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1052
	    (lastRemoved startsWith:lastInserted) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1053
		oldWOSuffix size >= lastInserted size ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1054
		    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1055
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1056
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1057
	    ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1058
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1062
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1063
    "Modified: / 07-11-2006 / 13:58:39 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1066
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1067
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1068
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1069
    "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
  1070
     This is used to specially priorize plausible typing errors of adjacent keys.
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1071
     CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else."
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1072
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1073
    ^ 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
  1074
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1075
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1076
     self isKey:$a nextTo:$a
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1077
     self isKey:$a nextTo:$s
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1078
     self isKey:$a nextTo:$q
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1079
     self isKey:$a nextTo:$w
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1080
     self isKey:$a nextTo:$z
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1081
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1082
    "
3316
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
    "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
  1085
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1086
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1087
isKey:k1 nextTo:k2 onKeyboard:keys
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1088
    "return true, if k1 and k2 are adjacent keys on the keyboard defined by keys.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1089
     This is used to specially priorize plausible typing errors of adjacent keys.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1090
     (typo checker uses a modified levenshtein, 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1091
      in which keys next to each other are valued differently)"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1092
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1093
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1094
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1095
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1096
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1097
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1098
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1099
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1100
    ^ (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
  1101
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1102
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1103
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1104
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1105
    "
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1106
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1107
    "Modified (comment): / 01-05-2016 / 12:19:24 / cg"
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1108
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1109
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1110
keyboard
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1111
    "the keyboard layout
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1112
     (useful to figure out which keys are nearby a key, to find possible typing errors)
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1113
     CAVEAT: hard coded us-, german and french keyboards here; data should come from somewhere else."
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1114
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1115
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1116
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1117
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1118
    lang == #de ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1119
	^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1120
	       '1234567890-'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1121
	       '*qwertzuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1122
	       '**asdfghjkl:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1123
	       '***yxcvbnm'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1124
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1125
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1126
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1127
    lang == #fr ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1128
	^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1129
	       '1234567890'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1130
	       '*azertyuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1131
	       '**qsdfghjklm'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1132
	       '***wxcvbn,'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1133
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1134
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1135
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1136
    ^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1137
	   '1234567890-'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1138
	   '*qwertyuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1139
	   '**asdfghjkl:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1140
	   '***zxcvbnm'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1141
    ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1142
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1143
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1144
     self keyboard
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1145
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1146
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1147
    "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
  1148
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1149
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1150
!DoWhatIMeanSupport methodsFor:'code completion'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1151
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1152
codeCompletionFor: codeAspectArg language: languageOrNilArg method:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1153
    "provide code completion information by analyzing what the editing state is in codeViewArg
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1154
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1155
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1156
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1157
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1158
        1) the completer needs to know about the text around the cursor position
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1159
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1160
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1161
     For example, in many situations, both a completion of a unary selector before the cursor,
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1162
     or adding another keyword part after the cursor is possible.
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1163
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1164
     perform the completion.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1165
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1166
     An additional array containing a textual description for each suggestion is also provided, which could
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1167
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1168
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1169
     ContextOrNil is the current context, if this is called from the debugger;
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1170
     or nil, if called from the browser.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1171
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1172
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1173
    | language |
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1174
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1175
    codeAspect := codeAspectArg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1176
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1177
    languageOrNilArg notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1178
        language := languageOrNilArg
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1179
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1180
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1181
            | method |
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1182
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1183
            method := contextOrNilArg method.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1184
            method notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1185
                language := method programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1186
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1187
                contextOrNilArg isJavaContext ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1188
                    language := JavaLanguage instance
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1189
                ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1190
                    language := SmalltalkLanguage instance.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1191
                ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1192
            ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1193
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1194
            methodOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1195
                language := methodOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1196
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1197
                classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1198
                    language := classOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1199
                ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1200
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1201
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1202
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1203
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1204
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1205
        language isSmalltalk ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1206
            ^self codeCompletionForSmalltalkMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1207
        ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1208
        language isSTXJavaScript ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1209
            ^self codeCompletionForJavascriptMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1210
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1211
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1212
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1213
    "/ No completion support for given language
5051
6e150dbaf9bc #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5050
diff changeset
  1214
    "/ self breakPoint: #cg.
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1215
    self breakPoint: #jv.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1216
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1217
    "Created: / 27-09-2013 / 10:21:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4451
8db9cfa578c0 class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4444
diff changeset
  1218
    "Modified: / 26-11-2013 / 23:43:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1219
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1220
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1221
codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNilArg codeView:codeViewArg
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1222
    "going to become OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1223
     contextOrNil is the current context, if this is called from the debugger;
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1224
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1225
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1226
     because we actually know what a variable's type is."
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1227
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1228
    | language |
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1229
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1230
    languageOrNil notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1231
        language := languageOrNil
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1232
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1233
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1234
            language := contextOrNilArg method programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1235
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1236
            classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1237
                language := classOrNilArg programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1238
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1239
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1240
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1241
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1242
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1243
        language isSmalltalk ifTrue:[
4731
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1244
            classOrNil := classOrNilArg.
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1245
            contextOrNil := contextOrNilArg.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1246
            ^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1247
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1248
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1249
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1250
    "/ No completion support for given language
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1251
    self breakPoint: #cg.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1252
    self breakPoint: #jv.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1253
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1254
    "Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5007
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1255
!
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1256
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1257
setClass: classOrNilArg andContext:contextOrNilArg
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1258
    classOrNil := classOrNilArg.
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1259
    contextOrNil := contextOrNilArg.
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1260
! !
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1261
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1262
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'!
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1263
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1264
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1265
    "provide code completion information by analyzing what the editing state is in codeViewArg
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1266
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1267
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1268
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1269
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1270
        1) the completer needs to know about the text around the cursor position
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1271
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1272
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1273
     For example, in many situations, both a completion of a unary selector before the cursor,
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1274
     or adding another keyword part after the cursor is possible.
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1275
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), to
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1276
     perform the completion.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1277
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1278
     An additional array containing a textual description for each suggestion is also provided, which could
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1279
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1280
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1281
     ContextOrNil is the current context, if this is called from the debugger;
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1282
     or nil, if called from the browser.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1283
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1284
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1285
    languageOrNil := STXJavaScriptLanguage instance.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1286
    methodOrNil := methodOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1287
    classOrNil := classOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1288
    codeView := codeViewArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1289
    contextOrNil := contextOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1290
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1291
    JavaScriptCompletionEngine notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1292
        JavaScriptCompletionEngine new
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1293
           completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1294
    ].
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1295
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1296
    self information:'Not yet supported'.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1297
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1298
    "Created: / 18-09-2013 / 16:24:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1299
    "Modified: / 25-09-2013 / 15:13:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1300
! !
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1301
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1302
!DoWhatIMeanSupport methodsFor:'code completion - Smalltalk'!
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1303
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1304
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1305
4379
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1306
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1307
     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
  1308
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1309
     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
  1310
     This is not yet done, sigh"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1311
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1312
    |crsrPos char interval source node parent checkedNode instanceOrNilArg
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1313
     forceNewMessageSend classOfReceiver prevChar|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1314
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1315
    languageOrNil := SmalltalkLanguage instance.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1316
    classOrNil := classOrNilArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1317
    codeView := codeViewArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1318
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1319
    crsrPos := codeView characterPositionOfCursor"-1".
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1320
    char := codeView characterAtCharacterPosition:crsrPos.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1321
    "/ Transcript show:crsrPos; show:' '; showCR:char.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1322
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1323
        crsrPos := crsrPos - 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1324
        char := codeView characterAtCharacterPosition:crsrPos.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1325
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1326
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1327
    interval := codeView selectedInterval.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1328
    "/ Transcript show:'iv: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1329
    interval isEmpty ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1330
        interval := crsrPos"-1" to:crsrPos.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1331
        "/ Transcript show:'iv2: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1332
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1333
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1334
    source := codeView contentsAsString string.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1335
    source := source copyTo:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1336
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1337
    "/ this is too naive and stupid; if there is a syntactic error,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1338
    "/ 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
  1339
    "/ 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
  1340
    "/ without any progress.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1341
    "/ 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
  1342
    "/ as it parses the code. Stop, when the interval is hit.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1343
    "/ that will also work for syntactic incorrect source code.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1344
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1345
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1346
        "/ Transcript show:'nd1: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1347
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1348
    node isNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1349
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1350
        "/ Transcript show:'nd2 try: '; showCR:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1351
        node isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1352
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1353
            self breakPoint:#cg.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1354
            "/ self information:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1355
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1356
        ]
4238
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
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1359
    forceNewMessageSend := false.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1360
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1361
    "/ if there a separator between the variable's name and the cursor position...
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1362
    prevChar := codeView characterBeforeCursor.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1363
    (prevChar isSeparator or:[ ')}]''' includes:prevChar ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1364
        (node isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1365
            and:[ (parent := node parent) notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1366
            and:[ parent isMessage ]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1367
        ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1368
            "/ completion after a variable node...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1369
            parent isKeyword ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1370
                "/ and it is a keyword message, we complete the keyword message instead
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1371
                node := parent.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1372
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1373
                "/ otherwise, a unary message is probably intended to be sent to the variable.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1374
                "/ (however, no character is available to determine what is useful)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1375
                forceNewMessageSend := true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1376
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1377
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1378
            (node isMessage and:[node isUnary]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1379
                "/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1380
                "/
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1381
                forceNewMessageSend := true.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1382
"/                "/ can we see what we get from foo?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1383
"/                classOfReceiver := self
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1384
"/                                    classOfReceiver:node receiver
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1385
"/                                    inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1386
"/                classOfReceiver notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1387
"/                    |mthd|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1388
"/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1389
"/                    mthd := classOfReceiver lookupMethodFor:node selector.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1390
"/                    mthd notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1391
"/                        self halt.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1392
"/                        (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1393
"/                            forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1394
"/                        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1395
"/                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1396
"/                ].
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1397
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1398
        ]
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1399
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1400
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1401
    forceNewMessageSend ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1402
        "/ completion with nothing to start (right after a variable)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1403
        "/ see what the variable can understand and present the most useful stuff (very thin ice here)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1404
        classOfReceiver := self classOfNode:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1405
        classOfReceiver isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1406
            "/ it does not make sense to offer anything, if we don't have any idea of what this
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1407
            "/ will be...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1408
            Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1409
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1410
            |superClass possible choice|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1411
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1412
            possible := classOfReceiver selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1413
            superClass := classOfReceiver superclass.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1414
            [superClass notNil "and:[(possible size + superClass selectors size) < 500]"] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1415
                possible := possible,superClass selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1416
                superClass := superClass superclass.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1417
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1418
            possible := possible copy sort.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1419
            choice := self askUserForCompletion:('Message to "%1"' bindWith:node formattedCode) for:codeView from:possible.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1420
            choice isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1421
                Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1422
                ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1423
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1424
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1425
            codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1426
                undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1427
                    codeView insertStringAtCursor:choice
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1428
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1429
                info:'Completion'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1430
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1431
        ^ self
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1432
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1433
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1434
    node isVariable ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1435
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1436
        ^ self.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1437
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1438
    node isLiteral ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1439
        node value isSymbol ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1440
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1441
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1442
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1443
        ^ self "/ huh - strings or what?
4238
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1446
    checkedNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1447
    [checkedNode notNil] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1448
        checkedNode isMessage ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1449
            "/ completion in a message-send
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1450
            contextOrNilArg notNil ifTrue:[
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1451
"/                |rcvrNode idx rcvr val|
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1452
"/
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1453
"/                (rcvrNode := checkedNode receiver) isVariable ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1454
"/                    rcvrNode isSelf ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1455
"/                        classOrNil := contextOrNil receiver class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1456
"/                    ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1457
"/                        (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1458
"/                            val := contextOrNil argsAndVars at:idx.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1459
"/                            classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1460
"/                        ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1461
"/                            (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1462
"/                                val := contextOrNil receiver instVarNamed:rcvrNode name.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1463
"/                                classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1464
"/                            ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1465
"/                        ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1466
"/                    ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1467
"/                ].
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1468
                instanceOrNilArg := contextOrNilArg receiver
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1469
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1470
            self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1471
                codeCompletionForMessage:checkedNode
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1472
                inClass:classOrNil instance:instanceOrNilArg
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1473
                context:contextOrNilArg codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1474
            ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1475
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1476
        checkedNode isMethod ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1477
            "/ completion in a method's selector pattern
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1478
            self codeCompletionForMethodSpec:checkedNode.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1479
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1480
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1481
        checkedNode := checkedNode parent.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1482
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1483
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1484
    self information:'Node is neither variable nor message.'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1485
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1486
    "Created: / 18-09-2013 / 15:25:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1487
!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1488
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1489
codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1490
    "provide code completion information by analyzing what the editing state is in codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1491
     (cursor position, characters around cursor etc.) and calling back into actionBlock, passing
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1492
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1493
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1494
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1495
        1) the completer needs to know about the text around the cursor position
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1496
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1497
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1498
     For example, in many situations, both a completion of a unary selector before the cursor,
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1499
     or adding another keyword part after the cursor is possible.
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1500
     Thus, this provides a list of completions PLUS a list of edit operations (as per completion), 
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1501
     to perform the completion.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1502
     The caller has to open a dialog, providing the suggestions, and perform the corresponding edit operation.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1503
     An additional array containing a textual description for each suggestion is also provided, which could
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1504
     be shown as info or appended to the suggestions (such as 'complete variable', 'complete keyword', etc.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1505
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1506
     ContextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1507
     or nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1508
     If nonNil, we can make better guesses, because we actually know what a variable's type is"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1509
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1510
    |crsrPos char interval i source partialSource cursorLineSource
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1511
     suggestions actions title suggestionCollector|
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1512
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1513
    languageOrNil := SmalltalkLanguage instance.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1514
    methodOrNil := methodOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1515
    classOrNil := classOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1516
    codeView := codeViewArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1517
    contextOrNil := contextOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1518
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1519
"/    classOrNil isNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1520
"/        self information:'No class'.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1521
"/        ^ self.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1522
"/    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1523
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1524
    crsrPos := codeView characterPositionOfCursor.
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  1525
    char := codeView characterAtCharacterPosition:(crsrPos-1 max:1).
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1526
    [crsrPos > 1 and:[char isSeparator "or:['.' includes:char]"]] whileTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1527
        crsrPos := crsrPos - 1.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1528
        char := codeView characterAtCharacterPosition:crsrPos.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1529
    ].
4711
1c2e635489e5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4710
diff changeset
  1530
    char == $. ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1531
        "/ either at end of statement or after a character constant
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1532
        crsrPos == 1 ifTrue:[^ self].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1533
        (codeView characterAtCharacterPosition:crsrPos-1) == $$ ifFalse:[^ self].
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1534
    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1535
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1536
    suggestionCollector :=
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1537
        [:listOfSuggestions :listOfActionsOrBlock :titleWhenAsking |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1538
            "/ may be called multiple times!!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1539
            suggestions isNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1540
                suggestions := listOfSuggestions.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1541
                actions := listOfActionsOrBlock.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1542
                title := titleWhenAsking.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1543
            ] ifFalse:[    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1544
                suggestions := suggestions asOrderedCollection.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1545
                actions isBlock ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1546
                    actions := Array new:suggestions size withAll:actions.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1547
                ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1548
                actions := actions asOrderedCollection.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1549
                
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1550
                suggestions addAll:listOfSuggestions.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1551
                listOfActionsOrBlock isBlock ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1552
                    actions addAll:(Array new:listOfSuggestions size withAll:listOfActionsOrBlock).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1553
                ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1554
                    actions addAll:listOfActionsOrBlock.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1555
                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1556
                title := titleWhenAsking.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1557
            ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1558
        ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1559
        
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1560
    interval := crsrPos-1 to:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1561
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1562
    source := codeView contentsAsString string.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1563
    partialSource := source copyTo:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1564
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1565
    methodOrNilArg isNil ifTrue:[
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1566
        (partialSource endsWith:Character cr) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1567
            partialSource := partialSource copyButLast.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1568
        ].    
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1569
        "/ first try parsing the current cursor line.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1570
        "/ this helps doIts in a workspace, where additional garbage is often before the actual expression to be evaluated
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1571
        (i := partialSource lastIndexOf:Character cr) ~~ 0 ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1572
            "/ because cursorPositions and node-positions are required elsewhere to be correct,
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1573
            "/ I cannot just snip off the line and parse that one alone (later corrections will do so at wrong position).
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1574
            "/ Instead, create a copy of the whole source, with the stuff before the cursor line being blanked out.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1575
            "/ However, because somewhere else, we fetch characters from the codeView using the index,
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1576
            "/ we must preserve the line structure (i.e. keep crs).
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1577
            cursorLineSource := partialSource copy.
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1578
            1 to:i do:[:pos | 
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1579
                (cursorLineSource at:pos) ~= Character cr ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1580
                    cursorLineSource at:pos put:Character space.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1581
                ]
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1582
            ].    
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1583
            self
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1584
                tryCodeCompletionWithSource:cursorLineSource nodeInterval:interval
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1585
                at:crsrPos mustBeExpression:true
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1586
                into:suggestionCollector.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1587
        ].
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1588
    ].
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1589
    
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1590
"/    suggestions isEmptyOrNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1591
"/        "/ try parsing the partial source (from beginning up to the cursor)
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1592
"/        self
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1593
"/            tryCodeCompletionWithSource:partialSource nodeInterval:interval
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1594
"/            at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil])
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1595
"/            into:suggestionCollector.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1596
"/    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1597
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1598
    suggestions isEmptyOrNil ifTrue:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1599
        "/ try parsing the whole source
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1600
        self
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1601
            tryCodeCompletionWithSource:source nodeInterval:interval
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1602
            at:crsrPos mustBeExpression:false
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1603
            into:suggestionCollector
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1604
    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1605
    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1606
    suggestions isNil ifTrue:[
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1607
        "/ try parsing the partial source (from beginning up to the cursor)
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1608
        self
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1609
            tryCodeCompletionWithSource:partialSource nodeInterval:interval
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1610
            at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil])
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1611
            into:suggestionCollector.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1612
    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1613
    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1614
    suggestions isEmptyOrNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1615
        "/ nothing found
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1616
        ^ self
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1617
    ].    
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1618
    actionBlock value:suggestions value:actions value:title.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1619
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1620
    "Created: / 18-09-2013 / 15:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1621
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1622
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1623
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1624
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1625
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1626
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1627
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1628
     contextOrNil is the current context, if this is called from the debugger;
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1629
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1630
     If nonNil, we can make better guesses, because we actually know what a variable's type is.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1631
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1632
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1633
    ^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1634
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1635
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1636
    "Modified: / 28-08-2013 / 17:15:25 / cg"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1637
    "Modified: / 18-09-2013 / 14:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1638
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1639
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1640
codeCompletionForMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1641
    <resource: #obsolete>
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1642
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1643
	codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1644
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1645
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1646
!DoWhatIMeanSupport methodsFor:'code completion-helpers'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1647
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1648
askUserForCompletion:what for:codeView at:position from:allTheBest
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1649
    |list choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1650
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1651
    "/ cg: until the new stuff works,...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1652
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1653
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1654
"/    allTheBest isEmpty ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1655
"/        ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1656
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1657
"/    allTheBest size == 1 ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1658
"/        ^ allTheBest first
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1659
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1660
"/    list := allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1661
"/    LastChoices notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1662
"/        lastChoice := LastChoices at:what ifAbsent:nil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1663
"/        lastChoice notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1664
"/            list := { lastChoice allBold } , (list copyWithout:lastChoice).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1665
"/        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1666
"/    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1667
"/    choice := Tools::CodeCompletionMenu
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1668
"/                openFor:codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1669
"/                at:position
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1670
"/                with:allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1671
"/    LastChoices isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1672
"/        LastChoices := Dictionary new.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1673
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1674
"/    LastChoices at:what put:choice.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1675
"/    ^ choice string
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1676
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1677
    "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
  1678
    "Modified: / 28-08-2013 / 16:41:35 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1679
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1680
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1681
askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1682
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1683
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1684
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1685
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1686
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1687
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1688
    LastChoices notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1689
	lastChoice := LastChoices at:what ifAbsent:nil.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1690
	lastChoice notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1691
	    list := {lastChoice. nil. } , (list copyWithout:lastChoice).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1692
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1693
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1694
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1695
    list size < 30 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1696
	|menu idx exitKey|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1697
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1698
	menu := PopUpMenu labels:list.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1699
	menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1700
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1701
		hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1702
		    exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1703
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1704
		hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1705
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1706
	idx := menu startUp.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1707
	idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1708
	    exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1709
		codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1710
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1711
	    ^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1712
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1713
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1714
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1715
	resources := codeView application isNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1716
			ifTrue:[ codeView resources]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1717
			ifFalse:[ codeView application resources ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1718
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1719
	choice := Dialog
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1720
	   choose:(resources string:'Choose ',what)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1721
	   fromList:list
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1722
	   lines:20
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1723
	   title:(resources string:'Code completion').
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1724
	choice isNil ifTrue:[^ nil].
4238
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
    LastChoices isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1728
	LastChoices := Dictionary new.
4238
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
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1731
    ^ choice
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
    "Created: / 10-11-2006 / 14:00:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1734
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1735
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1736
codeCompletionForBlockArgument:node into:actionBlock
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1737
!
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1738
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1739
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1740
    "looking for all symbols is way too much and inprecise;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1741
     experiment: only present symbols which are used by the class,
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1742
     and classes in that class category, or at least: implemented as method.
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1743
     We'll see..."
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1744
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1745
    |sym possibleCompletions longest editAction start stop addSymbol
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1746
     parentSelector parent symbolSelectorClass|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1747
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1748
    "/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1749
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1750
    start := (nodeOrNil ? tokenOrNil) start.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1751
    stop := (nodeOrNil ? tokenOrNil) stop.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1752
    (codeView characterAtCharacterPosition:stop) == $' ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1753
        ^ self.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1754
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1755
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1756
    sym := (nodeOrNil ? tokenOrNil) value.
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1757
    possibleCompletions := Set new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1758
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1759
    addSymbol :=
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1760
        [:aSymbol |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1761
            (aSymbol startsWith:sym) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1762
                (aSymbol = sym) ifFalse:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1763
                    possibleCompletions add:aSymbol
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1764
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1765
            ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1766
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1767
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1768
    (nodeOrNil notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1769
    and:[ (parent := nodeOrNil parent) notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1770
    and:[ parent isMessage ]]) ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1771
        parentSelector := parent selector.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1772
        ( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1773
            symbolSelectorClass := self classOfNode:parent receiver.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1774
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1775
        ( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1776
            "/ assume that send-target will be self.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1777
            (methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1778
                addSymbol value:(methodOrNil selector,'Changed').
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1779
            ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1780
            symbolSelectorClass := classOrNil.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1781
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1782
        ( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1783
            symbolSelectorClass := self classOfNode:parent arguments second.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1784
        ].
5074
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1785
        
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1786
        "/ actually, I found that this gives good suggestions.
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1787
        symbolSelectorClass isNil ifTrue:[
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1788
            symbolSelectorClass := classOrNil.
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1789
        ].
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1790
        
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1791
        symbolSelectorClass notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1792
            symbolSelectorClass withAllSuperclassesDo:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1793
                cls ~~ Object ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1794
                    cls ~~ Model ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1795
                        cls methodDictionary keysDo:addSymbol.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1796
                    ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1797
                ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1798
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1799
        ].
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1800
    ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1801
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1802
    (considerAll or:[classOrNil isNil]) ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1803
        Smalltalk allClassesDo:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1804
            cls theNonMetaclass methodDictionary keys do:addSymbol.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1805
            cls theMetaclass methodDictionary keys do:addSymbol.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1806
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1807
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1808
        "/ Symbol allInstancesDo:addSymbol.
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1809
    ] ifFalse:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1810
        Smalltalk allClassesInCategory:classOrNil do:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1811
            cls theNonMetaclass instAndClassMethodsDo:[:mthd |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1812
                mthd usedSymbols do:addSymbol
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1813
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1814
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1815
    ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1816
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1817
    "/ add symbolic literals (especially for spec methods)
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1818
    classOrNil notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1819
        classOrNil theMetaclass instAndClassMethodsDo:[:mthd |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1820
            mthd literalsDo:[:lit |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1821
                lit isSymbol ifTrue:[ addSymbol value: lit ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1822
            ].    
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1823
        ].    
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1824
    ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1825
    
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1826
    possibleCompletions := possibleCompletions asOrderedCollection sort.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1827
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1828
    longest := possibleCompletions longestCommonPrefix.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1829
    possibleCompletions remove:longest ifAbsent:[].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1830
    possibleCompletions addFirst: longest.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1831
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1832
    editAction :=
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1833
        [:chosenIndex |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1834
            |chosen oldSym oldLen newLen|
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1835
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1836
            chosen := possibleCompletions at:chosenIndex.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1837
            chosen notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1838
                (codeView characterAtCharacterPosition:start) == $# ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1839
                    start := start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1840
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1841
                (codeView characterAtCharacterPosition:start) == $' ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1842
                    start := start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1843
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1844
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1845
                oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1846
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1847
                codeView
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1848
                    undoableDo:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1849
                        codeView replaceFromCharacterPosition:start to:stop with:chosen
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1850
                    ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1851
                    info:'Completion'.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1852
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1853
                (chosen startsWith:oldSym) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1854
                    oldLen := stop - start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1855
                    newLen := chosen size.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1856
                    codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1857
                    codeView dontReplaceSelectionOnInput
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1858
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1859
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1860
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1861
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1862
    actionBlock value:possibleCompletions value:editAction value:'symbol'.
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
    "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
  1865
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1866
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1867
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1868
codeCompletionForMessage:node into:actionBlock
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1869
    "find good completions for a message selector in a message-send node"
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1870
    
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  1871
    |selector lcSelector bestSelectors parentSelector newParentSelector bestSelectors2 bestWithParenthesis allBest numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1872
     newParts nSelParts oldLen newLen selectorParts
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  1873
     findBest parentNode nodeReceiver "selectorsSentInCode" selectorsImplementedInClass
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  1874
     editAction parentNodeClassIfKnown
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  1875
     receiverNodeClassIfKnown 
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  1876
     offerParenthisationAroundNode parenthesisAroundIndex parentNodeToParenthesize
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  1877
     offerValueInsertion valueToInsert valueToInsertIndex valueInfo
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1878
     classesFromAssignmentsToReceiver otherMessagesToReceiver
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1879
     canParenthesize classesOfReceiver|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1880
 
5039
8199b9455761 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5038
diff changeset
  1881
    "/ Transcript show:'node '; show:node; show:' ; '.
8199b9455761 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5038
diff changeset
  1882
    "/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1883
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  1884
    offerParenthisationAroundNode := nil.
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  1885
    offerValueInsertion := false.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1886
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  1887
    "/ node at:1
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1888
 
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1889
    findBest := 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1890
        [:node :selector |
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1891
            |srchClasses bestSelectors bestPrefixes
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1892
             allMessagesSentToVariable classesImplementingAllMessages|
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1893
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1894
            srchClasses := node==nodeReceiver 
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1895
                            ifTrue:[classesOfReceiver]
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1896
                            ifFalse:[self classesOfNode:node].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1897
 
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1898
            srchClasses isEmptyOrNil ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1899
                node isVariable ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1900
                    allMessagesSentToVariable := Set new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1901
                    rememberedNodes do:[:eachNode |
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1902
                        eachNode allMessageNodesDo:[:eachMessage |
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1903
                            |msgReceiver msgSelector|
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1904
                            
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1905
                            (msgReceiver := eachMessage receiver) isVariable ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1906
                                msgReceiver name = node name ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1907
                                    (msgSelector := eachMessage selector) ~= selector ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1908
                                        allMessagesSentToVariable add:msgSelector
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1909
                                    ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1910
                                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1911
                            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1912
                        ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1913
                    ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1914
                    allMessagesSentToVariable notEmpty ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1915
                        "/ consider classes which implement all those messages.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1916
                        classesImplementingAllMessages := Smalltalk allImplementorsOf:(allMessagesSentToVariable first).
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1917
                        allMessagesSentToVariable do:[:eachSelector |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1918
                            classesImplementingAllMessages := classesImplementingAllMessages
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1919
                                                                select:[:cls | cls implements:eachSelector].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1920
                        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1921
                        srchClasses := classesImplementingAllMessages.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1922
                    ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1923
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1924
            ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1925
            bestSelectors := Set new.
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1926
            srchClasses isEmptyOrNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1927
                bestSelectors addAll:( Parser findBest:50 selectorsFor:selector in:nil forCompletion:true ).
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1928
            ] ifFalse:[    
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1929
                srchClasses do:[:srchClass |
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1930
                    |bestForThisClass|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1931
 
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1932
                    bestForThisClass := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1933
                    bestForThisClass := self
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1934
                                        withoutSelectorsUnlikelyFor:srchClass
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1935
                                        from:bestForThisClass
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1936
                                        forPartial:selector.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1937
                    bestSelectors addAll:bestForThisClass.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  1938
                ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1939
            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1940
            "/ remove the already typed-in selector itself, in case.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1941
            bestSelectors remove:selector ifAbsent:[].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1942
            bestSelectors := bestSelectors asOrderedCollection.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1943
            bestSelectors
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1944
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1945
 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1946
    selector := node selector.
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  1947
    lcSelector := selector asLowercase.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1948
    parentNode := node parent.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1949
    nodeReceiver := node receiver.
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1950
    nodeReceiver notNil ifTrue:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1951
        classesOfReceiver := self classesOfNode:nodeReceiver.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1952
    ].
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1953
Transcript show:node; show:' -> '; showCR:classesOfReceiver.
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  1954
( node isVariable and:[node name = 'self']) ifTrue:[self halt].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1955
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1956
    "/ if there is already space before the cursor, and the parent node is not a message,
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1957
    "/ do not attempt to complete the current message.
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1958
    "/ If it is a message, we will look for parent-message completion also below (best2 stuff)
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1959
    (codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  1960
        selector isKeyword ifFalse:[
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  1961
            self codeCompletionForMessageTo:node into:actionBlock.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1962
            ^ self
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1963
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1964
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1965
 
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1966
    "/ only do this if the node-message has no parents around
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1967
    node parentheses isEmptyOrNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1968
        bestSelectors := findBest value:nodeReceiver value:selector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1969
    ] ifFalse:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1970
        bestSelectors := OrderedCollection new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1971
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1972
 
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1973
    "/ if the receiver is a real variable,
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1974
    "/ we can look for other messages being sent to that variable in the current method.
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  1975
    "/ Also, if there are assignments to it (like constants or '<class> new'), use that as a hint...
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1976
    (tree notNil
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1977
        and:[ nodeReceiver isVariable
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1978
        and:[ nodeReceiver isSelf not
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1979
        and:[ nodeReceiver isSuper not ]]])
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1980
    ifTrue:[
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  1981
        |receiverName possibleClasses possibleClassesFromOtherSends|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1982
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1983
        receiverName := nodeReceiver name.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1984
 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1985
        classesFromAssignmentsToReceiver := self classesFromAssignmentTo:receiverName in:tree.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1986
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1987
        possibleClasses := classesFromAssignmentsToReceiver.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1988
        possibleClasses isEmpty ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1989
            "/ messages sent
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1990
            otherMessagesToReceiver := self messagesSentTo:receiverName in:tree.
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  1991
            otherMessagesToReceiver remove:selector ifAbsent:[].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  1992
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1993
            otherMessagesToReceiver notEmpty ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1994
                "/ classes which respond to all
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1995
                possibleClassesFromOtherSends :=
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1996
                    Smalltalk 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1997
                        allClassesForWhich:[:cls |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1998
                            cls isLoaded
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1999
                            and:[ otherMessagesToReceiver
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2000
                                    conform:[:eachSelectorSent | cls canUnderstand:eachSelectorSent]]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2001
                        ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2002
                possibleClasses := possibleClasses , possibleClassesFromOtherSends.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2003
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2004
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2005
 
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2006
        "/ if the receiver is a classVar/classInstVar,
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2007
        "/ include the class of its current value and UndefinedObject.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2008
        "/ This helps to complete class methods and (lazy) initializer code.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2009
        (classOrNil notNil) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2010
            |tryValue currentValue|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2011
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2012
            tryValue := false.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2013
            (classOrNil theNonMetaclass allClassVarNames includes: receiverName) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2014
                tryValue := true.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2015
                currentValue := classOrNil theNonMetaclass classVarAt:receiverName.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2016
            ] ifFalse:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2017
                (classOrNil isMeta and:[ classOrNil allInstVarNames includes: receiverName ]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2018
                    tryValue := true.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2019
                    currentValue := classOrNil theNonMetaclass instVarNamed:receiverName.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2020
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2021
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2022
            tryValue ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2023
                possibleClasses := { currentValue class } , possibleClasses.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2024
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2025
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2026
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2027
        (possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2028
            bestSelectors :=
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2029
                (possibleClasses 
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2030
                    collectAll:[:eachClass |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2031
                        Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2032
                    ] as:Set) asOrderedCollection.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2033
 
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2034
            "/ if any of those is a prefix-keyword of the selector,
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2035
            "/ do not offer it (i.e. ifTrue:ifFalse: is already present, don't offer ifTrue:ifFalse: again.
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2036
            bestSelectors := bestSelectors reject: [:sel | (selector startsWith: sel) or: [selector endsWith: sel]].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2037
        ].
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2038
    ].                                                                            
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2039
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2040
    "/ if we are behind a keyword messages colon,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2041
    "/ only look for matching prefix selectors;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2042
    "/ also, a good completion is to insert an argument;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2043
    "/ the name of the variable from the implementation, as comment, and selected might be a good one!!
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2044
    "/ Array new:1
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2045
    selector isKeyword ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2046
        (node arguments size = selector numArgs) ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2047
            offerParenthisationAroundNode := node. 
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2048
            "/ Transcript show:'2:'; showCR:node.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2049
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2050
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2051
        codeView characterBeforeCursor == $: ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2052
            (bestSelectors select:[:sel | sel asLowercase startsWith:lcSelector]) isEmpty ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2053
                "/ nothing better around
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2054
                |argIndex argNames argNameStrings impls|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2055
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2056
                argIndex := node selectorParts size.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2057
                argNames := Set new.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2058
                argNameStrings := OrderedCollection new.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2059
                impls := Smalltalk allImplementorsOf:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2060
                impls size < 10 ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2061
                    impls do:[:eachImplClass |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2062
                        |mthd argName|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2063
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2064
                        mthd := (eachImplClass compiledMethodAt:selector).
4764
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2065
                        argName := (mthd methodArgNames ? #()) at:argIndex ifAbsent:nil.
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2066
                        argName notNil ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2067
                            (argNames includes:argName) ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2068
                                argNames add:argName.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2069
                                argNameStrings add:(argName allItalic,' hint only: argName in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2070
                            ].    
4764
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2071
                        ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2072
                    ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2073
                    argNameStrings notEmptyOrNil ifTrue: [
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2074
                        argNameStrings := argNameStrings asOrderedCollection sort.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2075
                        actionBlock value:argNameStrings value:[:selIndex | ] value: 'argument name hint'.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2076
                        ^ self.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2077
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2078
                ]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2079
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2080
        ].
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2081
    ] ifFalse:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2082
        "/ when completing a non-keyword AND the parent is a keyword message,
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2083
        "/ only consider longer keyword messages or unary messages.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2084
        "/ unless the node is parenthesized
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2085
        node hasParentheses ifFalse:[ 
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2086
            (parentNode notNil and:[ parentNode isKeywordMessage ]) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2087
                bestSelectors := bestSelectors select:[:sel | sel isUnarySelector or:[ sel startsWith:sel]]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2088
            ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2089
        ]
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2090
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2091
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2092
"/    bestSelectors := bestSelectors asOrderedCollection.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2093
"/    bestSelectors sort:[:a :b | a size < b size].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2094
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2095
    (selector isUnarySelector and:[ parentNode notNil and:[ parentNode isMessage ]]) ifTrue:[
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2096
        (parentSelector := parentNode selector) isKeyword ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2097
            "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2098
            "/ i.e. look if there is a longer keyword possible
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2099
            newParentSelector := parentSelector,selector.
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2100
            bestSelectors2 := findBest value:(parentNode receiver) value:newParentSelector.
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2101
            bestSelectors2 := bestSelectors2 select:[:sel | sel isKeyword and:[ sel startsWith:parentSelector]].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2102
            bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2103
            bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2104
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2105
            "/ if the parent has a valid selector, offer parenthization
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2106
            (Smalltalk someImplementorOf:parentSelector) notNil ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2107
                offerParenthisationAroundNode := parentNode.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2108
                "/ Transcript show:'2:'; showCR:parentNode.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2109
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2110
        ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2111
            |kwSels|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2112
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2113
            "/ if its a unary message AND the parent is a unary or binary node, 
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2114
            "/ try again, sending the partial message
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2115
            "/ as a keyword to the parent node.
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2116
            "/ this is the case when after "foo binOp bar if", or "foo unOp bar if"
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2117
            "/ which should include ifTrue: in the suggestion result.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2118
            
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2119
            "/ suggestion will transform from (the incorrectly parsed)
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2120
            "/    foo == (shift if)
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2121
            "/
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2122
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2123
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2124
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2125
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2126
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2127
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2128
            "/           arg
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2129
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2130
            "/ into:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2131
            "/    (foo == shift) if
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2132
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2133
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2134
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2135
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2136
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2137
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2138
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2139
            "/           arg
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2140
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2141
            "/ but only do this, if typing to the end of the parent message
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2142
            "/ (i.e. after (foo == shift) <-
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2143
            "/    or after foo bar baz <-
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2144
            "/ not if typing into an existing message
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2145
            "/ (i.e. into foo == shift <- more
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2146
            "/    or into foo bar <- baz
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2147
            codeView characterPositionOfCursor >= parentNode stop ifTrue:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2148
                kwSels := findBest value:parentNode value:selector.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2149
                kwSels := kwSels select:[:sel | sel isKeyword].
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2150
     
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2151
                kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2152
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2153
                bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2154
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2155
                "/ these need to go to bestSelectors (see editAction)
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2156
                parentNodeClassIfKnown := self classOfNode:parentNode.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2157
                (parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2158
                    "/ this is so common, that it deserves a special case:
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2159
                    "/ if we complete an if after some boolean message e.g '(a == b) if'
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2160
                    "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2161
                    bestSelectors := self
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2162
                                        withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2163
                                        from:bestSelectors
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2164
                                        forPartial:selector.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2165
                    kwSels := self
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2166
                                withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2167
                                from:kwSels
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2168
                                forPartial:selector.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2169
     
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2170
                    "/ put keyword selectors in front, because they are very likely
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2171
                    bestSelectors := kwSels , bestSelectors.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2172
                ] ifFalse:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2173
                    "/ put them at the end
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2174
                    bestSelectors := bestSelectors , kwSels.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2175
                ].
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2176
            ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2177
        ]
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2178
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2179
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2180
    (selector isUnarySelector and:[ node isMessage ]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2181
        receiverNodeClassIfKnown := self classOfNode:nodeReceiver.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2182
        (receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2183
            "/ this is so common, that it deserves a special case:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2184
            "/ if we complete an if after some boolean message e.g '(a == b) if'
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2185
            "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2186
            bestSelectors := self
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2187
                                withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2188
                                from:bestSelectors
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2189
                                forPartial:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2190
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2191
    ].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2192
    
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2193
    Verbose == true ifTrue:[    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2194
        Transcript show:'parentNode: '; showCR:parentNode.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2195
        Transcript show:'parentNode: '; showCR:parentNode class.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2196
        Transcript show:'sel: '; showCR:selector.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2197
    ].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2198
    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2199
    canParenthesize := false.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2200
    parentNode notNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2201
        parentNode isMessage ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2202
            (((parentNode selector isUnarySelector not) and:[selector isUnarySelector])
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2203
            or:[ ((parentNode selector isKeyword) and:[selector isBinarySelector]) ]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2204
                canParenthesize := true.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2205
            ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2206
        ] ifFalse:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2207
            offerParenthisationAroundNode isNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2208
                selector isKeyword ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2209
                    offerParenthisationAroundNode := node.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2210
                ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2211
            ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2212
        ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2213
    ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2214
    canParenthesize ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2215
        "/ completing an already existing keyword or binary message with something starting with
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2216
        "/ if, and, or or while.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2217
        "/ Here, offer a special completion which inserts parenthesis / brackets around the already
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2218
        "/ existing message. Do this only, if the existing message makes sense.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2219
        "/    expr wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2220
        "/ ->
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2221
        "/    [expr] whileXX:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2222
        true "((
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2223
            #( 'ifTrue' 'ifFalse' 'and' 'or' 'do' 'keysAndValuesDo' 'whileTrue' 'whileFalse' 'ensure' 'on')
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2224
        ) contains:[:part | part startsWith:selector])" ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2225
            (Smalltalk someImplementorOf:parentNode selector) notNil ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2226
                |selsP selsB|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2227
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2228
                selsP := #( 'ifTrue:' 'ifFalse:' 'and' 'or' 'do' 'keysAndValuesDo' )
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2229
                            select:[:sel | sel startsWith:selector]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2230
                            thenCollect:[:sel | '(',parentNode selector,') ',sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2231
                ( #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' ) contains:[:sel | sel startsWith:selector]) 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2232
                ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2233
                    selsP := selsP copyWith:'(',parentNode selector,') ',selector  
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2234
                ]. 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2235
                selsB := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' )
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2236
                            select:[:sel | sel startsWith:selector]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2237
                            thenCollect:[:sel | '[',parentNode selector,'] ',sel].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2238
                parentNodeToParenthesize := parentNode.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2239
                bestWithParenthesis := selsP , selsB.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2240
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2241
        ].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2242
    ] ifFalse:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2243
        "/ also offer adding brackets for a while expression
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2244
        "/    expr wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2245
        "/ ->
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2246
        "/    [expr] whileXX:[]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2247
        ((
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2248
            #( 'whileTrue' 'whileFalse' 'ensure' 'on')
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2249
        ) contains:[:part | part startsWith:selector]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2250
            (node receiver isBlock) ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2251
                |sels|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2252
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2253
                (node receiver isMessage not
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2254
                or:[ (Smalltalk someImplementorOf:node receiver selector) notNil ]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2255
                    sels := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' )
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2256
                                select:[:sel | sel startsWith:selector]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2257
                                thenCollect:[:sel | '[...] ',sel].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2258
                    parentNodeToParenthesize := node receiver.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2259
                    bestWithParenthesis := sels.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2260
                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2261
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2262
        ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2263
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2264
 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2265
    allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()).
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2266
    self sortSelectors:allBest forSelector:selector lcSelector:lcSelector.
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2267
                        
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2268
    "/ sort: prefixes first.
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2269
    parentSelector notNil ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2270
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2271
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2272
                    by:[:sel | 
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2273
                            (sel asLowercase startsWith:lcSelector) 
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2274
                            or:[sel startsWith:parentSelector]].
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2275
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2276
 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2277
    "/ if receiver is super, always include the method's own selector
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2278
    nodeReceiver isSuper ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2279
        (tree isMethod) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2280
            |mSel|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2281
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2282
            mSel := tree selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2283
            mSel notNil ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2284
                (mSel startsWith:selector) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2285
                    "/ already the word before the cursor?
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2286
                    (mSel ~= selector) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2287
                        allBest remove:mSel ifAbsent:[].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2288
                        allBest addFirst:mSel.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2289
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2290
                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2291
            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2292
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2293
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2294
 
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2295
    "/ another convenient hack; 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2296
    "/ if we have just typed in foo == 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2297
    "/ and the value of foo is a known literal,
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2298
    "/ offer inserting this literal. This is great in a debugger...
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2299
    ( #(#'==' #'=' #'~=' #'~~') includes:selector ) ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2300
        |val|
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2301
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2302
        (val := self valueOfNode:nodeReceiver) notNil ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2303
            offerValueInsertion := true.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2304
            valueToInsert := val storeString.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2305
            nodeReceiver isVariable ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2306
                valueInfo := ' (current value of %1)' bindWith:nodeReceiver name.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2307
            ] ifFalse:[                
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2308
                valueInfo := ' (current value of expression)'.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2309
            ].
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2310
            valueInfo := valueInfo withColor:(Color grey).
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2311
        ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2312
    ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2313
    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2314
    (allBest isEmptyOrNil 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2315
        and:[bestWithParenthesis isEmptyOrNil
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2316
        and:[offerParenthisationAroundNode isNil
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2317
        and:[offerValueInsertion not]]] 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2318
    ) ifTrue:[ 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2319
        ^ self 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2320
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2321
 
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2322
"/    "/ see what is aready sent to this variable inside the code
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2323
"/    "/ and also what is assigned to it.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2324
"/    nodeReceiver notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2325
"/        nodeReceiver isVariable ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2326
"/            rememberedNodes notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2327
"/                selectorsSentInCode := 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2328
"/                    (rememberedNodes
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2329
"/                        select:[:node | 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2330
"/                            node isMessage 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2331
"/                                and:[node receiver isVariable
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2332
"/                                and:[node receiver name = nodeReceiver name]]]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2333
"/                        thenCollect:[:node | 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2334
"/                            node selector]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2335
"/                    ) asSet.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2336
"/            ] ifFalse:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2337
"/                selectorsSentInCode := Set new. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2338
"/                tree allMessageNodesDo:[:msg |
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2339
"/                    (msg receiver isVariable
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2340
"/                        and:[msg receiver name = nodeReceiver name]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2341
"/                    ) ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2342
"/                        selectorsSentInCode add:msg selector
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2343
"/                    ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2344
"/                ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2345
"/                selectorsSentInCode remove:selector ifAbsent:[].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2346
"/            ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2347
"/        ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2348
"/    ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2349
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2350
    nodeReceiver notNil ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2351
        |classOrNil|
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2352
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2353
        classOrNil := self classOfNode:nodeReceiver.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2354
        classOrNil isNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2355
            classesFromAssignmentsToReceiver size == 1 ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2356
                classOrNil := classesFromAssignmentsToReceiver anElement
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2357
            ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2358
        ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2359
        classOrNil notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2360
            selectorsImplementedInClass := classOrNil selectors.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2361
"/            selectorsImplementedInClass := Set new.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2362
"/            classOrNil withAllSuperclassesDo:[:cls |
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2363
"/                cls theNonMetaclass ~~ Object ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2364
"/                    selectorsImplementedInClass addAll:cls selectors.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2365
"/                ]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2366
"/            ]    
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2367
        ]
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2368
    ].    
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2369
    selectorsImplementedInClass notNil ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2370
        "/ the one's implemented in the class itself are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2371
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2372
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2373
                    by:[:sel | selectorsImplementedInClass includes:sel].
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2374
    ].
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2375
    otherMessagesToReceiver "selectorsSentInCode" notNil ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2376
        "/ the one's already sent in the code are moved to the top of the list.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2377
        "/ trouble is: parser bails out on error, so most of the time, we only see
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2378
        "/ selectors sent previously. sigh.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2379
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2380
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2381
                    by:[:sel | otherMessagesToReceiver "selectorsSentInCode" includes:sel].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2382
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2383
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2384
"/ this makes it very slow
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2385
"/false ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2386
"/    srchClass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2387
"/        implClass := srchClass whichClassIncludesSelector:best.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2388
"/    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2389
"/        implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2390
"/        implClass size == 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2391
"/            implClass := implClass first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2392
"/        ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2393
"/            implClass := nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2394
"/        ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2395
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2396
"/
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2397
"/    info := best storeString.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2398
"/    implClass notNil ifTrue:[
5095
71e2684154a4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5092
diff changeset
  2399
"/        info := implClass name , ' » ' , info.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2400
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2401
"/    self information:info.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2402
"/].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2403
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2404
    "/ the one's which are a prefix are moved towards the top of the list
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2405
    allBest := self splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2406
                    by:[:sel | sel notNil and:[sel asLowercase startsWith:lcSelector]].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2407
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2408
    "/ heuristic hack:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2409
    "/ 'i' and 'w' generate lists in which ifXXX / whileXXX are not at the top of the list.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2410
    "/ we know, that those are most often wanted!!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2411
    selector size <= 2 ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2412
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2413
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2414
                    by:[:sel | 
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2415
                        #(ifTrue: ifFalse: isNil notNil whileTrue whileFalse) includes:sel
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2416
                    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2417
    ]. 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2418
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2419
    self sortUsefulSelectorsIn:allBest. "/cosmetics
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2420
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2421
    "/ parenthesizers always at the end.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2422
    bestWithParenthesis notEmptyOrNil ifTrue:[ 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2423
        allBest := allBest , bestWithParenthesis.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2424
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2425
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2426
    "/ self at:1 put:#foo
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2427
    "/ Array new:10
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2428
    offerParenthisationAroundNode notNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2429
        allBest := allBest copyWith:( '(',selector,')' ).
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2430
        parenthesisAroundIndex := allBest size.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2431
    ].
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2432
    offerValueInsertion ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2433
        allBest := allBest copyWith:( '... ',(valueToInsert contractTo:30),valueInfo). 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2434
        valueToInsertIndex := allBest size.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2435
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2436
 
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2437
    editAction :=
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2438
        [:index |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2439
            |crsrPos chosen parenthesisToInsert action|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2440
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2441
            action := nil.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2442
            crsrPos := codeView characterPositionOfCursor.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2443
            chosen := allBest at:index.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2444
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2445
            chosen ~= selector ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2446
                (bestWithParenthesis notNil and:[bestWithParenthesis includes:chosen]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2447
                    "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2448
                    "/   chosen at: 10 if
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2449
                    "/ put parenthesis around, and add ifTrue/ifFalse
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2450
                    "/ i.e.:   (chosen at:10) ifTrue:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2451
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2452
                    "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2453
                    "/   a > 10 wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2454
                    "/ put brackets around and add whileTrue/whileFalse
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2455
                    "/ i.e.:   [a > 10] whileTrue:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2456
                    parenthesisToInsert := chosen first == $( ifTrue:'()' ifFalse:'[]'.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2457
                    chosen := (chosen copyFrom:(chosen lastIndexOf:parenthesisToInsert second)+1) withoutSeparators.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2458
                ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2459
                    (offerParenthisationAroundNode notNil and:[index = parenthesisAroundIndex]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2460
                        "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2461
                        "/      Array new:10
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2462
                        "/ put parenthesis around.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2463
                        "/ i.e.:   (Array new:10)
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2464
                        action :=
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2465
                            [
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2466
                                codeView insertString:'(' atCharacterPosition:offerParenthisationAroundNode start.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2467
                                codeView insertString:')' atCharacterPosition:offerParenthisationAroundNode stop+2.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2468
                                codeView cursorToCharacterPosition:(offerParenthisationAroundNode stop+2); cursorRight.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2469
                            ].
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2470
                    ] ifFalse:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2471
                        (offerValueInsertion and:[index = valueToInsertIndex]) ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2472
                            "/ for input like: 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2473
                            "/      foo == 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2474
                            "/ insert a value
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2475
                            "/ i.e.:   foo == #someSymbol
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2476
                            action :=
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2477
                                [
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2478
                                    codeView characterBeforeCursor isSeparator ifFalse:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2479
                                        codeView insertStringAtCursor:' '.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2480
                                    ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2481
                                    codeView insertStringAtCursor:valueToInsert.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2482
                                    "/ codeView cursorRight.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2483
                                ].
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2484
                        ]
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2485
                    ].    
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2486
                ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2487
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2488
                action isNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2489
                    numArgs := chosen numArgs.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2490
                    (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2491
                        selectorParts := parentNode selectorParts , node selectorParts.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2492
                    ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2493
                        selectorParts := node selectorParts.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2494
                    ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2495
                    nSelParts := selectorParts size.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2496
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2497
                    newParts := chosen asCollectionOfSubstringsSeparatedBy:$:.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2498
                    newParts := newParts select:[:part | part size > 0].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2499
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2500
                    action :=
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2501
                        [
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2502
                            |positionOfFirstArg newCursorPosition stop checkForArgumentTemplates
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2503
                             newPart oldPartialToken start|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2504
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2505
                            checkForArgumentTemplates := (selector isUnarySelector and:[chosen isKeywordSelector]).
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2506
                            numArgs > nSelParts ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2507
                                "/ new selector has more arguments; append them
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2508
                                stop := selectorParts last stop.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2509
                                codeView deleteFromCharacterPosition:stop+1 to:crsrPos-1.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2510
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2511
                                "/ append the rest ...
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2512
                                (numArgs min:newParts size) downTo:(nSelParts+1) do:[:idx |
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2513
                                    |newPart|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2514
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2515
                                    newPart := newParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2516
                                    newPart := newPart , ':'.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2517
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2518
                                    (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2519
                                        newPart := ':' , newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2520
                                    ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2521
                                    newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2522
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2523
                                    codeView replaceFromCharacterPosition:stop to:stop with:newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2524
                                    "/ remember the leftMost replacement's end as new cursor position
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2525
                                    newCursorPosition := stop + newPart size
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2526
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2527
                                checkForArgumentTemplates := true.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2528
                            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2529
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2530
                            "/ replace existing parts
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2531
                            (nSelParts min:newParts size) downTo:1 do:[:idx |
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2532
                                |skipColon|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2533
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2534
                                skipColon := 0.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2535
                                newPart := newParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2536
                                oldPartialToken := selectorParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2537
                                start := oldPartialToken start.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2538
                                stop := oldPartialToken stop.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2539
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2540
                                (chosen endsWith:$:) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2541
                                    (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2542
                                        newPart := newPart , ':'.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2543
                                    ] ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2544
                                        skipColon := 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2545
                                    ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2546
                                ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2547
                                    (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2548
                                        newPart := newPart , ':'
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2549
                                    ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2550
                                        |nextChar|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2551
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2552
                                        nextChar := codeView characterAtCharacterPosition:stop+1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2553
                                        nextChar isSeparator ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2554
                                            nextChar == $. ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2555
                                                newPart := newPart , ' '
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2556
                                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2557
                                        ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2558
                                    ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2559
            "/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2560
            "/                        ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2561
            "/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2562
                                ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2563
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2564
                                oldPartialToken value ~= newPart ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2565
                                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2566
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2567
                                    oldLen := stop - start + 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2568
                                    newLen := newPart size.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2569
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2570
                                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2571
                                    "/ remember the leftMost replacement's end as new cursor position
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2572
                                    newCursorPosition := start + newPart size + skipColon. "/ (newLen-oldLen) + 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2573
                                    "/ codeView cursorToCharacterPosition:newCursorPosition.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2574
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2575
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2576
                            newCursorPosition notNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2577
                                codeView cursorToCharacterPosition:newCursorPosition-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2578
                                codeView cursorRight.  "/ avoid going to the next line !!
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2579
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2580
                            codeView dontReplaceSelectionOnInput.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2581
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2582
                            checkForArgumentTemplates ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2583
                                "/ add opening brackets, etc.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2584
                                self insertAdditonalStuffAfterSelector:chosen.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2585
                            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2586
                            parenthesisToInsert notNil ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2587
                                |sav pos|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2588
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2589
                                sav := codeView characterPositionOfCursor-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2590
                                "/ check if already parenthized
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2591
                                parentNodeToParenthesize hasParentheses ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2592
                                    pos := parentNodeToParenthesize parentheses first first.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2593
                                    codeView selectFromCharacterPosition:pos to:pos.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2594
                                    codeView replaceSelectionBy:(parenthesisToInsert copyFirst:1) asString.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2595
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2596
                                    pos := parentNodeToParenthesize parentheses first last.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2597
                                    codeView selectFromCharacterPosition:pos to:pos.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2598
                                    codeView replaceSelectionBy:(parenthesisToInsert copyLast:1) asString.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2599
                                    codeView cursorToCharacterPosition:sav; cursorRight
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2600
                                ] ifFalse:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2601
                                    codeView insertString:(parenthesisToInsert copyLast:1) atCharacterPosition:node receiver stop+1.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2602
                                    codeView insertString:(parenthesisToInsert copyFirst:1) atCharacterPosition:parentNodeToParenthesize start.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2603
                                    codeView cursorToCharacterPosition:sav+2; cursorRight
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2604
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2605
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2606
                        ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2607
                    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2608
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2609
                codeView
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2610
                    undoableDo:action
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2611
                    info:'Completion'.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2612
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2613
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2614
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2615
    actionBlock value:allBest value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2616
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2617
    "Created: / 10-11-2006 / 13:18:27 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2618
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2619
    "Modified: / 01-05-2016 / 18:36:36 / cg"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2620
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2621
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2622
codeCompletionForMessageTo:node into:actionBlock
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2623
    "find good suggestions for a message send to node, with no input yet.
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2624
     I.e. right after a receiver (w.o. any input yet)"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2625
    
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2626
    |knownClass suggestions selectorsImplementedInClass mostUseful editActions pos|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2627
 
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2628
    (knownClass := self classOfNode:node) isNil ifTrue:[
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2629
        self breakPoint:#cg.
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2630
        self classOfNode:node.
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2631
        ^ self
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2632
    ].
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2633
    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2634
    Verbose == true ifTrue:[ 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2635
        Transcript show:node; show:' -> '; showCR:knownClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2636
    ].    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2637
    selectorsImplementedInClass := Set new.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2638
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2639
    knownClass withAllSuperclassesDo:[:cls |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2640
        cls ~~ Object ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2641
            selectorsImplementedInClass addAll:cls selectors.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2642
        ]    
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2643
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2644
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2645
    knownClass isMeta ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2646
        selectorsImplementedInClass := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2647
            selectorsImplementedInClass reject:[:sel |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2648
                |mthd|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2649
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2650
                mthd := knownClass lookupMethodFor:sel.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2651
                mthd notNil and:[mthd category startsWith: 'documentation']
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2652
            ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2653
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2654
        knownClass theNonMetaclass isAbstract ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2655
            mostUseful := selectorsImplementedInClass select:[:sel |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2656
                            knownClass implements:sel
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2657
                          ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2658
        ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2659
            mostUseful := selectorsImplementedInClass select:[:sel |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2660
                                |mthd|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2661
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2662
                                mthd := knownClass lookupMethodFor:sel.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2663
                                mthd notNil and:[mthd category startsWith: 'instance']
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2664
                          ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2665
        ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2666
    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2667
        mostUseful := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2668
            #(
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2669
                "/ blocks
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2670
                ifTrue: ifFalse: whileTrue: whileFalse: on:do: ensure: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2671
                whileTrue whileFalse loop
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2672
                "/ any
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2673
                isNil notNil isEmpty notEmpty 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2674
            ).
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2675
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2676
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2677
    mostUseful notNil ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2678
        suggestions := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2679
            (selectorsImplementedInClass select:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2680
            ,
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2681
            (selectorsImplementedInClass reject:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2682
    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2683
        suggestions := selectorsImplementedInClass asNewOrderedCollection sort.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2684
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2685
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2686
    suggestions := suggestions reject:[:sel | sel first == $_].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2687
    self sortUsefulSelectorsIn:suggestions. "/cosmetics
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2688
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2689
    pos := codeView characterPositionOfCursor.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2690
    editActions := suggestions collect:[:word |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2691
                        self editActionToReplaceCodeFrom:pos to:pos-1 by:word.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2692
                   ].                
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2693
    actionBlock value:suggestions value:editActions value:nil.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2694
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2695
    "Created: / 01-05-2016 / 17:01:21 / cg"
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2696
    "Modified: / 01-05-2016 / 18:54:03 / cg"
4238
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
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2699
codeCompletionForMethodSpec:node
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2700
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2701
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2702
    self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2703
	codeCompletionForMethodSpec:node
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2704
	into:
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2705
	    [:suggestions :action :whatIsIt |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2706
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2707
	    |chosen|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2708
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2709
	    chosen := self askUserForCompletion:whatIsIt for:codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2710
			   at:node start from:suggestions.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2711
	    chosen notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2712
		action value:(suggestions indexOf:chosen)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2713
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2714
	].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2715
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2716
"/    |crsrPos
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2717
"/     selectorSoFar matchingSelectors
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2718
"/     selectors distances best rest
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2719
"/     allExistingMethods nameBag namesByCount selectors1 selectors2|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2720
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2721
"/    crsrPos := codeView characterPositionOfCursor - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2722
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2723
"/    selectorSoFar := ''.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2724
"/    node selectorParts doWithIndex:[:partToken :argNr|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2725
"/        |part|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2726
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2727
"/        part := partToken value.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2728
"/        selectorSoFar := selectorSoFar , part.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2729
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2730
"/        (crsrPos >= partToken start
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2731
"/        and:[crsrPos <= partToken stop]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2732
"/            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2733
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2734
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2735
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2736
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2737
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2738
"/                                        md := eachClass theMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2739
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2740
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2741
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2742
"/                "/ dont forget the stuff in the class-line
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2743
"/                Metaclass withAllSuperclassesDo:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2744
"/                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2745
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2746
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2747
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2748
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2749
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2750
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2751
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2752
"/                                        md := eachClass theNonMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2753
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2754
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2755
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2756
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2757
"/            selectors := matchingSelectors asOrderedCollection.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2758
"/
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2759
"/            "/ if there is only one, and user has already entered it, he might want to complete the argument-name
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2760
"/            (selectors size == 1
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2761
"/            and:[selectors first = selectorSoFar]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2762
"/                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2763
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2764
"/                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2765
"/                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2766
"/                nameBag := Bag new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2767
"/                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2768
"/                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2769
"/                "/ take the one which occurs most often
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2770
"/                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
  2771
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2772
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2773
"/                    undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2774
"/                        (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2775
"/                            codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2776
"/                        ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2777
"/                            codeView insertString:best atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2778
"/                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2779
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2780
"/                    info:'completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2781
"/                codeView cursorToCharacterPosition:(crsrPos + best size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2782
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2783
"/                "the ones implemented in superclasses are shown first"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2784
"/                classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2785
"/                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2786
"/                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2787
"/                ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2788
"/                    selectors1 := selectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2789
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2790
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2791
"/                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2792
"/                distances sortWith:selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2793
"/                selectors1 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2794
"/                selectors := selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2795
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2796
"/                selectors2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2797
"/                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2798
"/                    distances sortWith:selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2799
"/                    selectors2 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2800
"/                    selectors1 := selectors1 collect:[:sel | sel allBold].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2801
"/                    selectors := selectors1,selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2802
"/                ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2803
"/
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2804
"/                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2805
"/                best isNil ifTrue:[^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2806
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2807
"/                rest := best copyFrom:selectorSoFar size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2808
"/                codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2809
"/                    undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2810
"/                        codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2811
"/                            replaceFromCharacterPosition:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2812
"/                            to:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2813
"/                            with:rest
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2814
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2815
"/                    info:'Completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2816
"/                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2817
"/            ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2818
"/            codeView cursorRight. "/ kludge to make it visible
4352
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
"/    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2821
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2822
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2823
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2824
    "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
  2825
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2826
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2827
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2828
codeCompletionForMethodSpec:node into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2829
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2830
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2831
    |crsrPos crsrLine crsrCol
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2832
     selectorSoFar matchingSelectors
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2833
     selectors distances
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2834
     allExistingMethods nameBag namesByCount 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2835
     allSelectors
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2836
     selectorsForIsXXXTests selectorsSentInClass selectorsImplementedInSuper 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2837
     editAction editActionForArg argNames selectorsForVars
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2838
     selectorTypedSoFar addIfNotYetImplemented alreadyOK|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2839
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2840
    allSelectors := Set new.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2841
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2842
    "/ Transcript showCR:'m'.
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2843
    crsrLine := codeView cursorLine.
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2844
    crsrCol := codeView cursorCol.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2845
    crsrPos := codeView characterPositionOfCursor - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2846
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2847
    selectorTypedSoFar := node selector.
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2848
    selectorTypedSoFar isUnarySelector ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2849
        "/ user has just begun to edit a selector.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2850
        "/ often, a good completion are the names of instVars for which no corresponding getter/setter exists
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2851
        classOrNil notNil ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2852
            selectorsForVars := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2853
            selectorsImplementedInSuper := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2854
            selectorsSentInClass := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2855
            selectorsForIsXXXTests := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2856
            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2857
            addIfNotYetImplemented :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2858
                [:list :sel |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2859
                    sel ~= selectorTypedSoFar ifTrue:[    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2860
                        (allSelectors includes:sel) ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2861
                            (classOrNil implements:sel asSymbol) ifFalse:[ 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2862
                                selectorsForVars add:sel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2863
                                allSelectors add:sel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2864
                            ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2865
                        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2866
                    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2867
                ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2868
                
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2869
            classOrNil instVarNames do:[:nm |
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2870
                (nm startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2871
                    addIfNotYetImplemented value:selectorsForVars value:nm.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2872
                    addIfNotYetImplemented value:selectorsForVars value:(nm,':').
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2873
                 ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2874
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2875
            classOrNil isMeta ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2876
                classOrNil theNonMetaclass classVarNames do:[:nm |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2877
                    |nmSel|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2878
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2879
                    nmSel := nm asLowercaseFirst.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2880
                    (nmSel startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2881
                        addIfNotYetImplemented value:selectorsForVars value:nmSel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2882
                        addIfNotYetImplemented value:selectorsForVars value:(nmSel,':').
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2883
                    ]
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2884
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2885
            ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2886
                "/ isXXX ?
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2887
                (('is',classOrNil nameWithoutPrefix) startsWith:selectorTypedSoFar ) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2888
                    addIfNotYetImplemented value:selectorsForIsXXXTests value:('is',classOrNil nameWithoutPrefix).
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2889
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2890
            ].
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2891
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2892
            "/ and also messages sent by the class itself
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2893
            classOrNil methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2894
                m messagesSentToSelf do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2895
                    (sel startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2896
                        addIfNotYetImplemented value:selectorsSentInClass value:sel.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2897
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2898
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2899
            ].
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2900
            classOrNil isMeta ifFalse:[
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2901
                classOrNil theMetaclass methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2902
                    m messagesSent do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2903
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2904
                            addIfNotYetImplemented value:selectorsSentInClass value:sel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2905
                        ]                     
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2906
                    ]                     
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2907
                ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2908
            ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2909
            "/ and also messages implemented by superclasses (except Object)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2910
            classOrNil allSuperclassesDo:[:eachSuperclass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2911
                eachSuperclass ~~ Object ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2912
                    eachSuperclass methodDictionary keysDo:[:sel |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2913
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2914
                            addIfNotYetImplemented value:selectorsImplementedInSuper value:sel.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2915
                        ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2916
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2917
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2918
            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2919
        ].
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2920
    ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2921
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2922
    selectorSoFar := ''.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2923
    matchingSelectors := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2924
    
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2925
    node selectorParts doWithIndex:[:partToken :argNr|
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2926
        |part|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2927
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2928
        part := partToken value.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2929
        selectorSoFar := selectorSoFar , part.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2930
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2931
        (crsrPos >= partToken start 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2932
            and:[crsrPos <= partToken stop
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2933
                 or:[ (crsrPos == (partToken stop+1))
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2934
                      and:[codeView characterBeforeCursor == Character space]] ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2935
        ) ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2936
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2937
                Smalltalk 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2938
                    allClassesDo:[:eachClass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2939
                        |md|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2940
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2941
                        md := eachClass theMetaclass methodDictionary.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2942
                        matchingSelectors addAll:(md keys 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2943
                                                    select:[:sel |sel startsWith:selectorSoFar]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2944
                    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2945
                "/ do not forget the stuff in the class-line
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2946
                Metaclass withAllSuperclassesDo:[:cls |
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2947
                    matchingSelectors addAll:(cls methodDictionary keys 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2948
                                                select:[:sel |sel startsWith:selectorSoFar]).
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2949
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2950
            ] ifFalse:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2951
                Smalltalk 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2952
                    allClassesDo:[:eachClass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2953
                        |md|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2954
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2955
                        md := eachClass theNonMetaclass methodDictionary.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2956
                        matchingSelectors addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2957
                    ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2958
            ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2959
        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2960
    ].  
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2961
    alreadyOK := matchingSelectors includes:selectorTypedSoFar.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2962
    matchingSelectors remove:selectorTypedSoFar ifAbsent:[].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2963
    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2964
    selectors := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2965
    selectors addAll:matchingSelectors.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2966
            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2967
    selectorsForVars notNil ifTrue:[ selectors addAll:selectorsForVars ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2968
    selectorsSentInClass notNil ifTrue:[ selectors addAll:selectorsSentInClass ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2969
    selectorsImplementedInSuper notNil ifTrue:[ selectors addAll:selectorsImplementedInSuper ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2970
    selectorsForIsXXXTests notNil ifTrue:[ selectors addAll:selectorsForIsXXXTests ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2971
        
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2972
    selectors := selectors asOrderedCollection.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2973
    selectors sort:[:a :b | a size < b size].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2974
    selectorsForVars notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2975
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2976
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2977
                        by:[:sel | selectorsForVars includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2978
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2979
    selectorsSentInClass notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2980
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2981
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2982
                        by:[:sel | selectorsSentInClass includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2983
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2984
    selectorsImplementedInSuper notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2985
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2986
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2987
                        by:[:sel | selectorsImplementedInSuper includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2988
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2989
    selectorsForIsXXXTests notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2990
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2991
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2992
                        by:[:sel | selectorsForIsXXXTests includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2993
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2994
    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2995
    selectors size > 100 ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2996
        selectors := selectors copyTo:100.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2997
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2998
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2999
    "/ if there is only one, and user has already entered it, 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3000
    "/ he might want to complete the argument-name
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3001
    (alreadyOK and:[selectorSoFar numArgs > 0]) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3002
        allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3003
                                    collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3004
        nameBag := Bag new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3005
        allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3006
        namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3007
        namesByCount := namesByCount copyToMax:5.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3008
        
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3009
        "/ take the one which occurs most often
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3010
        argNames := (namesByCount collect:[:a | a key]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3011
        argNames do:[:eachArgName |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3012
            selectors add:('%1 %2 %3' 
5089
9592bdeeff69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5086
diff changeset
  3013
                            bindWith:(selectorSoFar withColor:Color darkGrey) 
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3014
                            with:eachArgName
5089
9592bdeeff69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5086
diff changeset
  3015
                            with:('(argument)' allItalic withColor:Color darkGrey)).
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3016
        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3017
        
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3018
        editActionForArg :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3019
                [:chosenItem |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3020
                    |chosenName|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3021
                    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3022
                    chosenName := chosenItem 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3023
                                    copyFrom:(selectorSoFar size+2)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3024
                                    to:(chosenItem indexOfSeparatorStartingAt:selectorSoFar size+2)-1.
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3025
                    codeView
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3026
                        undoableDo:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3027
                            (crsrPos+1) >= codeView contents size ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3028
                                codeView paste:chosenName.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3029
                                codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3030
                            ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3031
                                codeView cursorToCharacterPosition:crsrPos.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3032
                                codeView cursorRight.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3033
                                codeView insertStringAtCursor:chosenName.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3034
                                codeView selectFromCharacterPosition:crsrPos+1 to:crsrPos+1+chosenName size-1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3035
                                codeView dontReplaceSelectionOnInput
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3036
                            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3037
                        ]
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3038
                        info:'argname completion'.
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3039
                ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3040
    ].            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3041
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3042
    "/ no, still more possibilities for the selector.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3043
    "/ the ones implemented in superclasses are shown first.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3044
    classOrNil notNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3045
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3046
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3047
                        by:[:sel | classOrNil superclass implements:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3048
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3049
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3050
"/"/    distances := selectors collect:[:each | each spellAgainst:selectorSoFar].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3051
"/"/    distances sortWith:selectors.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3052
"/"/    selectors reverse.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3053
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3054
    editAction :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3055
        [:selectedCompletionIndex |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3056
            |chosen rest|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3057
            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3058
            chosen := selectors at:selectedCompletionIndex.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3059
            (editActionForArg notNil and:[ chosen includesSeparator ]) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3060
                editActionForArg value:chosen.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3061
            ] ifFalse:[    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3062
                rest := chosen copyFrom:selectorSoFar size + 1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3063
                codeView
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3064
                    undoableDo:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3065
                        codeView insertString:rest atLine:crsrLine col:crsrCol.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3066
                    ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3067
                    info:'Completion'.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3068
                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3069
                codeView cursorRight. "/ kludge to make it visible
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3070
            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3071
        ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3072
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3073
    actionBlock
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3074
        value:selectors
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3075
        value:editAction
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3076
        value:'selector'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3077
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3078
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3079
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3080
    "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
  3081
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3082
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3083
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3084
codeCompletionForTempVariable:node into:actionBlock
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3085
!
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3086
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3087
codeCompletionForVariable:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3088
    |nonMetaClass crsrPos nm parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3089
     allVariables allDistances variablesAlreadyAdded nodeVal
5081
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3090
     char getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3091
     globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart editActions suggestions nameIsOK longerNames setOfNames otherArgNames
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3092
     suggestionsWithInfo isLeftSideOfAssignment|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3093
 
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  3094
    "/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3095
    classOrNil notNil ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3096
        nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3097
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3098
 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3099
    nm := node name.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3100
    parent := node parent.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3101
    isLeftSideOfAssignment := false.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3102
    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3103
    (parent notNil) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3104
        (parent isMessage) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3105
            node == parent receiver ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3106
                selectorOfMessageToNode := parent selector
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3107
            ]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3108
        ] ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3109
            (parent isAssignment) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3110
                isLeftSideOfAssignment := (node == node parent variable).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3111
            ].    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3112
        ].    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3113
    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3114
                    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3115
    crsrPos := codeView characterPositionOfCursor.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3116
 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3117
    "/ 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
  3118
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3119
    "/ If the variable represents a global, present its instance creation messages
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3120
    char := codeView characterBeforeCursor. 
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3121
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3122
    (isLeftSideOfAssignment not and:[char == Character space]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3123
        nm knownAsSymbol ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3124
            classOrNil isNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3125
                nodeVal := Smalltalk at:nm asSymbol.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3126
            ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3127
                nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3128
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3129
            nodeVal isBehavior ifTrue:[
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3130
                |selectors selectors1 selectors2|
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3131
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3132
                selectors1 := OrderedSet new.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3133
                selectors2 := OrderedSet new.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3134
                nodeVal class 
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3135
                    withAllSuperclassesDo:[:cls |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3136
                        cls methodDictionary keysAndValuesDo:[:sel :mthd |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3137
                            |cat|
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3138
                            cat := mthd category asLowercase.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3139
                            cat = 'instance creation' ifTrue:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3140
                                selectors1 add:sel
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3141
                            ] ifFalse:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3142
                                "/ other category: look if it sends new, new: etc.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3143
                                (mthd messagesSent includesAny:#(new new: basicNew basicNew:)) ifTrue:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3144
                                    selectors2 add:sel
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3145
                                ].    
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3146
                            ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3147
                        ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3148
                    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3149
 
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3150
                selectors := selectors1 order sort , #('-') , selectors2 order sort.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3151
                editActions := selectors collect:[:word | self editActionToInsert:word].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3152
                actionBlock value:selectors value:editActions value:nil.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3153
"/                editAction :=
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3154
"/                    [:answer |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3155
"/                        |s|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3156
"/                        s := answer isInteger ifTrue:[selectors at:answer] ifFalse:[answer].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3157
"/                        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3158
"/                            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3159
"/                                codeView insertString:s atCharacterPosition:crsrPos.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3160
"/                                codeView cursorToCharacterPosition:crsrPos+s size.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3161
"/                            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3162
"/                            info:'completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3163
"/                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3164
"/                actionBlock value:selectors value:editAction value:nil.
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3165
                ^ self.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3166
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3167
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3168
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3169
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3170
    "/ this is pure voodoo magic (tries to make a good spelling weight,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3171
    "/ by weighting the number of startsWith characters into the spelling distance...)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3172
    getDistanceComputeBlockWithWeight :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3173
        [:weight |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3174
            [:each |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3175
                |dist factor|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3176
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3177
                dist := each spellAgainst:nm.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3178
                factor := 1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3179
5027
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3180
                "/ bump the weight-factor if the name string is included
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3181
                (each includesString:nm) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3182
                    (each startsWith:nm) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3183
                        factor := 6 * weight * nm size.
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3184
                    ] ifFalse:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3185
                        nm size > 1 ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3186
                            factor := 4 * weight * nm size
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3187
                        ].    
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3188
                    ].    
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3189
                ] ifFalse:[
5027
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3190
                    (each includesString:nm caseSensitive:false) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3191
                        (each asLowercase startsWith:nm asLowercase) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3192
                            factor := 4 * weight * nm size.
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3193
                        ] ifFalse:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3194
                            nm size > 1 ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3195
                                factor := 2 * weight * nm size.
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3196
                            ]
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3197
                        ]
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3198
                    ]
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3199
                ].    
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3200
                dist := dist + (weight*factor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3201
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3202
                each -> (dist * weight)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3203
             ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3204
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3205
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3206
    nameIsOK := false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3207
    addWithFactorBlock :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3208
        [:eachNames :factor |
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3209
            |distanceComputeBlock|
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3210
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3211
            distanceComputeBlock := (getDistanceComputeBlockWithWeight value:factor).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3212
            eachNames do:[:nameToAdd |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3213
                (nameToAdd = nm) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3214
                    nameIsOK := true
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3215
                ] ifFalse:[ "/ not again
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3216
                    (variablesAlreadyAdded includes:nameToAdd) ifFalse:[  "/ not again
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3217
                        variablesAlreadyAdded add:nameToAdd.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3218
                        allVariables add:nameToAdd.
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3219
                        allDistances add:(distanceComputeBlock value:nameToAdd).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3220
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3221
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3222
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3223
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3224
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3225
    nm isUppercaseFirst ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3226
        globalFactor := 2.    "/ favour globals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3227
        localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3228
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3229
        globalFactor := 1.    "/ favour locals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3230
        localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3231
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3232
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3233
    variablesAlreadyAdded := Set new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3234
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3235
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3236
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3237
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3238
    (parent notNil
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3239
    and:[parent isMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3240
    and:[parent arguments includes:node]]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3241
        "/ yes -
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3242
        "/ now that's cool: look how the name of this argument is in other implementations
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3243
        "/ of this method, and take that as a basis of the selection
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3244
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3245
        implementors := SystemBrowser
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3246
                            findImplementorsOf:(parent selector)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3247
                            in:(Smalltalk allClasses)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3248
                            ignoreCase:false.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3249
        "/ which argument is it
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3250
        argIdx := parent arguments indexOf:node.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3251
        implementors size > 50 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3252
            implementors := implementors asOrderedCollection copyTo:50.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3253
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3254
        namesUsed := implementors
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3255
                        collect:[:eachImplementor |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3256
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3257
                            parseTree := eachImplementor parseTree.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3258
                            (parseTree notNil and:[parseTree arguments size > 0])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3259
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3260
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3261
                        thenSelect:[:a | a notNil].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3262
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3263
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3264
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3265
        "/ try some commonly used arg names, such as aBoolean, anInteger, etc.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3266
        nm size > 1 ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3267
            |tryClassNamesWith|
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3268
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3269
            ((nm startsWith:'a') and:[(nm at:2) isUppercase]) ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3270
                tryClassNamesWith := 'a'
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3271
            ] ifFalse:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3272
                (nm size > 2 and:[ (nm startsWith:'an') and:[(nm at:3) isUppercase]]) ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3273
                    tryClassNamesWith := 'an'.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3274
                ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3275
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3276
            tryClassNamesWith notNil ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3277
                addWithFactorBlock 
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3278
                    value:(Smalltalk keys 
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3279
                            collect:[:className | tryClassNamesWith,className]
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3280
                            thenSelect:[:name | name startsWith:nm])
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3281
                    value:(1.5 * localFactor)
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3282
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3283
        ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3284
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3285
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3286
            "/ also, look for the keyword before the argument,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3287
            "/ and see if there is such an instVar
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3288
            "/ if so, add it with -Arg
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3289
            parent selector isKeyword ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3290
                kwPart := parent selector keywords at:argIdx.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3291
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3292
                    addWithFactorBlock
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3293
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3294
                        value:(1 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3295
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3296
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3297
            "/ look for the variable names of any other method in that class
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3298
            otherArgNames := Set new.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3299
            classOrNil methodDictionary keysAndValuesDo:[:sel :mthd |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3300
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3301
                            parseTree := mthd parseTree.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3302
                            (parseTree notNil and:[parseTree arguments size > 0])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3303
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3304
                                ifTrue:[ otherArgNames addAll:(parseTree arguments collect:[:each | each name])] ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3305
            addWithFactorBlock value:otherArgNames value:(1.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3306
        ].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3307
        addWithFactorBlock 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3308
            value:(codeView previousReplacements 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3309
                                    collect:[:p | p value asString]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3310
                                    thenSelect:[:s | s isValidSmalltalkIdentifier]) 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3311
            value:(1.3 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3312
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3313
        "/ locals in the block/method
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3314
        |names nameSpace|
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3315
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3316
        names := OrderedCollection withAll:node allVariablesOnScope.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3317
        setOfNames := Set withAll:names.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3318
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3319
        rememberedScopeNodes notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3320
            "/ notNil when a parseError occurred.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3321
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3322
                (eachScope isMethod or:[eachScope isBlock]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3323
                    eachScope argumentNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3324
                        (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3325
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3326
                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3327
                    eachScope isSequence ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3328
                        eachScope temporaryNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3329
                            (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3330
                        ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3331
                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3332
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3333
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3334
                "/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3335
            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3336
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3337
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3338
                eachScope variableNodesDo:[:var |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3339
                    (setOfNames includes:var name) ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3340
                        names add:var name. setOfNames add:var name
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3341
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3342
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3343
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3344
        ] ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3345
            "/ tree must be there; in order to get as-yet-undeclared method locals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3346
            "/ (further down the code), add them also
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3347
            tree variableNodesDo:[:var |
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3348
                |name|
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3349
                
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3350
                name := var name.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3351
                (name first isLowercase or:[isLeftSideOfAssignment not]) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3352
                    (setOfNames includes:name) ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3353
                        names add:name. 
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3354
                        setOfNames add:name
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3355
                    ]
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3356
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3357
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3358
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3359
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3360
        addWithFactorBlock value:names value:(4 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3361
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3362
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3363
            "/ instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3364
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3365
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3366
            "/ inherited instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3367
            classOrNil superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3368
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3369
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3370
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3371
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3372
        "/ magic:
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3373
        "/ if the node to be expanded is the receiver in a message, look for the selector sent to it
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3374
        "/ give names which respond to those messages a higher weight
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3375
        selectorOfMessageToNode notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3376
            |responders nonResponders|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3377
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3378
            "/ responding to that messsage
4365
fda4ed5a9772 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4364
diff changeset
  3379
"/ self halt.
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3380
            classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3381
                "/ private classes
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3382
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3383
                                   value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3384
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3385
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3386
                names := nonMetaClass classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3387
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3388
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3389
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3390
                addWithFactorBlock value:responders value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3391
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3392
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3393
                "/ superclass var names
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3394
                nonMetaClass allSuperclassesDo:[:superClass |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3395
                    names := superClass classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3396
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3397
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3398
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3399
                    addWithFactorBlock value:responders value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3400
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3401
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3402
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3403
                isLeftSideOfAssignment ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3404
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3405
                    classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3406
                        names := classOrNil topNameSpace keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3407
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3408
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3409
                        responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3410
                        nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3411
                        addWithFactorBlock value:responders value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3412
                        addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3413
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3414
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3415
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3416
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3417
            isLeftSideOfAssignment ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3418
                "/ globals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3419
                names := Smalltalk keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3420
                names := names reject:
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3421
                                [:nm |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3422
                                    (nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3423
                                ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3424
                names := names reject:[:nm | nm startsWith:'Undeclared:::' ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3425
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3426
                names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3427
                responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3428
                nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3429
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3430
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3431
            ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3432
            
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3433
            isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3434
                classOrNil notNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3435
                    "/ pool variables
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3436
                    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3437
                        |pool names|
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3438
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3439
                        pool := Smalltalk at:poolName.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3440
                        names := pool classVarNames.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3441
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3442
                        responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3443
                        nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3444
                        addWithFactorBlock value:responders value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3445
                        addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3446
                    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3447
                ]
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3448
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3449
        ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3450
            classOrNil notNil ifTrue:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3451
                isLeftSideOfAssignment ifFalse:[ 
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3452
                    "/ private classes
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3453
                    addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3454
                                       value:(2.75 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3455
                ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3456
                
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3457
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3458
                addWithFactorBlock value:nonMetaClass classVarNames value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3459
                nonMetaClass superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3460
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3461
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3462
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3463
                isLeftSideOfAssignment ifFalse:[ 
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3464
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3465
                    classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3466
                        names := classOrNil topNameSpace keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3467
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3468
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3469
                        addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3470
                    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3471
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3472
                    ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3473
                        names := nameSpace isNameSpace ifTrue:[nameSpace keys] ifFalse:[nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3474
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3475
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3476
                        addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3477
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3478
                ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3479
                isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3480
                    "/ pool variables
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3481
                    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3482
                        |pool names|
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3483
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3484
                        pool := Smalltalk at:poolName.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3485
                        pool isNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3486
                            Transcript showCR:'non existent pool: ',poolName
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3487
                        ] ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3488
                            names := pool classVarNames.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3489
                            addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3490
                        ]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3491
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3492
                ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3493
            ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3494
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3495
            isLeftSideOfAssignment ifFalse:[ 
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3496
                "/ globals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3497
                names := OrderedCollection new.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3498
                Smalltalk keysDo:[:k |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3499
                    (k isUppercaseFirst
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3500
                    and:[ (k startsWith:'Undeclared:::') not
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3501
                    and:[ ((k includes:$:) and:[ (k includesString:'::') not]) not ]]) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3502
                        names add:k
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3503
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3504
                ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3505
            
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3506
                "/ only consider all globals, if the first char of the completed name is uppercase;
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3507
                "/ otherwise, only consider names with a caseInsensitve prefix match
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3508
                nm first isUppercase ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3509
                    names := names select:[:globalName | globalName asLowercase startsWith: nm].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3510
                ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3511
                addWithFactorBlock value:names value:(1.5 * globalFactor).
4665
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3512
            ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3513
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3514
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3515
        isLeftSideOfAssignment ifFalse:[ 
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3516
            "/ pseudos - assuming that thisContext is seldom used.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3517
            "/ also assuming, that nil is short so its usually typed in.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3518
            addWithFactorBlock value:#('self') value:(2.5 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3519
            addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3520
            addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3521
            addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3522
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3523
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3524
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3525
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3526
4410
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3527
"/ nope (foo := foo + 1) should be possible!!
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3528
"/    (parent notNil and:[parent isAssignment]) ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3529
"/        "/ remove the left side of the assignment (to avoid foo := foo suggestions)
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3530
"/        |i|
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3531
"/
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3532
"/        i := allDistances findFirst:[:entry | entry key = parent variable name].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3533
"/        i ~~ 0 ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3534
"/            allDistances removeAtIndex:i
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3535
"/        ].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3536
"/    ].
4385
d3381caeb327 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
  3537
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3538
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3539
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3540
                                                           ifTrue:[el]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3541
                                                           ifFalse:[best]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3542
                                                    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3543
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3544
    allDistances sort:[:a :b |
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3545
                                a value > b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3546
                                    true
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3547
                                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3548
                                    a value = b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3549
                                        a key < b key
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3550
                                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3551
                                        false
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3552
                                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3553
                                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3554
                      ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3555
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3556
    allTheBest := allDistances.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3557
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3558
    nameIsOK ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3559
        "/ if the name already exists, only allow longer names, if there are
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3560
        longerNames := allTheBest select:[:assoc | assoc key startsWith:nm].
5033
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3561
        longerNames size < 30 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3562
            longerNames := allTheBest select:[:assoc | assoc key includesString:nm caseSensitive:false].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3563
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3564
        longerNames isEmpty ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3565
            "/ no better name
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3566
            ^ self
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3567
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3568
        allTheBest := longerNames.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3569
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3570
5033
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3571
    allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3572
        allTheBest := allTheBest copyTo:20.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3573
"/        "/ remove all those which are below some threshold or are a prefix
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3574
"/        0.2 to:0.9 by:0.1 do:[:delta |
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3575
"/            |bestValue n|
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3576
"/            
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3577
"/            "/ if still too many, remove more and more
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3578
"/            allTheBest size > 50 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3579
"/                bestValue := bestAssoc value * delta.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3580
"/                n := allTheBest select:[:entry | (entry key startsWith:nm) or:[ entry value >= bestValue ]].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3581
"/                n size >= 15 ifTrue:[ allTheBest := n ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3582
"/            ]
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3583
"/        ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3584
"/        allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3585
"/            "/ remove all those which are below some threshold
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3586
"/            0.2 to:0.9 by:0.1 do:[:delta |
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3587
"/                |bestValue n|
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3588
"/                "/ if still too many, remove more and more
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3589
"/                allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3590
"/                    bestValue := bestAssoc value * delta.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3591
"/                    allTheBest := allTheBest select:[:entry | entry value >= bestValue ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3592
"/                ]
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3593
"/            ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3594
"/        ].
4238
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
    suggestions := allTheBest collect:[:assoc | assoc key].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3597
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3598
    "/ finally, the trick is to bring them into a reasonable order...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3599
    "/ sort the prefix matchers by length, the others by spelling distance
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3600
    "/ and bring the prefix-matchers towards the beginning
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3601
    suggestions := ((suggestions select:[:s | s startsWith:nm]) sort:[:a :b | a size < b size ])
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3602
                   ,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3603
                   (suggestions reject:[:s | s startsWith:nm]).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3604
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3605
    "/ if super is among them, add a full call to the completions
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3606
    (suggestions includes:'super') ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3607
        (tree notNil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3608
        and:[ tree isMethod ]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3609
            Error handle:[:ex |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3610
                Transcript showCR:'parse error in code completion ignored'.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3611
            ] do:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3612
                suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.').
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3613
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3614
        ].
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3615
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3616
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3617
    suggestionsWithInfo := 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3618
        suggestions 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3619
            collect:[:eachName |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3620
                |val kind valAndKind printString|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3621
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3622
                valAndKind := self valueAndKindOfVariable:eachName.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3623
                valAndKind isNil ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3624
                    eachName
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3625
                ] ifFalse:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3626
                    val := valAndKind first.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3627
                    kind := valAndKind second.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3628
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3629
                    val isBehavior ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3630
                        val isLoaded ifFalse:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3631
                            eachName,' (= ', ('autoloaded class in ',(val category ? 'unknown category')) allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3632
                        ] ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3633
                            val isNameSpace ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3634
                                eachName,' ( ', 'namespace' allItalic,' )'
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3635
                            ] ifFalse:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3636
                                eachName,' (= ', ('class in ',(val category ? 'unknown category')) allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3637
                            ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3638
                        ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3639
                    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3640
                        "/ Parser findBest:30 selectorsFor:'isLite' in:nil forCompletion:true
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3641
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3642
                        (val isLiteral and:[ (printString := val printString) size < 15 ]) ifTrue:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3643
                            eachName,' (= ',printString allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3644
                        ] ifFalse:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3645
                            eachName,' (= ',val classNameWithArticle allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3646
                        ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3647
                    ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3648
                ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3649
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3650
5081
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3651
    editActions := suggestions collect:[:word |
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3652
                     self editActionToReplaceNode:node by:word.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3653
                   ].        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3654
    actionBlock value:suggestionsWithInfo value:editActions value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3655
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3656
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3657
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3658
    "Modified: / 01-05-2016 / 18:45:07 / cg"
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3659
!
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3660
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3661
editActionToInsert:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3662
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3663
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3664
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3665
                codeView insertSelectedStringAtCursor:aString.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3666
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3667
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3668
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3669
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3670
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3671
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3672
editActionToInsertFromSuggestions:suggestions
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3673
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3674
        |answer|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3675
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3676
        answer := suggestions at:index.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3677
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3678
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3679
                codeView insertSelectedStringAtCursor:answer.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3680
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3681
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3682
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3683
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3684
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3685
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3686
editActionToReplaceCodeFrom:start to:stop by:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3687
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3688
        |oldVar oldLen newLen insertWithSpace|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3689
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3690
        insertWithSpace := false.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3691
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3692
        start <= stop ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3693
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3694
        ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3695
            codeView characterBeforeCursor == Character space ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3696
                insertWithSpace := true.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3697
            ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3698
        ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3699
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3700
        oldLen := stop - start + 1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3701
        newLen := aString size.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3702
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3703
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3704
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3705
                insertWithSpace ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3706
                    codeView insertSelectedStringAtCursor:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3707
                ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3708
                    codeView replaceFromCharacterPosition:start to:stop with:aString.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3709
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3710
                    (aString startsWith:oldVar) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3711
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3712
                    ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3713
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3714
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3715
                ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3716
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3717
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3718
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3719
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3720
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3721
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3722
    "Created: / 01-05-2016 / 18:47:40 / cg"
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3723
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3724
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3725
editActionToReplaceCodeFrom:start to:stop byWordIn:suggestions
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3726
    ^ [:index |
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3727
        |answer oldVar oldLen newLen insertWithSpace|
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3728
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3729
        insertWithSpace := false.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3730
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3731
        answer := suggestions at:index.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3732
        start <= stop ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3733
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3734
        ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3735
            codeView characterBeforeCursor == Character space ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3736
                insertWithSpace := true.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3737
            ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3738
        ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3739
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3740
        oldLen := stop - start + 1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3741
        newLen := answer size.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3742
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3743
        codeView
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3744
            undoableDo:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3745
                insertWithSpace ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3746
                    codeView insertSelectedStringAtCursor:answer
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3747
                ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3748
                    codeView replaceFromCharacterPosition:start to:stop with:answer.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3749
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3750
                    (answer startsWith:oldVar) ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3751
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3752
                    ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3753
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3754
                    ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3755
                ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3756
                codeView dontReplaceSelectionOnInput
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3757
            ]
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3758
            info:'Completion'.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3759
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3760
    ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3761
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3762
    "Created: / 01-05-2016 / 18:47:40 / cg"
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3763
!
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3764
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3765
editActionToReplaceNode:node by:word
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3766
    ^ self editActionToReplaceCodeFrom:node start to:node stop by:word
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3767
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3768
    "Created: / 01-05-2016 / 18:44:09 / cg"
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3769
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3770
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3771
editActionToReplaceNode:node byWordIn:suggestions
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3772
    ^ self editActionToReplaceCodeFrom:node start to:node stop byWordIn:suggestions
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3773
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3774
    "Created: / 01-05-2016 / 18:44:09 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3775
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3776
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3777
findNodeForInterval:interval in:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3778
    |tree node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3779
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3780
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3781
    RBParser isNil ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3782
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3783
    source = LastSource ifTrue:[
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3784
        tree := LastParseTree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3785
    ] ifFalse:[
4951
570438fc0023 #BUGFIX
mawalch
parents: 4938
diff changeset
  3786
        LastSource := LastParseTree := nil.
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3787
        tree := RBParser
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3788
                parseMethod:source
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3789
                onError:
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3790
                    [:str :err ":nodesSoFar" |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3791
                        "Transcript showCR:'Parse-Error: ',str."
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3792
                        nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3793
                    ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3794
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3795
        tree isNil ifTrue:[
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3796
            "/ try to parse as an expression
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3797
            tree := RBParser
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3798
                    parseExpression:source
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3799
                    onError:
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3800
                        [:str :err ":nodesSoFar" |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3801
                            "Transcript showCR:'Parse-Error: ',str."
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3802
                            nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3803
                        ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3804
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3805
            tree isNil ifTrue:[
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3806
                ^ nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3807
            ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3808
        ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3809
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3810
        LastSource := source.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3811
        LastParseTree := tree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3812
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3813
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3814
    Error handle:[:ex |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3815
    ] do:[ 
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3816
        node := tree whichNodeIsContainedBy:interval.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3817
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3818
    node isNil ifTrue: [
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3819
        node := tree bestNodeFor: interval.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3820
        node isNil ifTrue: [
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3821
            node := self findNodeIn:tree forInterval:interval
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3822
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3823
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3824
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3825
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3826
    "Modified: / 06-07-2011 / 12:42:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3827
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3828
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3829
findNodeForInterval:interval in:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3830
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3831
	findNodeForInterval:interval in:source allowErrors:allowErrors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3832
	mustBeMethod:false
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3833
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3834
    "Modified: / 16-09-2011 / 14:52:28 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3835
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3836
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3837
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3838
    "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
  3839
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3840
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3841
	findNodeForInterval:interval in:source allowErrors:allowErrors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3842
	mustBeMethod:mustBeMethod mustBeExpression:false
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3843
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3844
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3845
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3846
    "parse source, and find the node which is in the given interval 
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3847
     (typically a selection or a word in the source).
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3848
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3849
     parse it as expression or method;
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3850
        if mustBeMethod is true, do not try as expression;
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3851
        if mustBeExpression is true, do not try as method
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3852
     expression syntax parsing is done in workspaces (doIt).
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3853
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3854
     Big hack as workaround a limitation of RBParser:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3855
     in case of an error, the parent chain of a node is usually not yet set.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3856
     (because the code is written as: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3857
        parentNode addChild:(self parseChild)
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3858
     and the parent-chain of the parsed child is set in addChild).
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3859
     However:
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3860
        when doing code completion, having invalid syntax to parse is the normal case.
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3861
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3862
     Workaround:
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3863
        remember created nodes as the parse proceeds.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  3864
        Thus, I can construct a partial the parent chain.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3865
    "
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3866
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3867
    |intersectingNodes smallestIntersectingNode firstIntersectingNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3868
     lastIntersectingNode onErrorBlock
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3869
     nodeGenerationHook parserClass parser currentScopeNodes bestNode|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3870
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3871
    interval isEmpty ifTrue: [^ nil].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3872
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3873
    languageOrNil notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3874
        parserClass := languageOrNil parserClass.
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3875
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3876
        classOrNil notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3877
            parserClass := classOrNil programmingLanguage parserClass.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3878
        ]
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3879
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3880
    parserClass notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3881
        "/ hack
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3882
        parserClass == Parser ifTrue: [
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3883
            parserClass := RBParser.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3884
        ].
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3885
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3886
        parserClass := RBParser.
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3887
    ].
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3888
    parserClass isNil ifTrue: [^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3889
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3890
    rememberedScopeNodes := nil.
4434
b15ce7d47dd8 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  3891
    rememberedNodes := OrderedCollection new.
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3892
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3893
    "/ LastSource := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3894
    source = LastSource ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3895
        tree := LastParseTree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3896
        tokens := LastScanTokens.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3897
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3898
        intersectingNodes := OrderedCollection new.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3899
        currentScopeNodes := IdentitySet new.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3900
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3901
        onErrorBlock :=
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3902
            [:str :err :nodesSoFar |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3903
                |nodes|
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3904
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3905
                allowErrors ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3906
                    rememberedScopeNodes := currentScopeNodes.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3907
                    firstIntersectingNode notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3908
                        ^ firstIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3909
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3910
                    nodesSoFar notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3911
                        nodes := nodesSoFar asOrderedCollection
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3912
                                    collect:[:nd | nd whichNodeIntersects:interval]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3913
                                    thenSelect:[:nd | nd notNil ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3914
                        nodes size == 1 ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3915
                            ^ nodes first
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3916
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3917
                    ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3918
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3919
                nil
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3920
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3921
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3922
        self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3923
            Transcript show:'looking for: '; showCR:interval.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3924
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3925
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3926
        nodeGenerationHook :=
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3927
            [:node |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3928
                rememberedNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3929
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3930
                "/ would like to return here as soon as the node has been created by the parser;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3931
                "/ however, at that time, its parent(chain) is not yet created and so we might not know
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3932
                "/ what the semantic interpretation (especially: scope of variable) will be.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3933
                "/ therefore, we parse all, and return the found node at the end.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3934
                (node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3935
                    currentScopeNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3936
                ] ifFalse:[
5075
7158e4b9c2c0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  3937
"/                    self debuggingCodeFor:#cg is:[
7158e4b9c2c0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  3938
"/                        node isMessage ifTrue:[
7158e4b9c2c0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  3939
"/                            Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop.
7158e4b9c2c0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  3940
"/                        ].
7158e4b9c2c0 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  3941
"/                    ].
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3942
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3943
                    (node intersectsInterval:interval) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3944
                        self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3945
                            Transcript showCR:'yes'.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3946
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3947
                        intersectingNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3948
                        firstIntersectingNode isNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3949
                            firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3950
                        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3951
                            |lenNode lenSmallest|
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3952
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3953
                            lenNode := (node stop - node start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3954
                            lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3955
                            lenNode < lenSmallest ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3956
                                smallestIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3957
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3958
                            node start > lastIntersectingNode start ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3959
                                lastIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3960
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3961
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3962
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3963
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3964
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3965
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3966
        "/ one of the big problems when using the RBParser here is
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3967
        "/ that it behaves badly when a syntax error is encountered;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3968
        "/ for example, a node's parent is usually set AFTER the children are
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3969
        "/ completely parsed (for example, a blockNode gets the parent-method only
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3970
        "/ after parsing). Thus, when an error is encountered, we cannot walk
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3971
        "/ the parent chain, and therefore will not see the outer locals/args of
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3972
        "/ an inner scope (allVariablesOnScope returns only a partial set).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3973
        "/ A walkaround is to remember Method/Block nodes as created in the above node generation.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3974
        "/ The disadvantage of it is that we do not have correct scope information, until the node's
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3975
        "/ parent gets set eventually, thus we might consider locals from sibling blocks.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3976
        "/ See rememberedScopeNodes handling above.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3977
        "/ Those other nodes are only remembered for failed parses;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3978
        "/ if the parse is ok, rememberedScopeNodes will be nil.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3979
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3980
        mustBeExpression ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3981
            tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3982
                        parseMethod: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3983
                        setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3984
                            parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3985
                            p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3986
                            p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3987
                            p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3988
                        ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3989
                        onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3990
            parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3991
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3992
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3993
        mustBeMethod ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3994
            "/ only cache parsed methods
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3995
            tree notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3996
                LastSource := source.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3997
                LastParseTree := tree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3998
                LastScanTokens := tokens.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3999
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4000
        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4001
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4002
                "/ try as an expression
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4003
                tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4004
                            parseExpression: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4005
                            setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4006
                                parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4007
                                p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4008
                                p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4009
                                p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4010
                            ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4011
                            onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4012
                parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4013
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4014
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4015
        lastIntersectingNode notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4016
            self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4017
                Transcript show:'last: '; showCR:lastIntersectingNode.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4018
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4019
            ^ lastIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4020
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4021
        "/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4022
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4023
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4024
    bestNode := self findNodeForInterval:interval inParseTree:tree.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4025
    self debuggingCodeFor:#cg is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4026
        Transcript show:'best: '; showCR:bestNode.
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4027
    ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4028
    ^ bestNode
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4029
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4030
    "Created: / 16-09-2011 / 14:52:08 / cg"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  4031
    "Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4032
    "Modified (comment): / 01-05-2016 / 10:05:10 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4033
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4034
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4035
findNodeForInterval:interval inParseTree:parseTree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4036
    |node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4037
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4038
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4039
    parseTree isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4040
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4041
    node := parseTree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4042
    node isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4043
	node := parseTree whichNodeIntersects:interval.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4044
	node isNil ifTrue: [
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4045
	    node := self findNodeIn:parseTree forInterval:interval
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4046
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4047
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4048
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4049
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4050
    "Modified: / 10-11-2006 / 13:13:58 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4051
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4052
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4053
findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4054
    |nodeFound wouldReturn|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4055
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4056
    nodeFound := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4057
    tree nodesDo:[:eachNode |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4058
	(eachNode intersectsInterval:interval) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4059
	    (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4060
		nodeFound := eachNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4061
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4062
		(nodeFound parent == eachNode parent
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4063
		and:[ eachNode start >= nodeFound start
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4064
		      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4065
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4066
		    (nodeFound parent notNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4067
		    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4068
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4069
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4070
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4071
	    nodeFound notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4072
		"/ already found one - beyond that one; leave
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4073
		wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4074
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4075
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4076
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4077
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4078
    ^ nodeFound
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4079
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4080
    "Modified: / 20-11-2006 / 12:31:12 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4081
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4082
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4083
insertAdditonalStuffAfterSelector:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4084
    |optionalExtraSpace|
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4085
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4086
    optionalExtraSpace := (codeView characterAfterCursor isSeparator)
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4087
                            ifTrue:['']
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4088
                            ifFalse:[' '].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4089
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4090
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4091
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4092
            'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4093
            'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4094
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4095
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4096
        codeView insertStringAtCursor:('[',optionalExtraSpace,']').
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4097
        "/ codeView cursorLeft:1+extra size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4098
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4099
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4100
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4101
            'collect:' 'select:' 'reject:' 'do:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4102
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4103
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4104
        codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4105
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4106
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4107
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4108
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4109
            'contains:' 'findFirst:' 'detect:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4110
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4111
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4112
        codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4113
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4114
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4115
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4116
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4117
            'remove:ifAbsent:' 'detect:ifNone:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4118
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4119
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4120
        codeView insertStringAtCursor:('[]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4121
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4122
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4123
!
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4124
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4125
messagesSentTo:varName in:aTree
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4126
    |messagesToReceiver collector|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4127
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4128
    collector :=
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4129
        [:node | 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4130
            (node isMessage 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4131
            and:[node receiver isVariable
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4132
            and:[node receiver name = varName]]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4133
                messagesToReceiver add:(node selector)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4134
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4135
        ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4136
        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4137
    "/ collect messages sent
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4138
    messagesToReceiver := Set new.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4139
    "/ remembered nodes is nonNil if parser aborted with error
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4140
    rememberedNodes notNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4141
        rememberedNodes do:collector.
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4142
    ] ifFalse:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4143
        tree allMessageNodesDo:collector.
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4144
    ]. 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4145
    ^ messagesToReceiver
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4146
!
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4147
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4148
old_askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4149
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4150
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4151
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4152
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4153
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4154
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4155
    LastChoices notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4156
	lastChoice := LastChoices at:what ifAbsent:nil.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4157
	lastChoice notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4158
	    "/ move tha last choice to the top of the list, if it is in.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4159
	    (list includes: lastChoice) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4160
		(list indexOf: lastChoice) < 10 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4161
		    list := {lastChoice allBold } , (list copyWithout:lastChoice).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4162
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4163
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4164
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4165
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4166
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4167
    list size < 30 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4168
	|menu idx exitKey|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4169
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4170
	menu := PopUpMenu labels:list.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4171
	menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4172
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4173
		hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4174
		    exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4175
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4176
		hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4177
	menu memorizeLastSelection:3 "sigh, not 1 because of heading!!".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4178
	idx := menu startUpWithHeading:'Choose ',what.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4179
	idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4180
	    exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4181
		codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4182
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4183
	    ^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4184
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4185
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4186
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4187
	resources := codeView application isNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4188
			ifTrue:[ codeView resources]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4189
			ifFalse:[ codeView application resources ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4190
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4191
	choice := Dialog
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4192
	   choose:(resources string:'Choose ',what)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4193
	   fromList:list
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4194
	   lines:20
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4195
	   initialSelection:(list firstIfEmpty:nil)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4196
	   title:(resources string:'Code completion').
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4197
	choice isNil ifTrue:[^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4198
    ].
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  4199
    choice := choice string.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4200
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4201
    LastChoices isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4202
	LastChoices := Dictionary new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4203
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4204
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4205
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4206
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4207
    "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
  4208
    "Modified: / 28-08-2013 / 15:28:01 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4209
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4210
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4211
sortSelectors:list forSelector:selector lcSelector:lcSelector
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4212
    list sort: [:a :b |
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4213
        |aBeforeB|
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4214
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4215
        (a startsWith:selector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4216
            (b startsWith:selector) ifFalse:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4217
                aBeforeB := true
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4218
            ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4219
        ] ifFalse:[    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4220
            (b startsWith:selector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4221
                aBeforeB := false
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4222
            ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4223
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4224
        aBeforeB isNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4225
            aBeforeB := a asLowercase < b asLowercase.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4226
            (a asLowercase startsWith:lcSelector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4227
                (b asLowercase startsWith:lcSelector) ifFalse:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4228
                    aBeforeB := true
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4229
                ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4230
            ] ifFalse:[    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4231
                (b asLowercase startsWith:lcSelector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4232
                    aBeforeB := false
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4233
                ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4234
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4235
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4236
        aBeforeB
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4237
    ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4238
!
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4239
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4240
sortUsefulSelectorsIn:selectorList
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4241
    "/ cosmetics: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4242
    "/  ifTrue / whileTrue should come before ifFalse/whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4243
    #(
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4244
        ifTrue:         ifFalse:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4245
        ifTrue:ifFalse: ifFalse:ifTrue:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4246
        whileTrue:      whileFalse:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4247
        whileTrue       whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4248
        whileTrue:      whileTrue
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4249
        whileFalse:     whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4250
        new:            basicNew:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4251
        new             basicNew
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4252
    ) pairWiseDo:[:sel1 :sel2 |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4253
        |idx1 idx2|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4254
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4255
        (idx1 := selectorList indexOf:sel1) ~~ 0 ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4256
            (idx2 := selectorList indexOf:sel2) ~~ 0 ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4257
                idx1 > idx2 ifTrue:[ 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4258
                    selectorList swap:idx1 with:idx2
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4259
                ] 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4260
            ] 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4261
        ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4262
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4263
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4264
    "Created: / 01-05-2016 / 17:48:02 / cg"
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4265
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4266
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4267
splitSelectorList:list by:condition
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4268
    |part1 part2 newList|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4269
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4270
    part1 := list select:condition.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4271
    part2 := list reject:condition.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4272
    part1 isEmpty ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4273
        newList := part2.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4274
    ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4275
        part2 isEmpty ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4276
            newList := part1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4277
        ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4278
            newList := part1 , part2.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4279
        ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4280
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4281
    ^ newList
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4282
!
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4283
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4284
treeForCode:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4285
    |tree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4286
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4287
    source = LastSource ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4288
	tree := LastParseTree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4289
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4290
	tree := RBParser
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4291
		parseMethod:source
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4292
		onError: [:str :err :nodesSoFar :parserOrNil|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4293
			allowErrors ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4294
			    "/ parserOrNil isNil if raised by the scanner
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4295
			    parserOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4296
				^ parserOrNil currentMethodNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4297
			    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4298
			].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4299
			^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4300
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4301
		proceedAfterError:false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4302
		rememberNodes:true.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4303
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4304
	tree notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4305
	    LastSource := source.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4306
	    LastParseTree := tree.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4307
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4308
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4309
    ^ tree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4310
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4311
    "Modified: / 13-01-2012 / 11:54:30 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4312
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4313
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4314
tryCodeCompletionWithSource:source nodeInterval:interval at:characterPositionOfCursor mustBeExpression:mustBeExpression into:actionBlock
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4315
    "this is tried multiple times;
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4316
        first with cursor line only
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4317
        then with the source copied up to the cursor position,
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4318
        then with the full source.
4381
43de05e6af6c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  4319
     Either one may give better results (for example, when completing
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4320
     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
  4321
     legal, but stupid message send to be parsed...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4322
     (which happens often after inserting)"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4323
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4324
    |node nodeParent checkedNode characterBeforeCursor|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4325
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4326
    "/ this is too naive and stupid; if there is a syntactic error,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4327
    "/ 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
  4328
    "/ 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
  4329
    "/ without any progress.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4330
    "/ 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
  4331
    "/ as it parses the code. Stop, when the interval is hit.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4332
    "/ that will also work for syntactic incorrect source code.
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4333
    (mustBeExpression not and:[methodOrNil notNil or:[classOrNil notNil]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4334
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4335
    ].           
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4336
    node isNil ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4337
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4338
        node isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4339
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4340
            self information:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4341
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4342
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4343
    ].
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4344
    "/ (source startsWith:'sel') ifTrue:[self halt].
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4345
    nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4346
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4347
    (node isVariable
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4348
    and:[ nodeParent notNil
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4349
    and:[ nodeParent isMessage
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  4350
    and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4351
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4352
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4353
    ].
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4354
    characterPositionOfCursor > source size ifTrue:[^ self].
4525
71ebd312132a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4524
diff changeset
  4355
    characterBeforeCursor := source at:(characterPositionOfCursor-1 max:1). "/ codeView characterBeforeCursor.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4356
    characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  4357
    characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4358
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4359
    node isVariable ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4360
        |nodeIsInTemporaries nodeIsInBlockArguments nodeIsInMethodArguments |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4361
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4362
        nodeIsInTemporaries :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4363
            nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4364
            and:[ nodeParent isSequence
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4365
            and:[ nodeParent temporaries notEmptyOrNil
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4366
            and:[ node stop <= nodeParent temporaries last stop ]]]. 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4367
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4368
        nodeIsInBlockArguments :=
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4369
            node blockScope notNil
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4370
            and:[ node blockScope arguments notEmptyOrNil
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4371
            and:[ node stop <= node blockScope arguments last stop ]].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4372
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4373
        (nodeIsInBlockArguments not and:[rememberedScopeNodes notNil]) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4374
            "/ sigh - parent (and therefore blockScope) is unknown if parser has error
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4375
            nodeIsInBlockArguments := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4376
                rememberedScopeNodes 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4377
                    contains:[:scope |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4378
                        (scope isMethod or:[scope isBlock])
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4379
                        and:[scope arguments notEmpty
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4380
                        and:[scope arguments first start <= node start
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4381
                        and:[scope arguments last stop >= node stop]]].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4382
                    ].        
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4383
        ].
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4384
        nodeIsInTemporaries ifTrue:[ self codeCompletionForTempVariable:node into:actionBlock. ^ self ]. 
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4385
        nodeIsInBlockArguments ifTrue:[ self codeCompletionForBlockArgument:node into:actionBlock. ^ self ]. 
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4386
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4387
        "/ for variable completion, cursor must be right after the node 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4388
        codeView characterPositionOfCursor = (node stop + 1) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4389
            codeView characterBeforeCursor ~= Character space ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4390
                self codeCompletionForVariable:node into:actionBlock.
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4391
                ^ self.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4392
            ]. 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4393
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4394
        "/ nodeParent isNil or:[nodeParent isMessage not]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4395
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4396
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4397
false ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4398
        codeView characterPositionOfCursor = (node stop + 2) ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4399
            |classes cls| 
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4400
            "/ after a variable;
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4401
            "/ offer local messages, if receiver type is known
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4402
            classes := (self classesOfNode:node).
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4403
            classes notEmptyOrNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4404
                classes size > 1 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4405
                    cls := classes anElement.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4406
                ] ifFalse:[    
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4407
                    cls := Behavior commonSuperclassOf:classes.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4408
                ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4409
            ]. 
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4410
            cls notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4411
                |clsSelectors moreSelectors|
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4412
            
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4413
                "/ completion in a message-send
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4414
                clsSelectors := cls methodDictionary keys. "/ Parser findBest:50 selectorsFor:'' in:cls forCompletion:true.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4415
                clsSelectors size < 30 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4416
                    cls superclass notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4417
                        moreSelectors := cls superclass methodDictionary keys.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4418
                        clsSelectors size + moreSelectors size < 30 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4419
                            clsSelectors := clsSelectors , moreSelectors.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4420
                        ].
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4421
                    ].    
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4422
                ].
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4423
                "/ self codeCompletionForMessage:checkedNode into:actionBlock.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4424
                actionBlock value:clsSelectors value:nil value:nil.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4425
                ^ self.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4426
            ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4427
        ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4428
].
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4429
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4430
    node isLiteral ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4431
        "/ however, user may want to complete a symbol inside a literal array!!
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4432
        node value isArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4433
            node token isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4434
                |elementBeforeCursor searcher|
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4435
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4436
                elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4437
                elementBeforeCursor isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4438
                    searcher :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4439
                        [:tok :check |
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4440
                            tok isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4441
                                tok value inject:nil into:[:found :el | found ifNil:[searcher value:el value:check]]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4442
                            ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4443
                                (check value:tok) ifTrue:[tok] ifFalse:[nil]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4444
                            ]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4445
                        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4446
                    elementBeforeCursor := searcher value:node token value:[:anElementToken | characterPositionOfCursor == (anElementToken stop)].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4447
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4448
                (elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4449
                    self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4450
                    ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4451
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4452
            ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4453
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4454
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4455
        "/ cursor must be right after the literal
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4456
        characterPositionOfCursor == (node stop + 1) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4457
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4458
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4459
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4460
        node value isSymbol ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4461
            self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4462
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4463
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4464
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4465
        "/ huh - completing strings, numbers or what?
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4466
        (nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4467
            and:[ nodeParent isMessage
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4468
            and:[ nodeParent isKeyword ]])
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4469
        ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4470
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4471
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4472
        "/ no, move up and try completing the outer keyword message (next arg)
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4473
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4474
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4475
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4476
5050
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4477
    Verbose == true ifTrue:[
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4478
        Transcript show:'node is '.
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4479
        Error ignoreIn:[ Transcript show:node ].
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4480
        Transcript cr.
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4481
    ].
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4482
    
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4483
    "/ if in a keyword-argument position...
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4484
    node isMessage ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4485
        "/ where are we?
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4486
        node selector isKeyword ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4487
            characterBeforeCursor == $: ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4488
                |argIdx senders implementors receiverClasses selectorUpToCursor implementorOfSelectorUpToCursor|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4489
                "/ about to enter an argument?
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4490
                argIdx := node selectorParts keysAndValuesDetectKey:[:idx :part |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4491
                            part stop == (codeView characterPositionOfCursor-1). 
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4492
                          ] ifNone:nil.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4493
                argIdx notNil ifTrue:[          
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4494
                    selectorUpToCursor := ((node selectorParts collect:#value) copyTo:argIdx) asStringWith:''.        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4495
                    implementors := Set new.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4496
                    "/ find senders of this message, and see if they call it with a block argument
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4497
                    "/ this takes too long for a completion;
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4498
                    "/    Smalltalk allClassesDo:[:cls |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4499
                    "/        cls instAndClassMethodsDo:[:m |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4500
                    "/            (m sendsMessageForWhich:[:sel | sel startsWith:node selector]) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4501
                    "/                senders add:m
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4502
                    "/            ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4503
                    "/        ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4504
                    "/    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4505
                    "/ therefore, restrict to a max. of 5 classes
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4506
                    receiverClasses := self classesOfNode:node receiver.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4507
                    (receiverClasses notEmptyOrNil and:[receiverClasses size <= 5]) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4508
                        receiverClasses do:[:eachPossibleReceiverClass |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4509
                            eachPossibleReceiverClass withAllSuperclassesDo:[:cls |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4510
                                cls methodDictionary keysAndValuesDo:[:sel :mthd |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4511
                                    (sel startsWith:selectorUpToCursor) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4512
                                        implementors add:mthd.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4513
                                        (sel = selectorUpToCursor) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4514
                                            implementorOfSelectorUpToCursor := implementorOfSelectorUpToCursor ? mthd
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4515
                                        ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4516
                                    ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4517
                                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4518
                            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4519
                        ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4520
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4521
                    implementorOfSelectorUpToCursor notNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4522
                        |tree argName|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4523
                        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4524
                        tree := implementorOfSelectorUpToCursor parseTree.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4525
                        argName := tree argumentNames at:argIdx.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4526
                        (argName includesString:'block' caseSensitive:false) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4527
                            actionBlock value:{'[ "',argName,'" ]'}
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4528
                                        value:{ self editActionToInsert:('[ "',argName,'" ]') }
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4529
                                        value:'block argument'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4530
                        ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4531
                    ] ifFalse:[    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4532
                        implementors notEmpty ifTrue:[
5082
87e1ffeceb8a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5081
diff changeset
  4533
                            self breakPoint:#cg.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4534
                        ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4535
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4536
                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4537
            ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4538
        ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4539
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4540
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4541
    (node isVariable or:[node isBlock and:[node stop notNil]]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4542
        (characterPositionOfCursor == (node stop + 1)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4543
        "/ hack (spaces at end of line)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4544
        or:[characterPositionOfCursor == (node stop)]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4545
            codeView characterBeforeCursor == Character space ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4546
                self codeCompletionForMessageTo:node into:actionBlock.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4547
                ^ self
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4548
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4549
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4550
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4551
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  4552
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  4553
characterBeforeCursor == $) ifTrue:[self halt].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  4554
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4555
    "/ move outward, until we find a message-send node,
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4556
    "/ or the method's selector pattern node.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4557
    checkedNode := node.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4558
    [checkedNode notNil] whileTrue:[
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4559
        (characterPositionOfCursor <= (checkedNode stop ? source size)) ifTrue:[
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4560
            "/ Transcript show:'T: '; showCR:node.
5048
8dbd0140a2f0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5047
diff changeset
  4561
            "/ Transcript showCR:('Inside a ',(checkedNode className)).
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4562
            "/ self information:('Inside a ',(checkedNode className)).
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4563
            (checkedNode isMessage 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4564
            and:[characterPositionOfCursor < (checkedNode selectorParts first start)]) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4565
                self codeCompletionForMessageTo:checkedNode receiver into:actionBlock.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4566
                ^ self
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4567
            ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4568
            
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4569
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4570
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4571
        checkedNode isMessage ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4572
            "/ completion in a message-send
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4573
            "/ Transcript showCR:'codeCompletionForMessage'.
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4574
            self codeCompletionForMessage:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4575
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4576
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4577
        checkedNode isMethod ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4578
            "/ completion in a method's selector pattern
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4579
            "/ Transcript showCR:'codeCompletionForMethodSpec'.
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4580
            self codeCompletionForMethodSpec:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4581
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4582
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4583
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4584
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4585
        checkedNode := checkedNode parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4586
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4587
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4588
    "/ Transcript showCR:'Node is neither variable nor message'.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4589
    self information:'Node is neither variable nor message.'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4590
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4591
    "Modified: / 04-07-2006 / 18:48:26 / fm"
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4592
    "Modified: / 01-05-2016 / 19:00:33 / cg"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4593
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4594
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4595
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4596
    "some heuristics;
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4597
     as best selectors has been chosen by implemented methods for aClass,
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4598
     some of them should be filtered (for example, at:/at:put:, which are
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4599
     found in object, but only make sense for variable objects or those which do
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4600
     implement at:put: themself.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4601
     I have currently no better idea than hardcoding stuff I found irritating..."
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4602
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4603
    |selectors noNilChecks noIsXXXChecks noNoXXXChecks noBecome 
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4604
     noIndexedSetters noIndexedGetters noSizeQueries|
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4605
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4606
    aClass isNil ifTrue:[ ^ selectorsArg ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4607
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4608
    noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := false.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4609
    noIndexedSetters := noIndexedGetters := noSizeQueries := false.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4610
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4611
    selectors := (selectorsArg ? #()) asOrderedCollection.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4612
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4613
    self tracePoint:#cg message:aClass.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4614
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4615
    "/ actually meaning booleans here
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4616
    (aClass == True or:[aClass == False]) ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4617
        noNilChecks := noBecome := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4618
        (partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4619
        (partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4620
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4621
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4622
    (aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4623
    (aClass includesBehavior: Symbol) ifTrue:[ noNilChecks := noBecome := noIndexedSetters := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4624
    (aClass includesBehavior: Number) ifTrue:[ noBecome := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4625
    (aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4626
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4627
    (aClass isMeta) ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4628
        noNilChecks := noBecome := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4629
        "/ remove messages which are only defined in Object and non-meta classes.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4630
        selectors := selectors reject:
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4631
            [:sel |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4632
                (Object implements:sel)
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4633
                and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]]
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4634
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4635
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4636
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4637
    aClass isVariable ifFalse:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4638
        noIndexedGetters := noIndexedSetters := noSizeQueries := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4639
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4640
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4641
    noIndexedSetters ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4642
        #( #'at:put:' #'basicAt:put:') do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4643
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4644
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4645
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4646
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4647
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4648
    noIndexedGetters ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4649
        #( #'at:' #'basicAt:') do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4650
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4651
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4652
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4653
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4654
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4655
    noSizeQueries ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4656
        #( #size #basicSize ) do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4657
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4658
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4659
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4660
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4661
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4662
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4663
    noNilChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4664
        selectors removeAllFoundIn:#(
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4665
                    'isNil' 'notNil'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4666
                    'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4667
                    'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4668
                    'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4669
                  ).
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4670
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4671
    noIsXXXChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4672
        "/ get rid of all isXXX selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4673
        selectors := selectors reject:[:sel | sel startsWith:'is'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4674
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4675
    noNoXXXChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4676
        "/ get rid of all notXXX selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4677
        selectors := selectors reject:[:sel | sel startsWith:'no'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4678
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4679
    noBecome ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4680
        "/ get rid of all become* selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4681
        selectors := selectors reject:[:sel | sel startsWith:'become'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4682
        selectors remove:#oneWayBecome: ifAbsent:[].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4683
        selectors := selectors reject:[:sel | sel startsWith:'changeClassTo'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4684
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4685
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4686
    "/ actually: directly implemented selectors are more likely, so move them to top
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4687
    selectors := (selectors select:[:sel | aClass implements:sel])
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4688
                 ,
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4689
                 (selectors reject:[:sel | aClass implements:sel]).
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4690
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4691
    ^ selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4692
! !
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4693
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4694
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4695
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4696
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4697
    |sym possibleCompletions best start stop oldLen newLen oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4698
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4699
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4700
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4701
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4702
    Symbol allInstancesDo:[:existingSym |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4703
	(existingSym startsWith:sym) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4704
	    (existingSym = sym) ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4705
		possibleCompletions add:existingSym
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4706
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4707
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4708
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4709
    possibleCompletions sort.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4710
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4711
    best := possibleCompletions longestCommonPrefix.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4712
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4713
	best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4714
	best isNil ifTrue:[^ self].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4715
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4716
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4717
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4718
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4719
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4720
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4721
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4722
	start := start + 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4723
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4724
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4725
	start := start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4726
	stop := stop - 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4727
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4728
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4729
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4730
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4731
    codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4732
	undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4733
	info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4734
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4735
    (best startsWith:oldVar) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4736
	oldLen := stop - start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4737
	newLen := best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4738
	codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4739
	codeView dontReplaceSelectionOnInput
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4740
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4741
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4742
    "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
  4743
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4744
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4745
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4746
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4747
    "going to be OBSOLETE"
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4748
    
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4749
    |selector
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4750
     bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4751
     newParts nSelParts oldLen newLen selectorParts
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4752
     findBest parentNode selectorInBest selector2InBest2
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4753
     parser selectorsSentInCode selectorsImplementedInClass
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4754
     varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4755
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4756
    RefactoryTyper notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4757
        "/ refactory package also provides a (very limited) typer;
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4758
        "/ ask it for its oppinion as well (temporary - will vanish, once we have a better typer)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4759
        (node receiver isVariable) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4760
            varName := node receiver name.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4761
            varName isUppercaseFirst ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4762
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4763
                tree := RBParser
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4764
                            parseMethod:codeView contents string
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4765
                            onError:[:aString :pos | nil].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4766
                tree notNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4767
                    rbTypes := RefactoryTyper
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4768
                                classesFor: varName
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4769
                                in: tree
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4770
                                model: nil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4771
                                ignoredSelectors:(Array with:node selector).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4772
                    rbTypes size > 0 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4773
                        rbTypes size > 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4774
                            rbTypes remove:ProtoObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4775
                            rbTypes remove:Autoload ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4776
                            rbTypes remove:ObsoleteObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4777
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4778
                        rbTypes size == 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4779
                            rbType := rbTypes first.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4780
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4781
                            rbType := Class commonSuperclassOf:rbTypes
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4782
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4783
                        (rbType notNil "and:[rbType ~= Object]") ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4784
                            bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4785
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4786
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4787
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4788
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4789
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4790
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4791
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4792
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4793
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4794
        selectorsSentInCode := parser messagesSent.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4795
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4796
    classOrNil notNil ifTrue:[
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4797
        selectorsImplementedInClass := Set new.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4798
        classOrNil withAllSuperclassesDo:[:cls |
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4799
            cls theNonMetaclass ~~ Object ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4800
                selectorsImplementedInClass addAll:cls selectors.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4801
            ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4802
        ]    
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4803
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4804
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4805
    findBest := [:node :selector |
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4806
        |srchClasses bestSelectors bestPrefixes|
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4807
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4808
        codeView withCursor:(Cursor questionMark) do:[
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4809
            srchClasses := self classesOfNode:node receiver.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4810
            srchClasses notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4811
                bestSelectors := Set new.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4812
                srchClasses do:[:each |
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4813
                    bestSelectors addAll:(Parser findBest:30 selectorsFor:selector in:each forCompletion:true).
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4814
                ]    
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4815
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4816
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4817
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4818
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4819
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4820
        (bestSelectors includes:selector) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4821
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4822
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4823
        bestSelectors
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4824
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4825
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4826
    selector := node selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4827
    bestSelectors := findBest value:node value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4828
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4829
    parentNode := node parent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4830
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4831
    parentIsKeywordMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4832
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4833
            and:[ parentNode isMessage
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  4834
            and:[ parentNode selector isKeyword]]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4835
    parentIsBinaryMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4836
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4837
            and:[ parentNode isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4838
            and:[ parentNode selector isBinarySelector]]).
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4839
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4840
    tryParent := false.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4841
    "/ if its a unary message AND the parent is a keyword node, look for parent completion too.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4842
    (node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4843
        tryParent := true.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4844
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4845
        "/ if the parent is an instance creation message, take that as lookup class.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4846
        (node isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4847
        and:[ node receiver isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4848
        and:[ node receiver receiver isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4849
        and:[ node receiver receiver name isUppercaseFirst
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4850
        and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4851
            rcvrClass := Smalltalk classNamed:(node receiver receiver name).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4852
            "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4853
            bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4854
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4855
            "/ also, if nothing was found
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4856
            (bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4857
            and:[ parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4858
            and:[ parentNode isMessage ]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4859
                "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4860
                "/ selector2 := parentNode selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4861
                "/ selector2 := selector2,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4862
                bestSelectors := findBest value:parentNode value:selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4863
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4864
        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4865
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4866
    tryParent ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4867
        selector2 := parentNode selector,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4868
        bestSelectors2 := findBest value:parentNode value:selector2.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4869
    ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4870
    bestSelectorsFromRB notEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4871
        bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4872
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4873
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4874
    "/ if the parent is a keyword selector, the child cannot
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4875
    (parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  4876
        bestSelectors := bestSelectors reject:[:sel | sel isKeyword]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4877
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4878
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4879
    bestSelectors2 isEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4880
        allBest := bestSelectors.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4881
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4882
        bestSelectors isEmptyOrNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4883
            allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4884
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4885
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4886
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4887
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4888
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4889
                "/ selector2 is more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4890
                allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4891
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4892
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4893
                    "/ selector more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4894
                    allBest := bestSelectors
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4895
                ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4896
                    "/ assume same likelyness
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4897
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4898
                    allBest := bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4899
                                ifTrue:[ bestSelectors2 ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4900
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4901
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4902
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4903
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4904
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4905
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4906
    allBest isEmptyOrNil ifTrue:[ ^ self ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4907
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4908
    selectorsImplementedInClass notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4909
        "/ the ones implemented in the receiver class are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4910
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4911
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4912
                    by:[:sel | selectorsImplementedInClass includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4913
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4914
    selectorsSentInCode notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4915
        "/ the ones already sent in the code are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4916
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4917
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4918
                    by:[:sel | selectorsSentInCode includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4919
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4920
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4921
    "/ the ones which are a prefix are moved towards the top of the list
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4922
    allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4923
                splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4924
                by:[:sel | sel notNil and:[sel startsWith:selector]].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4925
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4926
    best := allBest first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4927
    allBest size > 1 ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4928
        "allBest size < 20 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4929
            |idx|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4930
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4931
            idx := (PopUpMenu labels:allBest) startUp.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4932
            idx == 0 ifTrue:[ ^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4933
            best := allBest at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4934
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4935
            allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4936
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4937
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4938
        ]."
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4939
        allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4940
        best := self askUserForCompletion:('Selector for "%1"' bindWith:selector) for:codeView at: node selectorParts first start from:allBest.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4941
        best isEmptyOrNil ifTrue:[^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4942
        best = '-' ifTrue:[^ self].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4943
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4944
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4945
"/    srchClass notNil ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4946
"/        implClass := srchClass whichClassIncludesSelector:best.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4947
"/    ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4948
"/        implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4949
"/        implClass size == 1 ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4950
"/            implClass := implClass first.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4951
"/        ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4952
"/            implClass := nil
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4953
"/        ]
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4954
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4955
"/
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4956
"/    info := best storeString.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4957
"/    implClass notNil ifTrue:[
5095
71e2684154a4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5092
diff changeset
  4958
"/        info := implClass name , ' » ' , info.
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4959
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4960
"/    self information:info.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4961
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4962
    best ~= selector ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4963
        numArgs := best numArgs.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4964
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4965
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4966
            selectorParts := parentNode selectorParts , node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4967
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4968
            selectorParts := node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4969
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4970
        nSelParts := selectorParts size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4971
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4972
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4973
        newParts := newParts select:[:part | part size > 0].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4974
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4975
        codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4976
            undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4977
                |newCursorPosition stop|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4978
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4979
                numArgs > nSelParts ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4980
                    stop := selectorParts last stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4981
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4982
                    "/ append the rest ...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4983
                    numArgs downTo:nSelParts+1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4984
                        |newPart|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4985
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4986
                        newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4987
                        (best endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4988
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4989
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4990
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4991
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4992
                            newPart := ':' , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4993
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4994
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4995
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4996
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4997
                        newCursorPosition := stop + newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4998
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4999
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5000
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5001
                (nSelParts min:newParts size) downTo:1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5002
                    |newPart oldPartialToken start stop nextChar|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5003
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5004
                    newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5005
                    oldPartialToken := selectorParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5006
                    start := oldPartialToken start.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5007
                    stop := oldPartialToken stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5008
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5009
                    (best isKeyword) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5010
                        (oldPartialToken value endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5011
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5012
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5013
                            (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5014
                                newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5015
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5016
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5017
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5018
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5019
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5020
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5021
                            nextChar := codeView characterAtCharacterPosition:stop+1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5022
                            nextChar isSeparator ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5023
                                (').' includes:nextChar) ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5024
                                    newPart := newPart , ' '
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5025
                                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5026
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5027
                        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5028
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5029
"/                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5030
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5031
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5032
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5033
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5034
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5035
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5036
                    newCursorPosition isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5037
                        oldLen := stop - start + 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5038
                        newLen := newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5039
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5040
                        newCursorPosition := stop + (newLen-oldLen)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5041
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5042
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5043
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5044
                codeView cursorToCharacterPosition:newCursorPosition.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5045
                codeView cursorRight.  "/ avoid going to the next line !!
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5046
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5047
                ((best endsWith:':') and:[numArgs == 1]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5048
                    |impls impl|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5049
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5050
                    "/ see if it expects a block argument (heuristic)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5051
                    best := best asSymbol.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5052
                    (node notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5053
                    and:[classOrNil notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5054
                    and:[node receiver isSelf]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5055
                        (impl := classOrNil whichClassImplements:best) isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5056
                            impls := #().
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5057
                            Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5058
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5059
                            impls := { impl }
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5060
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5061
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5062
                        impls := Smalltalk allImplementorsOf:best.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5063
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5064
                    (impls contains:[:cls |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5065
                        |argName|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5066
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5067
                        argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5068
                        (argName includesString:'block') or:[ (argName includesString:'action')]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5069
                    ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5070
                        codeView insertStringAtCursor:'['
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5071
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5072
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5073
                codeView dontReplaceSelectionOnInput.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5074
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5075
        info:'Completion'.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5076
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5077
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5078
    "Created: / 10-11-2006 / 13:18:27 / cg"
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5079
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5080
    "Modified: / 30-04-2016 / 18:21:21 / cg"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5081
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5082
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5083
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5084
    |parent nonMetaClass crsrPos nm
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5085
     allVariables allDistances best nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5086
     char start stop oldLen newLen oldVar
4485
c6ed849af389 class: DoWhatIMeanSupport
Stefan Vogel <sv@exept.de>
parents: 4484
diff changeset
  5087
     getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5088
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5089
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5090
    classOrNil notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5091
	nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5092
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5093
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5094
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5095
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5096
    "/ 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
  5097
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5098
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5099
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5100
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5101
    char isSeparator ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5102
	classOrNil isNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5103
	    nodeVal := Smalltalk at:nm asSymbol.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5104
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5105
	    nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5106
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5107
	nodeVal isBehavior ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5108
	    |methods menu exitKey idx|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5109
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5110
	    methods := nodeVal class methodDictionary values
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5111
			    select:[:m | |cat|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5112
				cat := m category asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5113
				cat = 'instance creation'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5114
			    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5115
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5116
	    menu := PopUpMenu labels:(methods collect:[:each | each selector]).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5117
	    menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5118
		    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5119
		    hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5120
			exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5121
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5122
		    hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5123
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5124
	    idx := menu startUp.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5125
	    idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5126
		exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5127
		    codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5128
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5129
		^ self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5130
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5131
	    best := (methods at:idx) selector.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5132
	    codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5133
		undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5134
		    codeView insertString:best atCharacterPosition:crsrPos.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5135
		    codeView cursorToCharacterPosition:crsrPos+best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5136
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5137
		info:'completion'.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5138
	    ^ self.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5139
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5140
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5141
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5142
    ((parent := node parent) notNil and:[parent isMessage]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5143
	node == parent receiver ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5144
	    selectorOfMessageToNode := parent selector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5145
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5146
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5147
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5148
    getDistanceComputeBlockWithWeight :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5149
	[:weight |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5150
	    [:each |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5151
		|dist factor|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5152
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5153
		dist := each spellAgainst:nm.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5154
		factor := 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5155
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5156
		(each startsWith:nm) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5157
		    factor := 6 * nm size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5158
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5159
		    (each asLowercase startsWith:nm asLowercase) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5160
			factor := 4 * nm size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5161
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5162
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5163
		dist := dist + (weight*factor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5164
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5165
		each -> (dist * weight)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5166
	     ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5167
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5168
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5169
    addWithFactorBlock :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5170
	[:eachNames :factor | |namesToAdd|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5171
	    namesToAdd := eachNames select:[:nameToAdd | nameToAdd ~= nm ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5172
	    namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5173
	    allVariables addAll:namesToAdd.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5174
	    allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5175
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5176
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5177
    nm isUppercaseFirst ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5178
	globalFactor := 2.    "/ favour globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5179
	localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5180
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5181
	globalFactor := 1.    "/ favour locals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5182
	localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5183
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5184
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5185
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5186
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5187
4308
f1c31624744d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4304
diff changeset
  5188
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5189
    ((parent := node parent) notNil
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5190
    and:[parent isMethod
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5191
    and:[parent arguments includes:node]]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5192
	"/ now thats cool: look how the naem of this argument is in other implementations
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5193
	"/ of this method, and take that as a basis of the selection
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5194
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5195
	implementors := SystemBrowser
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5196
			    findImplementorsOf:(parent selector)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5197
			    in:(Smalltalk allClasses)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5198
			    ignoreCase:false.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5199
	"/ which argument is it
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5200
	argIdx := parent arguments indexOf:node.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5201
	implementors size > 50 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5202
	    implementors := implementors asOrderedCollection copyTo:50.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5203
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5204
	namesUsed := implementors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5205
			collect:[:eachImplementor |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5206
			    |parseTree|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5207
			    parseTree := eachImplementor parseTree.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5208
			    (parseTree notNil and:[parseTree arguments size > 0])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5209
				ifFalse:nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5210
				ifTrue:[ (parseTree arguments at:argIdx) name] ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5211
			thenSelect:[:a | a notNil] as:Set.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5212
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5213
	addWithFactorBlock value:namesUsed value:(2 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5214
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5215
	classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5216
	    "/ also, look for the keyword before the argument,
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5217
	    "/ and see if there is such an instVar
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5218
	    "/ if so, add it with -Arg
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5219
	    parent selector isKeyword ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5220
		kwPart := parent selector keywords at:argIdx.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5221
		(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5222
		    addWithFactorBlock
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5223
			value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5224
			value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5225
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5226
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5227
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5228
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5229
	classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5230
	    "/ locals in the block/method
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5231
	    |names|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5232
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5233
	    names := node allVariablesOnScope.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5234
	    "/ if there were no variables (due to a parse error)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5235
	    "/ do another parse and see what we have
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5236
	    names isEmpty ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5237
		tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5238
		"/ better if we already have a body (include locals then)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5239
		"/ otherwise, only the arguments are considered
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5240
		tree notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5241
		    names := (tree body ? tree) allVariablesOnScope.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5242
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5243
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5244
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5245
	    addWithFactorBlock value:names value:(4 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5246
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5247
	    "/ instance variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5248
	    addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5249
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5250
	    "/ inherited instance variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5251
	    classOrNil superclass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5252
		addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5253
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5254
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5255
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5256
	selectorOfMessageToNode notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5257
	    |names responders nonResponders|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5258
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5259
	    "/ responding to that messsage
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5260
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5261
	    classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5262
		"/ private classes
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5263
		addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5264
				   value:(1.75 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5265
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5266
		"/ class variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5267
		names := nonMetaClass classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5268
		responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5269
		nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5270
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5271
		addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5272
		addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5273
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5274
		"/ superclass var names
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5275
		nonMetaClass allSuperclassesDo:[:superClass |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5276
		    names := superClass classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5277
		    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5278
		    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5279
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5280
		    addWithFactorBlock value:responders value:(1 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5281
		    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5282
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5283
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5284
		"/ namespace vars
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5285
		classOrNil nameSpace ~~ Smalltalk ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5286
		    names := classOrNil topNameSpace keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5287
		    names := names reject:[:nm | nm includes:$:].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5288
		    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5289
		    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5290
		    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5291
		    addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5292
		    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5293
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5294
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5295
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5296
	    "/ globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5297
	    names := Smalltalk keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5298
	    "/ names := names reject:[:nm | nm includes:$:].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5299
	    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5300
	    responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5301
	    nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5302
	    addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5303
	    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5304
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5305
	    "/ pool variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5306
	    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5307
		|pool|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5308
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5309
		pool := Smalltalk at:poolName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5310
		names := pool classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5311
		names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5312
		responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5313
		nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5314
		addWithFactorBlock value:responders value:(2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5315
		addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5316
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5317
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5318
	    |names|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5319
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5320
	    classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5321
		"/ private classes
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5322
		addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5323
				   value:(1.75 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5324
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5325
		"/ class variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5326
		addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5327
		classOrNil superclass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5328
		    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5329
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5330
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5331
		"/ namespace vars
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5332
		classOrNil nameSpace ~~ Smalltalk ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5333
		    names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5334
		    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5335
		    addWithFactorBlock value:names value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5336
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5337
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5338
		"/ pool variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5339
		classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5340
		    |pool|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5341
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5342
		    pool := Smalltalk at:poolName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5343
		    names := pool classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5344
		    addWithFactorBlock value:names value:(2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5345
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5346
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5347
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5348
	    "/ globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5349
	    names := Smalltalk keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5350
	    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5351
	    addWithFactorBlock value:names value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5352
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5353
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5354
	"/ pseudos - assuming that thisContext is seldom used.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5355
	"/ also assuming, that nil is short so its usually typed in.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5356
	addWithFactorBlock value:#('self') value:(2.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5357
	addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5358
	addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5359
	addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5360
	addWithFactorBlock value:#('true') value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5361
	addWithFactorBlock value:#('false') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5362
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5363
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5364
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5365
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5366
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5367
							   ifTrue:[el]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5368
							   ifFalse:[best]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5369
						    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5370
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5371
    allDistances sort:[:a :b |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5372
				a value > b value ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5373
				    true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5374
				] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5375
				    a value = b value ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5376
					a key < b key
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5377
				    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5378
					false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5379
				    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5380
				]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5381
		      ].
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  5382
    ((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5383
	allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5384
	allTheBest size > 15 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5385
	    allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5386
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5387
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5388
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5389
    start := node start.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5390
    stop := node stop.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5391
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5392
    best := self askUserForCompletion:('Variable for "%1"' bindWith:node name)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5393
		 for:codeView at: start
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5394
		 from:(allTheBest collect:[:assoc | assoc key]).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5395
    best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5396
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5397
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5398
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5399
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5400
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5401
    codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5402
	undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5403
	info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5404
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5405
    (best startsWith:oldVar) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5406
	oldLen := stop - start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5407
	newLen := best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5408
	codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5409
	codeView dontReplaceSelectionOnInput
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5410
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5411
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5412
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5413
    "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
  5414
    "Modified: / 28-08-2013 / 15:37:28 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5415
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5416
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5417
!DoWhatIMeanSupport methodsFor:'helpers-naive type inference'!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5418
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5419
addClassesFromAssignmentTo:varName in:aTree to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5420
    "/ assignments...
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5421
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5422
    aTree allAssignmentNodesDo:[:eachAssignmentNode |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5423
        |leftSide|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5424
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5425
        leftSide := eachAssignmentNode variable.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5426
        leftSide name = varName ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5427
            self 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5428
                addClassesOfExpression:eachAssignmentNode value 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5429
                inClass:classOrNil to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5430
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5431
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5432
    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5433
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5434
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5435
addClassesFromMessagesSentTo:varNode in:aTree to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5436
    "/ from the set of messages sent at other places,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5437
    "/ try to find classes, which respond to all those.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5438
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5439
    |varName allSelectors candidates|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5440
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5441
    varName := varNode name.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5442
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5443
    allSelectors := IdentitySet new.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5444
    aTree allMessageNodesDo:[:eachMessageNode |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5445
        |rcvr|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5446
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5447
        rcvr := eachMessageNode receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5448
        (rcvr isVariable and:[rcvr name = varName]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5449
            allSelectors add:eachMessageNode selector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5450
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5451
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5452
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5453
    "/ the selector beeing comleted must be ignored here
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5454
    (varNode parent notNil and:[varNode parent isMessage]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5455
        allSelectors remove:(varNode parent selector) ifAbsent:[].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5456
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5457
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5458
    "/ now look for classes which implement all of them
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5459
    candidates := SystemBrowser findRespondersOfAll:allSelectors in:nil ignoreCase:false.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5460
    candidates remove:Object ifAbsent:[].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5461
    setOfTypes addAll:candidates.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5462
    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5463
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5464
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5465
addClassesOfBlockVarForWellknownBlocks:variableNode inScope:blockScope to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5466
    |blockParent blockParentSelector exNode isHandler|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5467
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5468
    blockParent := blockScope parent.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5469
    (blockParent notNil and:[blockParent isMessage]) ifFalse:[^ setOfTypes].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5470
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5471
    blockParentSelector := blockParent selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5472
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5473
    "/ if the parent of the block is an enumeration message, and the receiver is known,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5474
    "/ we know the type of argument.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5475
    ( #(do: keysAndValuesDo: select: collect:) includes:blockParent selector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5476
        |collection|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5477
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5478
        collection := self valueOfNode:blockParent receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5479
        collection notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5480
            (collection isKindOf:Collection) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5481
                collection notEmpty ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5482
                    |someElement|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5483
                    someElement := collection anElement.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5484
                    setOfTypes add:someElement class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5485
                    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5486
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5487
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5488
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5489
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5490
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5491
    "/ because we type-in those so often, it is great to get
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5492
    "/ better info on the ex parameter... (and it's a low hanging fruit)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5493
    ( blockParentSelector == #handle:do: ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5494
        exNode := blockParent receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5495
        isHandler := (blockScope == (blockParent arguments at:1)).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5496
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5497
    ( blockParentSelector == #on:do: ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5498
        self halt.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5499
        exNode := blockParent arg1.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5500
        isHandler := (blockScope == (blockParent arguments at:2)).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5501
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5502
    exNode notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5503
        |cls exClass|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5504
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5505
        ((cls := (self valueOfNode:exNode)) notNil and:[cls isBehavior]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5506
            exClass := cls
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5507
        ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5508
            exClass := Exception
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5509
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5510
        setOfTypes add:exClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5511
        ^ self
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5512
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5513
    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5514
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5515
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5516
addClassesOfExpression:expr inClass:classOrNil to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5517
    |cls exprVal varName varScope instVarClass classVarClass poolVarClass sym|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5518
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5519
    expr isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5520
        exprVal := expr value.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5521
        cls := exprVal class.         
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5522
        (exprVal isArray or:[ exprVal isByteArray or:[ exprVal isString ]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5523
            exprVal isImmutable ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5524
                setOfTypes add:cls mutableClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5525
                ^ setOfTypes.    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5526
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5527
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5528
        setOfTypes add:cls. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5529
        ^ setOfTypes.    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5530
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5531
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5532
    expr isBlock ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5533
        setOfTypes add:Block. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5534
        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5535
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5536
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5537
    expr isVariable ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5538
        varName := expr name.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5539
        varName = 'self' ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5540
            setOfTypes add:(classOrNil ? UndefinedObject).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5541
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5542
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5543
        varName = 'super' ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5544
            classOrNil isNil 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5545
                ifTrue:[setOfTypes add:Object]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5546
                ifFalse:[setOfTypes add:classOrNil superclass].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5547
            ^ setOfTypes.    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5548
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5549
        varName = 'thisContext' ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5550
            setOfTypes add:Context.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5551
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5552
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5553
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5554
        varScope := expr whoDefines: varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5555
        (varScope notNil) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5556
            varScope isSequence ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5557
                varScope := varScope parent.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5558
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5559
            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5560
            (varScope isBlock) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5561
                self addClassesOfBlockVarForWellknownBlocks:expr inScope:varScope to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5562
                self addClassesFromAssignmentTo:varName in:varScope to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5563
                self addClassesFromMessagesSentTo:expr in:varScope to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5564
                ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5565
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5566
            (varScope isMethod) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5567
                self addClassesFromAssignmentTo:varName in:varScope to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5568
                self addClassesFromMessagesSentTo:expr in:varScope to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5569
                ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5570
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5571
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5572
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5573
        classOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5574
            "/ inst var
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5575
            instVarClass := classOrNil whichClassDefinesInstVar:varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5576
            instVarClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5577
                setOfTypes addAll:(self classesOfInstVarNamed:varName inClass:instVarClass).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5578
                ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5579
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5580
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5581
            "/ class vars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5582
            classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5583
            classVarClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5584
                "/ see what is currently there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5585
                setOfTypes add:(classVarClass classVarAt:varName asSymbol) class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5586
                ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5587
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5588
            varName isUppercaseFirst ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5589
                "/ private class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5590
                varName knownAsSymbol ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5591
                    cls := classOrNil theNonMetaclass privateClassesAt:varName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5592
                    cls notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5593
                        setOfTypes add:(cls theMetaclass).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5594
                        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5595
                    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5596
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5597
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5598
            "/ pool vars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5599
            poolVarClass := classOrNil theNonMetaclass whichPoolDefinesPoolVar:varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5600
            poolVarClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5601
                "/ see what is currently there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5602
                setOfTypes add:(poolVarClass classVarAt:varName asSymbol) class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5603
                ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5604
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5605
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5606
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5607
        varName isUppercaseFirst ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5608
            sym := varName asSymbolIfInterned.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5609
            sym notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5610
                exprVal := (Smalltalk at:sym).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5611
                exprVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5612
                    setOfTypes add:(exprVal class).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5613
                ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5614
            ].        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5615
        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5616
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5617
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5618
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5619
    (exprVal := self valueOfNode:expr) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5620
        "/ knowing the value is always great!!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5621
        setOfTypes add:exprVal class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5622
        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5623
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5624
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5625
    expr isMessage ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5626
        self addClassesOfMessage:expr inClass:classOrNil to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5627
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5628
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5629
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5630
    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5631
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5632
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5633
addClassesOfInstVarNamed:varName inClass:aClass to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5634
    |instIndex type|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5635
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5636
    instIndex := aClass instVarIndexFor:varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5637
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5638
    "/ ask the class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5639
    (type := aClass typeOfInstVarNamed:varName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5640
        type isCollection ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5641
            setOfTypes addAll:type.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5642
        ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5643
            setOfTypes add:type.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5644
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5645
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5646
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5647
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5648
    "/ look for instances
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5649
    aClass allSubInstancesDo:[:i |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5650
        |varClass|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5651
        varClass := (i instVarAt:instIndex) class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5652
        setOfTypes add:varClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5653
    ].  
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5654
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5655
    "/ look for assignments in code
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5656
    aClass withAllSubclassesDo:[:eachClass |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5657
        eachClass methodDictionary do:[:m |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5658
            |tree code visitor|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5659
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5660
            "/ quick check
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5661
            code := m source.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5662
            (code notNil and:[code includesString:varName]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5663
                tree := Parser parse:code class:eachClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5664
                (tree notNil and:[tree ~~ #Error]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5665
                    visitor := PluggableParseNodeVisitor new. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5666
                    visitor 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5667
                        actionForNodeClass:AssignmentNode 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5668
                        put:[:node |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5669
                            |val expr exprSelector|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5670
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5671
                            node variable name = varName ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5672
                                expr := node expression.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5673
                                "/ only look for wellknown types on the right side.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5674
                                expr isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5675
                                    val := expr evaluate.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5676
                                    val isArray ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5677
                                        setOfTypes add:Array 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5678
                                    ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5679
                                        setOfTypes add:val class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5680
                                    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5681
                                ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5682
                                    expr isMessage ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5683
                                        exprSelector := expr selector. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5684
                                        ( #(+ - * /) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5685
                                            setOfTypes add:Number
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5686
                                        ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5687
                                            ( #(// size) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5688
                                                setOfTypes add:Integer
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5689
                                            ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5690
                                                ( #(copy shallowCopy) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5691
                                                ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5692
                                                    ( #(new new: basicNew basicNew:) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5693
                                                        expr receiver isGlobal ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5694
                                                            setOfTypes add:expr receiver evaluate
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5695
                                                        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5696
                                                    ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5697
self breakPoint:#cg.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5698
                                                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5699
                                                ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5700
                                            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5701
                                        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5702
                                    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5703
                                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5704
                            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5705
                            true "/ yes - visit subnodes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5706
                        ].        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5707
                    visitor visit:tree.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5708
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5709
            ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5710
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5711
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5712
    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5713
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5714
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5715
addClassesOfMessage:expr inClass:classOrNil to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5716
    |valClass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5717
     msgSelector msgReceiver msgArg1
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5718
     receiverClasses receiverClass 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5719
     arg1Classes arg1Value mthd|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5720
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5721
    msgSelector := expr selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5722
         
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5723
    "/ heuristic: quickly assume boolean for some:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5724
    (
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5725
        #( 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5726
            isNil notNil isEmpty isEmptyOrNil notEmpty notEmptyOrNil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5727
            > >= < <= = == ~ ~=
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5728
            knownAsSymbol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5729
            isMeta 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5730
            includes: contains:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5731
            not and: or:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5732
            exists atEnd positive negative odd even
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5733
        ) includes:msgSelector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5734
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5735
        setOfTypes add:True.  "/ use True, because Boolean does not include the full protocol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5736
        ^ setOfTypes    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5737
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5738
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5739
    msgReceiver := expr receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5740
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5741
    "/ some hardwired knowledge here
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5742
    receiverClasses := self classesOfNode:msgReceiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5743
    receiverClass := receiverClasses size == 1 ifTrue:[receiverClasses anElement] ifFalse:[nil].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5744
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5745
    receiverClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5746
        "/ follow Smalltalk at: to see what is there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5747
        receiverClass == Smalltalk ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5748
            msgSelector == #at: ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5749
                msgArg1 := expr arg1.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5750
                msgArg1 isLiteralSymbol ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5751
                    arg1Value := Smalltalk at:msgArg1 value.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5752
                    arg1Value notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5753
                        setOfTypes add:arg1Value class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5754
                        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5755
                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5756
                ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5757
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5758
        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5759
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5760
        "/ usually return something of the receiver's type
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5761
        ( #(copy shallowCopy copyWith: , ) includes:msgSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5762
            setOfTypes addAll:receiverClasses.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5763
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5764
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5765
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5766
        ( msgSelector == #class ) ifTrue:[  
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5767
            setOfTypes add:(receiverClass class).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5768
            ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5769
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5770
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5771
        receiverClass isBehavior ifTrue:[                        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5772
            ( #(compiledMethodAt:) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5773
                setOfTypes add:Method.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5774
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5775
            ].            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5776
            ( #(superclass) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5777
                receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5778
                    setOfTypes add:Metaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5779
                ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5780
                    setOfTypes add:Class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5781
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5782
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5783
            ].            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5784
            ( #(theNonMetaclass theMetaclass) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5785
                receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5786
                    setOfTypes add:Metaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5787
                    ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5788
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5789
                setOfTypes add:(receiverClass perform:msgSelector) class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5790
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5791
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5792
            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5793
            mthd := receiverClass lookupMethodFor:msgSelector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5794
            receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5795
                ( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: msgSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5796
                    setOfTypes add:receiverClass theNonMetaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5797
                    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5798
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5799
                "/ if that method sends one of new/basicNew/new:/basicNew:, assume it returns an instance of itself
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5800
                mthd notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5801
                    ( mthd sendsAny:#( #'new' #'basicNew' #'new:' #'basicNew:' )) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5802
                        setOfTypes add:receiverClass theNonMetaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5803
                        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5804
                    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5805
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5806
            ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5807
                mthd notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5808
                    (ParseTreeSearcher methodIsSetterMethod:mthd) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5809
                        setOfTypes add:receiverClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5810
                        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5811
                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5812
                ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5813
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5814
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5815
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5816
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5817
    ((msgSelector startsWith:'as')
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5818
    and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5819
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5820
        setOfTypes add:valClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5821
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5822
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5823
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5824
    ((msgSelector startsWith:'is')
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5825
    and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5826
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5827
        setOfTypes add:True. "/ True - not boolean; it does not contain the full protocol (would not find ifTrue:)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5828
        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5829
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5830
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5831
    #(
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5832
        size                    SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5833
        hash                    SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5834
        identityHash            SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5835
        class                   Class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5836
        theMetaclass            Metaclass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5837
        theNonMetaclass         Class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5838
        fork                    Process
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5839
        newProcess              Process
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5840
    ) pairWiseDo:[:sel :clsName |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5841
        msgSelector == sel ifTrue:[ 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5842
            setOfTypes add:(Smalltalk at:clsName).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5843
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5844
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5845
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5846
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5847
    ( #( bitAnd: bitOr: bitShift: rightShift: >> << highBit lowBit ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5848
        "/ assume integer
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5849
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5850
        setOfTypes add:Integer.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5851
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5852
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5853
    ( #( + - * // \\ ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5854
        "/ assume numeric
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5855
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5856
        setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5857
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5858
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5859
    msgSelector == #/ ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5860
        ((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Number]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5861
            setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5862
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5863
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5864
        msgArg1 := expr arguments at:1 ifAbsent:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5865
        msgArg1 isNil ifTrue:[^ setOfTypes].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5866
        arg1Classes := ((self classesOfNode:msgArg1) ? #()).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5867
        (arg1Classes contains:[:cls | cls includesBehavior:Number]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5868
            setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5869
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5870
        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5871
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5872
    ( #( construct: / ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5873
        ((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Filename]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5874
            setOfTypes add:Filename.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5875
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5876
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5877
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5878
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5879
    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5880
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5881
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5882
classOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5883
    "returns the class of a receiver, if it is well-known.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5884
     Otherwise nil (either unknown, or multiple possibilities)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5885
     When showing possible completions for a message,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5886
     it is a good idea to know what the kind receiver is."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5887
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5888
    | classes |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5889
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5890
    classes := self classesOfNode:aNode.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5891
    classes size == 1 ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5892
        ^ classes anElement
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5893
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5894
    self breakPoint:#cg.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5895
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5896
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5897
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5898
classesFromAssignmentTo:varName in:aTree
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5899
    ^ self addClassesFromAssignmentTo:varName in:aTree to:IdentitySet new
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5900
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5901
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5902
classesOfInstVarNamed:varName inClass:aClass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5903
    ^ self addClassesOfInstVarNamed:varName inClass:aClass to:(IdentitySet new)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5904
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5905
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5906
classesOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5907
    "returns the set of possible classes of a parsenode.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5908
     or nil if unknown.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5909
     When showing possible completions for a message,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5910
     it is a good idea to know what the kind receiver is."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5911
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5912
    ^ self addClassesOfExpression:aNode inClass:classOrNil to:(IdentitySet new).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5913
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5914
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5915
isNonDestructive:aMessageNode whenSentTo:receiverValue
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5916
    "return true, if it is safe to send aSelector to receiverValue
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5917
     (i.e. has no side effects)"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5918
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5919
    |selector method impl arg1Value|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5920
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5921
    selector := aMessageNode selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5922
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5923
    impl := receiverValue class whichClassIncludesSelector:selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5924
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5925
    ( #( 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5926
        basicSize basicAt:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5927
        class theMetaclass theNonMetaclass ) includes:selector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5928
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5929
        ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5930
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5931
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5932
    selector == #size ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5933
        "/ mhm - be conservative; someone might have redefined #size
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5934
        "/ more hardwired stuff.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5935
        ((impl == Object) or:[(impl == String) or:[impl isSubclassOf:Collection]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5936
            ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5937
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5938
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5939
    selector == #at: ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5940
        "/ mhm - be conservative; someone might have redefined #at: and do something there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5941
        "/ more hardwired stuff.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5942
        arg1Value := self valueOfNode:(aMessageNode arg1).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5943
        arg1Value notNil ifTrue:[            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5944
            receiverValue == Smalltalk ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5945
                ^ arg1Value isSymbol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5946
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5947
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5948
            ((impl == Object) or:[(impl == String) or:[(impl isSubclassOf:Collection)]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5949
                ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5950
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5951
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5952
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5953
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5954
    selector argumentCount == 0 ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5955
        "/ follow non-destructive accessors
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5956
        method := receiverValue class lookupMethodFor:selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5957
        method notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5958
            (ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5959
                "/ we can savely call that method to get the current value
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5960
                ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5961
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5962
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5963
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5964
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5965
    ^ false
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5966
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5967
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5968
valueAndKindOfVariable:aVariableName
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5969
    "when showing possible completions for a variable,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5970
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5971
     Sigh - returns nil as value both if unknown AND if a real nil is there"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5972
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5973
    |nodeVal con classInstVarClass classVarClass privateClass pool sym nameSpace topNameSpace|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5974
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5975
    aVariableName isUppercaseFirst ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5976
        classOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5977
            classOrNil isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5978
                "/ class instVars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5979
                (classInstVarClass := classOrNil whichClassDefinesInstVar:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5980
                    nodeVal := classInstVarClass theNonMetaclass instVarNamed:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5981
                    ^ { nodeVal . #classInstVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5982
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5983
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5984
            "/ class vars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5985
            (classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5986
                nodeVal := classVarClass classVarAt:aVariableName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5987
                ^ { nodeVal . #classVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5988
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5989
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5990
            privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5991
            privateClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5992
                nodeVal := privateClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5993
                ^ { nodeVal . #privateClass }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5994
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5995
            pool := classOrNil theNonMetaclass whichPoolDefinesPoolVar:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5996
            pool notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5997
                nodeVal := pool classVarAt:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5998
                ^ { nodeVal . #poolVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5999
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6000
            ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6001
                nameSpace isNameSpace ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6002
                    nodeVal := nameSpace at:aVariableName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6003
                    ^ { nodeVal . #nameSpaceVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6004
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6005
                nodeVal := nameSpace privateClassNamed:aVariableName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6006
                ^ { nodeVal . #privateClass }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6007
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6008
            ((topNameSpace := classOrNil topNameSpace) notNil 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6009
            and:[topNameSpace ~~ nameSpace
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6010
            and:[topNameSpace ~~ Smalltalk]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6011
                nodeVal := topNameSpace at:aVariableName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6012
                ^ { nodeVal . #nameSpaceVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6013
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6014
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6015
        (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6016
            nodeVal := Smalltalk at:sym.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6017
            (nodeVal notNil or:[Smalltalk includesKey:sym]) ifTrue:[     
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6018
                ^ { nodeVal . #global }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6019
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6020
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6021
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6022
        "/ 'evaluate' the variable (like in a browser's codeView)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6023
        "/ mhmh - will we catch workspace vars then?
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6024
        Error handle:[:ex |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6025
        ] do:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6026
            nodeVal := Parser new evaluate:aVariableName in:classOrNil receiver:classOrNil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6027
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6028
        nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6029
            ^ { nodeVal . #global }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6030
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6031
        ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6032
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6033
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6034
    aVariableName = 'self' ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6035
        contextOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6036
            ^ { contextOrNil receiver . #pseudoVar } 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6037
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6038
        (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6039
            "/ ^ { classOrNil . #pseudoVar }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6040
            ^ { classOrNil theNonMetaclass . #pseudoVar }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6041
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6042
        ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6043
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6044
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6045
    contextOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6046
        "/ in the debugger, we know more
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6047
        con := contextOrNil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6048
        [ con notNil ] whileTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6049
            "/ a local in the context?
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6050
            ((con argAndVarNames ? #()) includes:aVariableName) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6051
                nodeVal := con argsAndVars at:(con argAndVarNames indexOf:aVariableName) ifAbsent:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6052
                nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6053
                    ^ { nodeVal . #argument }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6054
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6055
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6056
            con := con home.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6057
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6058
        "/ an instvar
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6059
        (contextOrNil receiver class allInstVarNames includes:aVariableName) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6060
            nodeVal := contextOrNil receiver instVarNamed:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6061
            nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6062
                ^ { nodeVal . #instanceVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6063
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6064
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6065
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6066
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6067
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6068
    "Created: / 01-05-2016 / 12:40:05 / cg"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6069
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6070
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6071
valueOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6072
    "when showing possible completions for a message,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6073
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6074
     Sigh - returns nil both if unknown AND if a real nil is there."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6075
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6076
    |nodeSelector nodeReceiver isNonDestructive receiverValue arg1Value|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6077
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6078
    aNode isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6079
        ^ aNode value
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6080
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6081
    aNode isVariable ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6082
        ^ self valueOfVariable:aNode name.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6083
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6084
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6085
    aNode isMessage ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6086
        nodeSelector := aNode selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6087
        nodeReceiver := aNode receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6088
                
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6089
        "/ some hardwired knowledge here
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6090
        classOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6091
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6092
                ^ classOrNil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6093
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6094
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6095
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6096
        receiverValue := self valueOfNode:nodeReceiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6097
        receiverValue notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6098
            isNonDestructive := self isNonDestructive:aNode whenSentTo:receiverValue.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6099
            isNonDestructive ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6100
                nodeSelector argumentCount == 1 ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6101
                    arg1Value := self valueOfNode:(aNode arg1).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6102
                    [
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6103
                        ^ receiverValue perform: nodeSelector with: arg1Value.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6104
                    ] on:Error do:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6105
                        ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6106
                    ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6107
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6108
                ^ receiverValue perform: nodeSelector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6109
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6110
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6111
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6112
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6113
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6114
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6115
    "Created: / 28-08-2013 / 16:34:53 / cg"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6116
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6117
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6118
valueOfVariable:aVariableName
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6119
    "when showing possible completions for a variable,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6120
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6121
     Sigh - returns nil both if unknown AND if a real nil is there."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6122
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6123
    |valueAndKind|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6124
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6125
    (valueAndKind := self valueAndKindOfVariable:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6126
        self assert:valueAndKind isArray.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6127
        ^ valueAndKind first.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6128
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6129
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6130
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6131
    "Modified: / 01-05-2016 / 12:41:30 / cg"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6132
! !
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6133
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6134
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6135
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6136
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6137
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6138
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6139
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6140
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6141
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6142
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6143
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6144
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6145
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6146
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6147
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6148
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6149
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6150
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6151
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6152
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6153
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6154
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6155
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6156
version
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  6157
    ^ '$Header$'
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6158
!
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6159
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  6160
version_CVS
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  6161
    ^ '$Header$'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6162
! !
4194
e677aae984be Refactoring:
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
  6163