DoWhatIMeanSupport.st
author Claus Gittinger <cg@exept.de>
Tue, 02 Feb 2016 23:38:30 +0100
changeset 4954 5224a5211ae5
parent 4951 570438fc0023
child 4955 08ce57096e06
child 4976 2e6c19f32c49
permissions -rw-r--r--
#UI_ENHANCEMENT class: DoWhatIMeanSupport changed: #codeCompletionForVariable:into: instance creation code completion messages
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
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
    21
		LastCompletedSelectors'
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
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   219
		2nd: collection consisting of matching names"
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
    aPartialClassName isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   225
	matches := Smalltalk allClassesForWhich:filterBlock.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   226
	^ InputCompletionResult bestName:aPartialClassName matchingNames:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   227
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   228
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   229
    (words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   230
	w1 := words first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   231
	w2 := words second.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   232
	rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   233
	bestMatch := rslt first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   234
	matches := rslt second.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   235
	('class' copyTo:(w2 size min:5)) = w2 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   236
	    matches := matches collect:[:m | m , ' class'].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   237
	    bestMatch := bestMatch , ' class'.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   238
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   239
	^ InputCompletionResult bestName:bestMatch matchingNames:matches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   240
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   241
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   242
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   243
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   244
	nsPrefix := 'Smalltalk::'.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   245
	searchName := aPartialClassName withoutPrefix:'Smalltalk::'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   246
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   247
	nsPrefix := ''.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   248
	searchName := aPartialClassName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   249
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   250
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   251
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   252
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   253
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   254
    isMatchString := searchName includesMatchCharacters.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   255
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   256
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   257
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   258
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   259
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   260
    tryToMatch :=
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   261
	[:className :fullClassName|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   262
	    |addIt|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   263
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   264
	    isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   265
		addIt := searchName match:className
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   266
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   267
		addIt := className startsWith:searchName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   268
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   269
	    addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   270
		matches add:(nsPrefix , fullClassName).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   271
		matchedNamesWithoutPrefix add:className.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   272
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   273
		"/ try ignoring case
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   274
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   275
		isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   276
		    addIt := searchName match:className caseSensitive:false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   277
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   278
		    addIt := className asLowercase startsWith:lcSearchName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   279
		    addIt ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   280
			others add:className
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   281
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   282
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   283
		addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   284
		    ignCaseMatches add:(nsPrefix , fullClassName).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   285
		    matchedNamesWithoutPrefix add:className.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   286
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   287
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   288
	    addIt
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   289
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   290
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   291
    anEnvironment allClassesForWhich:filterBlock do:[:aClass |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   292
	|addIt fullClassName classNameWithoutPrefix|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   293
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   294
	aClass isMeta ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   295
	    fullClassName := aClass name.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   296
	    classNameWithoutPrefix := aClass nameWithoutPrefix.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   297
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   298
	    addIt := tryToMatch value:fullClassName value:fullClassName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   299
	    addIt ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   300
		classNameWithoutPrefix ~~ fullClassName ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   301
		    tryToMatch value:classNameWithoutPrefix value:fullClassName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   302
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   303
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   304
	]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   305
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   306
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   307
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   308
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   309
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   310
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   311
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   312
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   313
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   314
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   315
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   316
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   317
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   318
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   319
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   320
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   321
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   322
"/"/            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
   323
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   324
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   325
"/"/            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
   326
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   327
"/"/            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
   328
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   329
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
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
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   332
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   333
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   334
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   335
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   336
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   337
	^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   338
    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   339
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   340
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   341
	best := matches first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   342
	^ 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
   343
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   344
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   345
    matches
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   346
	sort:[:name1 :name2 |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   347
	    "name1 comes before:name2 iff"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   348
	    ((name2 includes:$:) and:[(name1 includes:$:) not])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   349
	    or:[ ((name1 includes:$:) == (name2 includes:$:))
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   350
		  and:[ (name1 size < name2 size)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   351
			or: [ name1 < name2 ]]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   352
	       ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   353
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   354
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   355
    isMatchString ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   356
	best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   357
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   358
	matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   359
	best := ignCaseMatches isEmpty
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   360
		    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   361
		    ifFalse:[ matchesForLongestPrefix longestCommonPrefixCaseSensitive:false ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   362
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   363
	best size < aPartialClassName size "best size == 0" ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   364
	    best := matchedNamesWithoutPrefix longestCommonPrefix.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   365
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   366
	best size == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   367
	    "if tried again, return next match"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   368
	    idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   369
	    idx ~~ 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   370
		^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   371
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   372
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   373
	best size < aPartialClassName size ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   374
	    best := aPartialClassName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   375
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   376
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   377
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   378
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   379
    (cls isBehavior and:[cls isNameSpace]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   380
	(matches conform:[:each | each = best
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   381
				 or:[each startsWith:(best , '::')]])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   382
	ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   383
	    best := best , '::'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   384
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   385
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   386
    ^ 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
   387
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   388
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   389
     Smalltalk classnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   390
     Smalltalk classnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   391
     Smalltalk classnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   392
     Smalltalk classnameCompletion:'*rray'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   393
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   394
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   395
    "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
   396
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   397
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   398
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   399
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   400
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   401
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   402
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   403
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   404
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   405
	filter:[:cls | true]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   406
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   407
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   408
    "
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   409
     self classnameCompletion:'Arr'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   410
     self classnameCompletion:'Arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   411
     self classnameCompletion:'arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   412
     self classnameCompletion:'*rray' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   413
    "
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
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   416
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   417
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   418
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   419
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   420
    "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
   421
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   422
    ^ [:contents :field  |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   423
	  |s what m|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   424
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   425
	  s := contents withoutSpaces.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   426
	  field topView withCursor:(Cursor questionMark) do:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   427
	      what := self perform:completionSelector with:s with:Smalltalk.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   428
	  ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   429
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   430
	  field contents:(what first).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   431
	  (what at:2) size ~~ 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   432
	      UserPreferences current beepInEditor ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   433
		field device beep
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   434
	      ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   435
	  ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   436
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   437
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   438
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   439
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   440
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   441
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   442
    "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
   443
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   444
		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
   445
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   446
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   447
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   448
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   449
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   450
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   451
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   452
     Smalltalk globalnameCompletion:'*rray'
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   453
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   454
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   455
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   456
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   457
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   458
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   459
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   460
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   461
		2nd: collection consisting of matching names"
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   462
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   463
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   464
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   465
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   466
    searchName isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   467
	^ Array with:searchName with:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   468
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   469
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   470
    (searchName at:1) isLowercase ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   471
	searchName := searchName copy asUppercaseFirst
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   472
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   473
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   474
    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
   475
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   476
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   477
    anEnvironment keysDo:[:aGlobalName |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   478
	| addIt|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   479
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   480
	isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   481
	    addIt := searchName match:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   482
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   483
	    addIt := aGlobalName startsWith:searchName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   484
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   485
	addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   486
	    matches add:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   487
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   488
	    "/ try ignoring case
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   489
	    isMatchString ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   490
		addIt := searchName match:aGlobalName caseSensitive:false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   491
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   492
		addIt := aGlobalName asLowercase startsWith:searchName asLowercase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   493
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   494
	    addIt ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   495
		ignCaseMatches add:aGlobalName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   496
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   497
	]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   498
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   499
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   500
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   501
	matches := ignCaseMatches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   502
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   503
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   504
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   505
	^ 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
   506
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   507
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   508
	^ 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
   509
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   510
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   511
    isMatchString ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   512
	best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   513
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   514
	best := matches longestCommonPrefix.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   515
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   516
    ^ 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
   517
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   518
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   519
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   520
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   521
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   522
     Smalltalk globalnameCompletion:'*rray'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   523
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   524
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   525
    "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
   526
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   527
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   528
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   529
    "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
   530
     2 entries: 1st: the best (longest) match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   531
		2nd: collection consisting of matching protocols"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   532
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   533
    |matches best lcName|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   534
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   535
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   536
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   537
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   538
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   539
	|protocol|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   540
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   541
	protocol := eachMethod category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   542
	(protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   543
	    matches add:protocol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   544
	].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   545
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   546
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   547
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   548
	lcName := aPartialProtocolName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   549
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   550
	    |protocol|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   551
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   552
	    protocol := eachMethod category.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   553
	    (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   554
		matches add:protocol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   555
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   556
	].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   557
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   558
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   559
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   560
	^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   561
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   562
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   563
	^ Array with:matches first with:(matches asArray)
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
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   566
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   567
    ^ Array with:best with:matches asArray
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
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   570
     Smalltalk methodProtocolCompletion:'doc'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   571
     Smalltalk methodProtocolCompletion:'docu'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   572
     Smalltalk methodProtocolCompletion:'documenta'
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   573
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   574
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   575
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   576
    "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
   577
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   578
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   579
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   580
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   581
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   582
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   583
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   584
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   585
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   586
	filter:[:cls | cls isNameSpace]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   587
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   588
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   589
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   590
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   591
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   592
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   593
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   594
!
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
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   597
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   598
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   599
		2nd: collection consisting of matching packages"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   600
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   601
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   602
4195
f154f90d39a6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4194
diff changeset
   603
    matches := Smalltalk allProjectIDs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   604
	select:[:package | package startsWith:aPartialPackage].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   605
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   606
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   607
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   608
	lcName := aPartialPackage asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   609
	anEnvironment allClassesDo:[:aClass |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   610
	    |package|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   611
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   612
	    package := aClass package.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   613
	    (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   614
		matches add:package
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   615
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   616
	].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   617
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   618
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   619
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   620
	^ Array with:aPartialPackage with:(Array with:aPartialPackage)
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   621
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   622
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   623
	^ Array with:matches first with:(matches asArray)
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
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   626
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   627
    ^ Array with:best with:matches asArray
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
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   630
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   631
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   632
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   633
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   634
    "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
   635
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   636
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   637
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   638
    "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
   639
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   640
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   641
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   642
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   643
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   644
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   645
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   646
    "given a partial poolname, return an array consisting of
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   647
     2 entries: 1st: the best (longest) match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   648
		2nd: collection consisting of matching names"
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   649
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   650
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   651
	classnameCompletion:aPartialClassName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   652
	filter:[:cls | cls isSharedPool]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   653
	inEnvironment:anEnvironment
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   654
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   655
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   656
     self poolnameCompletion:'Win' inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   657
     self poolnameCompletion:'Z'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   658
     self poolnameCompletion:'a'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   659
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   660
!
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   661
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   662
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   663
    "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
   664
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   665
		2nd: collection consisting of matching defined resources"
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   666
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   667
    |matches best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   668
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   669
    matches := IdentitySet new.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   670
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   671
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   672
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   673
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   674
	eachMethod hasResource ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   675
	    eachMethod resources keysDo:[:eachResourceName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   676
		(isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   677
		    ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:ignoreCase not) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   678
		    ifFalse:[ ignoreCase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   679
				ifTrue:[ (eachResourceName asLowercase startsWith:aPartialResourceName asLowercase) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   680
				ifFalse:[ (eachResourceName startsWith:aPartialResourceName) ] ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   681
		) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   682
		    matches add:eachResourceName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   683
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   684
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   685
	].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   686
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   687
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   688
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   689
	lcSym := aPartialResourceName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   690
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   691
	    eachMethod hasResource ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   692
		eachMethod resources keysDo:[:eachResourceName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   693
		    (isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   694
			ifTrue:[ (aPartialResourceName match:eachResourceName caseSensitive:false) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   695
			ifFalse:[ (eachResourceName asLowercase startsWith:lcSym) ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   696
		     ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   697
			matches add:eachResourceName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   698
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   699
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   700
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   701
	].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   702
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   703
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   704
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   705
	^ Array with:aPartialResourceName with:#()
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   706
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   707
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   708
	^ Array with:matches first with:(matches asArray)
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
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   711
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   712
    ^ Array with:best with:matches asArray
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
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   715
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   716
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   717
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   718
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   719
    "
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
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   722
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   723
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   724
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   725
    "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
   726
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   727
		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
   728
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   729
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   730
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   731
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   732
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   733
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   734
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   735
		2nd: collection consisting of matching implemented selectors"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   736
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   737
    ^ self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   738
	selectorCompletion:aPartialSymbolName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   739
	inEnvironment:anEnvironment
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   740
	match:doMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   741
	ignoreCase:false
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   742
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   743
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   744
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   745
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   746
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   747
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   748
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
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
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   751
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   752
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   753
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   754
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   755
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   756
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   757
     2 entries: 1st: the longest match
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   758
		2nd: collection consisting of matching implemented selectors"
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   759
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   760
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   761
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   762
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   763
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   764
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   765
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   766
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   767
	(isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   768
	    ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:ignoreCase not) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   769
	    ifFalse:[ ignoreCase
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   770
			ifTrue:[ (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   771
			ifFalse:[ (eachSelector startsWith:aPartialSymbolName) ] ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   772
	 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   773
	    matches add:eachSelector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   774
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   775
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   776
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   777
	"/ search for case-ignoring match
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   778
	lcSym := aPartialSymbolName asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   779
	anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   780
	    (isMatch
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   781
		ifTrue:[ (aPartialSymbolName match:eachSelector caseSensitive:false) ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   782
		ifFalse:[ (eachSelector asLowercase startsWith:lcSym) ])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   783
	     ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   784
		matches add:eachSelector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   785
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   786
	].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   787
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   788
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   789
    matches isEmpty ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   790
	^ 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
   791
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   792
    matches size == 1 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   793
	^ 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
   794
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   795
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   796
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   797
    ^ 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
   798
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   799
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   800
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   801
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   802
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   803
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   804
     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
   805
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   806
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   807
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   808
    "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
   809
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   810
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   814
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   815
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   816
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   817
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
    (lastNewName endsWith:lastOldName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   825
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   826
	    'foo' -> 'Xfoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   827
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   828
	    'bar' would be 'Xbar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   829
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   830
	prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   831
	^ (prefix , oldName).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
    (lastOldName endsWith:lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   834
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   835
	    'Xfoo' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   836
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   837
	    'Xbar' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   838
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   839
	prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   840
	(oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   841
	    ^ (oldName copyFrom:prefix size+1).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   842
	]
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   843
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   844
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   845
	(lastOldName first ~= lastNewName first) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   846
	    (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   847
		"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   848
		    'xfoo' -> 'Xfoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   849
		 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   850
		    'xbar' would be 'Xbar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   851
		"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   852
		lastOldName first isLowercase ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   853
		    ^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   854
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   855
		    ^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   856
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   857
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   858
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   861
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   862
	    '  foo   ' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   863
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   864
	    '  bar   ' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   865
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   866
	^ oldName withoutSeparators.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    (lastNewName startsWith:lastOldName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   869
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   870
	    'foo' -> 'fooX'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   871
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   872
	    'bar' would be 'barX'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   873
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   874
	suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   875
	^ (oldName , suffix).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
    (lastOldName startsWith:lastNewName) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   878
	"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   879
	    'fooX' -> 'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   880
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   881
	    'barX' would be 'bar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   882
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   883
	suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   884
	(oldName endsWith:suffix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   885
	    ^ (oldName copyButLast:suffix size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   886
	]
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   887
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   888
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   889
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   890
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   891
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   892
    (prefix size > 0) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   893
	(suffix size > 0) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   894
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   895
	    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
   896
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   897
	    "last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   898
		'fooR' -> 'fooXR'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   899
	     then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   900
		'barR' would be 'barXR'
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
	    left := lastOldName copyTo:prefix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   903
	    right := lastOldName copyLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   904
	    lastNewSize > lastOldSize ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   905
		inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   906
		inserted size > 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   907
		    (oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   908
			^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   909
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   910
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   911
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   912
	    (oldName string endsWith:suffix string) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   913
		deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   914
		(oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   915
		    ((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
   916
			"last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   917
			    'fooXR' -> 'fooR'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   918
			 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   919
			    'barXS' would be 'barS'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   920
			"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   921
			^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   922
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   923
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   924
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   925
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   926
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   927
	(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   928
	    "last rename was
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   929
		'fooX' -> 'fooY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   930
	     then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   931
		'barX' would be 'barY'
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
	    left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   934
	    right := lastNewName copyFrom:prefix size+1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   935
	    ^ left , right
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   936
	]
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   937
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   939
    suffix size > 0 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   940
	|prefix2|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   941
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   942
	"last rename was:
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   943
	    'fooSUFF1' -> 'barSUFF1'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   944
	 then, a good default for
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   945
	    'fooSUFF2' -> 'barSUFF2'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   946
	"
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   947
	prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   948
	(oldName startsWith:prefix) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   949
	    prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   950
	    ^ prefix2,(oldName copyFrom:(prefix size+1)).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   951
	].
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   952
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   953
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   954
    "/ was there something stripped at the end?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   955
    suffix := oldName commonSuffixWith:lastOldName.
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   956
    [suffix size > 0] whileTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   957
	tryAgain := self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   958
		    goodRenameDefaultFor:(oldName copyButLast:suffix size)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   959
		    lastOld:(lastOldName copyButLast:suffix size)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   960
		    lastNew:lastNewName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   961
	tryAgain notNil ifTrue:[^ tryAgain].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   962
	suffix := suffix copyFrom:2.
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   963
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   964
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   965
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   966
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   967
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   968
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   969
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   970
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo'
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   971
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
   972
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   973
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   974
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   975
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   976
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
   977
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   978
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   979
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   980
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   981
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   982
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   983
     self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   984
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   985
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   986
		       lastOld:'mti.odt2.level1HeadlineMatchPattern'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   987
		       lastNew:'Key_odt2_level1HeadlineMatchPattern'
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
   988
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   989
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   990
    "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
   991
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   992
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   993
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   994
    "generate a reasonable default for a file rename operation.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   995
     (Try to rename multiple files in the new fileBrowser,
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   996
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   997
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   998
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
   999
     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
  1000
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1001
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1002
    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
  1003
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1004
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1005
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1006
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1007
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1008
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1009
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1010
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1011
	lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1012
	    ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1013
	].
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1014
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1015
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1016
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1017
    default notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1018
	lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1019
	lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1020
	oldRest := oldName copyFrom:oldWOSuffix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1021
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1022
	^ default , lastNewRest
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1023
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1024
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1025
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1026
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1027
	lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1028
	lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1029
	oldRest := oldWOSuffix copyFrom:prefix size + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1030
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1031
	(lastNewRest endsWith:lastOldRest) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1032
	    t := lastNewRest copyButLast:lastOldRest size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1033
	    ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1034
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1037
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
    suffix size > 0 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1039
	"/ last change changed something at the beginning
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1040
	prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1041
	prefix size > 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1042
	    "/ this name starts with the same characters
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1043
	    lastRemoved := lastOldWOSuffix copyButLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1044
	    lastInserted := lastNewWOSuffix copyButLast:suffix size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1045
	    (lastRemoved startsWith:lastInserted) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1046
		oldWOSuffix size >= lastInserted size ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1047
		    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1048
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1049
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1050
	    ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1051
	].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1052
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1053
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1055
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1056
    "Modified: / 07-11-2006 / 13:58:39 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1059
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1060
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1061
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1062
    "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
  1063
     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
  1064
     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
  1065
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1066
    ^ 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
  1067
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1068
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1069
     self isKey:$a nextTo:$a
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1070
     self isKey:$a nextTo:$s
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1071
     self isKey:$a nextTo:$q
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1072
     self isKey:$a nextTo:$w
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1073
     self isKey:$a nextTo:$z
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1074
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1075
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1076
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1077
    "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
  1078
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1079
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1080
isKey:k1 nextTo:k2 onKeyboard:keys
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1081
    "return true, if k1 and k2 are adjacent keys on the keyboard defined by keys"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1082
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1083
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1084
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1085
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1086
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1087
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1088
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1089
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1090
    ^ (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
  1091
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1092
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1093
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1094
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1095
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1096
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1097
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1098
keyboard
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1099
    "the keyboard layout
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1100
     (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
  1101
     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
  1102
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1103
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1104
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1105
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1106
    lang == #de ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1107
	^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1108
	       '1234567890-'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1109
	       '*qwertzuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1110
	       '**asdfghjkl:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1111
	       '***yxcvbnm'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1112
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1113
    ].
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 == #fr ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1116
	^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1117
	       '1234567890'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1118
	       '*azertyuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1119
	       '**qsdfghjklm'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1120
	       '***wxcvbn,'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1121
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1122
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1123
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1124
    ^ #(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1125
	   '1234567890-'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1126
	   '*qwertyuiop'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1127
	   '**asdfghjkl:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1128
	   '***zxcvbnm'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1129
    ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1130
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1131
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1132
     self keyboard
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1133
    "
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
    "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
  1136
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1137
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1138
!DoWhatIMeanSupport methodsFor:'code completion'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1139
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1140
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
  1141
    "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
  1142
     (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
  1143
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1144
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1145
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1146
        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
  1147
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1148
           (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
  1149
     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
  1150
     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
  1151
     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
  1152
     perform the completion.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1153
     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
  1154
     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
  1155
     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
  1156
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1157
     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
  1158
     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
  1159
     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
  1160
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1161
    | language |
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1162
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1163
    codeAspect := codeAspectArg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1164
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1165
    languageOrNilArg notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1166
        language := languageOrNilArg
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1167
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1168
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1169
            | method |
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1170
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1171
            method := contextOrNilArg method.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1172
            method notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1173
                language := method programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1174
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1175
                contextOrNilArg isJavaContext ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1176
                    language := JavaLanguage instance
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1177
                ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1178
                    language := SmalltalkLanguage instance.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1179
                ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1180
            ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1181
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1182
            methodOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1183
                language := methodOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1184
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1185
                classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1186
                    language := classOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1187
                ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1188
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1189
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1190
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1191
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1192
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1193
        language isSmalltalk ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1194
            ^self codeCompletionForSmalltalkMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1195
        ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1196
        language isSTXJavaScript ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1197
            ^self codeCompletionForJavascriptMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1198
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1199
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1200
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1201
    "/ No completion support for given language
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1202
    self breakPoint: #cg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1203
    self breakPoint: #jv.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1204
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1205
    "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
  1206
    "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
  1207
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1208
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1209
codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNilArg codeView:codeViewArg
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1210
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1211
     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
  1212
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1213
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1214
     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
  1215
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1216
    | language |
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1217
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1218
    languageOrNil notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1219
        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
  1220
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1221
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1222
            language := contextOrNilArg method programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1223
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1224
            classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1225
                language := classOrNilArg programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1226
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1227
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1228
    ].
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
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1231
        language isSmalltalk ifTrue:[
4731
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1232
            classOrNil := classOrNilArg.
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1233
            contextOrNil := contextOrNilArg.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1234
            ^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1235
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1236
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1237
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1238
    "/ 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
  1239
    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
  1240
    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
  1241
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1242
    "Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1243
! !
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1244
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1245
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'!
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1246
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1247
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1248
    "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
  1249
     (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
  1250
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1251
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1252
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1253
        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
  1254
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1255
           (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
  1256
     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
  1257
     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
  1258
     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
  1259
     perform the completion.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1260
     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
  1261
     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
  1262
     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
  1263
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1264
     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
  1265
     or nil, if called from the browser.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1266
     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
  1267
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1268
    languageOrNil := STXJavaScriptLanguage instance.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1269
    methodOrNil := methodOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1270
    classOrNil := classOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1271
    codeView := codeViewArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1272
    contextOrNil := contextOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1273
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1274
    JavaScriptCompletionEngine notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1275
        JavaScriptCompletionEngine new
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1276
           completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1277
    ].
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1278
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1279
    self information:'Not yet supported'.
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
    "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
  1282
    "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
  1283
! !
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1284
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1285
!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
  1286
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1287
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1288
4379
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1289
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1290
     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
  1291
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1292
     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
  1293
     This is not yet done, sigh"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1294
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1295
    |crsrPos char interval source node parent checkedNode instanceOrNilArg
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1296
     forceNewMessageSend classOfReceiver prevChar|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1297
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1298
    languageOrNil := SmalltalkLanguage instance.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1299
    classOrNil := classOrNilArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1300
    codeView := codeViewArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1301
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1302
    crsrPos := codeView characterPositionOfCursor"-1".
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1303
    char := codeView characterAtCharacterPosition:crsrPos.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1304
    "/ Transcript show:crsrPos; show:' '; showCR:char.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1305
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1306
        crsrPos := crsrPos - 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1307
        char := codeView characterAtCharacterPosition:crsrPos.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1308
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1309
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1310
    interval := codeView selectedInterval.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1311
    "/ Transcript show:'iv: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1312
    interval isEmpty ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1313
        interval := crsrPos"-1" to:crsrPos.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1314
        "/ Transcript show:'iv2: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1315
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1316
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1317
    source := codeView contentsAsString string.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1318
    source := source copyTo:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1319
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1320
    "/ this is too naive and stupid; if there is a syntactic error,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1321
    "/ 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
  1322
    "/ 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
  1323
    "/ without any progress.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1324
    "/ 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
  1325
    "/ as it parses the code. Stop, when the interval is hit.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1326
    "/ that will also work for syntactic incorrect source code.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1327
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1328
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1329
        "/ Transcript show:'nd1: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1330
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1331
    node isNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1332
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1333
        "/ Transcript show:'nd2 try: '; showCR:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1334
        node isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1335
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1336
            self breakPoint:#cg.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1337
            "/ self information:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1338
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1339
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1340
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1341
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1342
    forceNewMessageSend := false.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1343
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1344
    "/ 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
  1345
    prevChar := codeView characterBeforeCursor.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1346
    (prevChar isSeparator or:[ ')}]''' includes:prevChar ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1347
        (node isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1348
            and:[ (parent := node parent) notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1349
            and:[ parent isMessage ]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1350
        ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1351
            "/ completion after a variable node...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1352
            parent isKeyword ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1353
                "/ and it is a keyword message, we complete the keyword message instead
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1354
                node := parent.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1355
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1356
                "/ 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
  1357
                "/ (however, no character is available to determine what is useful)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1358
                forceNewMessageSend := true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1359
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1360
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1361
            (node isMessage and:[node isUnary]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1362
                "/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1363
                "/
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1364
                forceNewMessageSend := true.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1365
"/                "/ can we see what we get from foo?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1366
"/                classOfReceiver := self
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1367
"/                                    classOfReceiver:node receiver
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1368
"/                                    inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1369
"/                classOfReceiver notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1370
"/                    |mthd|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1371
"/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1372
"/                    mthd := classOfReceiver lookupMethodFor:node selector.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1373
"/                    mthd notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1374
"/                        self halt.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1375
"/                        (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1376
"/                            forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1377
"/                        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1378
"/                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1379
"/                ].
4710
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
        ]
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1382
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1383
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1384
    forceNewMessageSend ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1385
        "/ completion with nothing to start (right after a variable)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1386
        "/ 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
  1387
        classOfReceiver := self classOfNode:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1388
        classOfReceiver isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1389
            "/ 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
  1390
            "/ will be...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1391
            Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1392
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1393
            |superClass possible choice|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1394
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1395
            possible := classOfReceiver selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1396
            superClass := classOfReceiver superclass.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1397
            [superClass notNil "and:[(possible size + superClass selectors size) < 500]"] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1398
                possible := possible,superClass selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1399
                superClass := superClass superclass.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1400
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1401
            possible := possible copy sort.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1402
            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
  1403
            choice isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1404
                Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1405
                ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1406
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1407
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1408
            codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1409
                undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1410
                    codeView insertStringAtCursor: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
                info:'Completion'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1413
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1414
        ^ self
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1415
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1416
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1417
    node isVariable ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1418
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1419
        ^ self.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1420
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1421
    node isLiteral ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1422
        node value isSymbol ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1423
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1424
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1425
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1426
        ^ self "/ huh - strings or what?
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1427
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1428
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1429
    checkedNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1430
    [checkedNode notNil] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1431
        checkedNode isMessage ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1432
            "/ completion in a message-send
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1433
            contextOrNilArg notNil ifTrue:[
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1434
"/                |rcvrNode idx rcvr val|
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1435
"/
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1436
"/                (rcvrNode := checkedNode receiver) isVariable ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1437
"/                    rcvrNode isSelf ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1438
"/                        classOrNil := contextOrNil receiver class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1439
"/                    ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1440
"/                        (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1441
"/                            val := contextOrNil argsAndVars at:idx.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1442
"/                            classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1443
"/                        ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1444
"/                            (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1445
"/                                val := contextOrNil receiver instVarNamed:rcvrNode name.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1446
"/                                classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1447
"/                            ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1448
"/                        ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1449
"/                    ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1450
"/                ].
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1451
                instanceOrNilArg := contextOrNilArg receiver
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1452
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1453
            self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1454
                codeCompletionForMessage:checkedNode
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1455
                inClass:classOrNil instance:instanceOrNilArg
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1456
                context:contextOrNilArg codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1457
            ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1458
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1459
        checkedNode isMethod ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1460
            "/ completion in a method's selector pattern
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1461
            self codeCompletionForMethodSpec:checkedNode.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1462
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1463
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1464
        checkedNode := checkedNode parent.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1465
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1466
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1467
    self information:'Node is neither variable nor message.'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1468
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1469
    "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
  1470
!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1471
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1472
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
  1473
    "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
  1474
     (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
  1475
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1476
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1477
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1478
        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
  1479
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1480
           (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
  1481
     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
  1482
     or adding another keyword part after the cursor is possible.
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1483
     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
  1484
     to perform the completion.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1485
     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
  1486
     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
  1487
     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
  1488
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1489
     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
  1490
     or nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1491
     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
  1492
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1493
    |crsrPos char interval i source partialSource cursorLineSource
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1494
     suggestions actions title|
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1495
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1496
    languageOrNil := SmalltalkLanguage instance.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1497
    methodOrNil := methodOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1498
    classOrNil := classOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1499
    codeView := codeViewArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1500
    contextOrNil := contextOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1501
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1502
"/    classOrNil isNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1503
"/        self information:'No class'.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1504
"/        ^ self.
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
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1507
    crsrPos := codeView characterPositionOfCursor.
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  1508
    char := codeView characterAtCharacterPosition:(crsrPos-1 max:1).
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1509
    [crsrPos > 1 and:[char isSeparator "or:['.' includes:char]"]] whileTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1510
        crsrPos := crsrPos - 1.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1511
        char := codeView characterAtCharacterPosition:crsrPos.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1512
    ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1513
4711
1c2e635489e5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4710
diff changeset
  1514
    char == $. ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1515
        "/ either at end of statement or after a character constant
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1516
        crsrPos == 1 ifTrue:[^ self].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1517
        (codeView characterAtCharacterPosition:crsrPos-1) == $$ ifFalse:[^ self].
4391
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
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1520
    interval := crsrPos-1 to:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1521
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1522
    source := codeView contentsAsString string.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1523
    partialSource := source copyTo:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1524
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1525
    methodOrNilArg isNil ifTrue:[
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1526
        (partialSource endsWith:Character cr) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1527
            partialSource := partialSource copyButLast.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1528
        ].    
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1529
        "/ first try parsing the current cursor line.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1530
        "/ 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
  1531
        (i := partialSource lastIndexOf:Character cr) ~~ 0 ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1532
            "/ because cursorPositions and node-positions are required elsewhere to be correct,
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1533
            "/ 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
  1534
            "/ 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
  1535
            "/ However, because somewhere else, we fetch characters from the codeView using the index,
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1536
            "/ we must preserve the line structure (i.e. keep crs).
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1537
            cursorLineSource := partialSource copy.
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1538
            1 to:i do:[:pos | 
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1539
                (cursorLineSource at:pos) ~= Character cr ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1540
                    cursorLineSource at:pos put:Character space.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1541
                ]
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1542
            ].    
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1543
            self
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1544
                tryCodeCompletionWithSource:cursorLineSource nodeInterval:interval
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1545
                at:crsrPos mustBeExpression:true
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1546
                into:[:listOfSuggestions :listOfActions :titleWhenAsking |
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1547
                    suggestions := listOfSuggestions.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1548
                    actions := listOfActions.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1549
                    title := titleWhenAsking.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1550
                ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1551
        ].
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1552
    ].
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1553
    
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1554
    suggestions isEmptyOrNil ifTrue:[
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1555
        "/ try parsing the partial source (from beginning up to the cursor)
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1556
        self
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1557
            tryCodeCompletionWithSource:partialSource nodeInterval:interval
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1558
            at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil])
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1559
            into:[:listOfSuggestions :listOfActions :titleWhenAsking |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1560
                suggestions := listOfSuggestions.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1561
                actions := listOfActions.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1562
                title := titleWhenAsking.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1563
                "/ suggestions1 size>100 ifTrue:[ self halt].
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1564
            ].
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1565
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1566
        suggestions isEmptyOrNil ifTrue:[
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1567
            "/ then try parsing the whole source
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1568
            self
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1569
                tryCodeCompletionWithSource:source nodeInterval:interval
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1570
                at:crsrPos mustBeExpression:false
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1571
                into:[:listOfSuggestions :listOfActions :titleWhenAsking |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1572
                    suggestions := listOfSuggestions.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1573
                    actions := listOfActions.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1574
                    title := titleWhenAsking.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1575
                ].
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1576
            suggestions isEmptyOrNil ifTrue:[
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1577
                "/ nothing found
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1578
                ^ self
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1579
            ].    
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1580
        ].
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1581
    ].    
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1582
    actionBlock value:suggestions value:actions value:title.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1583
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1584
    "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
  1585
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1586
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1587
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1588
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1589
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1590
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1591
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1592
     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
  1593
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1594
     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
  1595
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1596
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1597
    ^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1598
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1599
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1600
    "Modified: / 28-08-2013 / 17:15:25 / cg"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1601
    "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
  1602
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1603
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1604
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
  1605
    <resource: #obsolete>
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1606
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1607
	codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1608
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1609
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1610
!DoWhatIMeanSupport methodsFor:'code completion-helpers'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1611
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1612
askUserForCompletion:what for:codeView at:position from:allTheBest
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1613
    |list choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1614
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1615
    "/ cg: until the new stuff works,...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1616
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1617
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1618
"/    allTheBest isEmpty ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1619
"/        ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1620
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1621
"/    allTheBest size == 1 ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1622
"/        ^ allTheBest first
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1623
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1624
"/    list := allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1625
"/    LastChoices notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1626
"/        lastChoice := LastChoices at:what ifAbsent:nil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1627
"/        lastChoice notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1628
"/            list := { lastChoice allBold } , (list copyWithout:lastChoice).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1629
"/        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1630
"/    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1631
"/    choice := Tools::CodeCompletionMenu
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1632
"/                openFor:codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1633
"/                at:position
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1634
"/                with:allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1635
"/    LastChoices isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1636
"/        LastChoices := Dictionary new.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1637
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1638
"/    LastChoices at:what put:choice.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1639
"/    ^ choice string
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1640
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1641
    "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
  1642
    "Modified: / 28-08-2013 / 16:41:35 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1643
!
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
askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1646
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1647
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1648
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1649
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
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
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1652
    LastChoices notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1653
	lastChoice := LastChoices at:what ifAbsent:nil.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1654
	lastChoice notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1655
	    list := {lastChoice. nil. } , (list copyWithout:lastChoice).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1656
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1657
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1658
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1659
    list size < 30 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1660
	|menu idx exitKey|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1661
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1662
	menu := PopUpMenu labels:list.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1663
	menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1664
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1665
		hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1666
		    exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1667
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1668
		hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1669
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1670
	idx := menu startUp.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1671
	idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1672
	    exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1673
		codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1674
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1675
	    ^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1676
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1677
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1678
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1679
	resources := codeView application isNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1680
			ifTrue:[ codeView resources]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1681
			ifFalse:[ codeView application resources ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1682
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1683
	choice := Dialog
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1684
	   choose:(resources string:'Choose ',what)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1685
	   fromList:list
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1686
	   lines:20
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1687
	   title:(resources string:'Code completion').
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1688
	choice isNil ifTrue:[^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1689
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1690
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1691
    LastChoices isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1692
	LastChoices := Dictionary new.
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
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1695
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1696
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1697
    "Created: / 10-11-2006 / 14:00:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1698
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1699
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1700
classOfNode:aNode
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1701
    "when showing possible completions for a message,
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1702
     it is a good idea to know what the kind receiver is."
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1703
4427
fb066a08ef83 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4426
diff changeset
  1704
    | nm nodeVal receiverClass nodeSelector nodeReceiver mthd|
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1705
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  1706
    aNode isBlock ifTrue:[
4727
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1707
        ^ Block
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  1708
    ].
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1709
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1710
    (nodeVal := self valueOfNode:aNode) notNil ifTrue:[
4727
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1711
        "/ knowing the value is always great!!
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1712
        ^ nodeVal class
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1713
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1714
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1715
    aNode isVariable ifTrue:[
4727
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1716
        nm := aNode name.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1717
        nm = 'self' ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1718
            classOrNil isNil ifTrue:[^ UndefinedObject].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1719
            ^ classOrNil
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1720
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1721
        nm = 'super' ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1722
            classOrNil isNil ifTrue:[^ Object].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1723
            ^ classOrNil superclass
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1724
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1725
        nm = 'thisContext' ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1726
            ^ Context
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1727
        ].
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1728
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1729
"/        classOrNil notNil ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1730
"/            (classOrNil allInstVarNames includes:nm) ifTrue:[
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1731
"/                "/ could look at existing instances here...
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1732
"/                self breakPoint:#cg.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1733
"/            ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  1734
"/        ].
4727
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1735
        ^ nil
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1736
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1737
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  1738
    aNode isMessage ifTrue:[
4727
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1739
        nodeSelector := aNode selector.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1740
        nodeReceiver := aNode receiver.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1741
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1742
        "/ some hardwired knowlegde here
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1743
        receiverClass := self classOfNode:nodeReceiver.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1744
        receiverClass notNil ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1745
            nodeSelector == #class ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1746
                ^ receiverClass class
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1747
            ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1748
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1749
            receiverClass isBehavior ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1750
                mthd := receiverClass lookupMethodFor:nodeSelector.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1751
                receiverClass isMeta ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1752
                    ( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: nodeSelector ) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1753
                        ^ receiverClass theNonMetaclass
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1754
                    ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1755
                    "/ if that method sends one of new/basicNew/new:/basicNew:, assume it returns an instance of itself
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1756
                    mthd notNil ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1757
                        ( mthd sendsAny:#( #'new' #'basicNew' #'new:' #'basicNew:' )) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1758
                            ^ receiverClass theNonMetaclass
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1759
                        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1760
                    ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1761
                ] ifFalse:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1762
                    mthd notNil ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1763
                        (ParseTreeSearcher methodIsSetterMethod:mthd) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1764
                            ^ receiverClass.
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1765
                        ]
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1766
                    ]
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1767
                ]
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1768
            ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1769
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1770
        classOrNil notNil ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1771
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1772
                ^ classOrNil class
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1773
            ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1774
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1775
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1776
        (nodeSelector = #'asFilename') ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1777
            ^ Filename
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1778
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1779
        (nodeSelector = #'asOrderedCollection') ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1780
            ^ OrderedCollection
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1781
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1782
        (nodeSelector = #'asArray') ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1783
            ^ Array
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1784
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1785
        (nodeSelector = #'asSet') ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1786
            ^ Set
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1787
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1788
        (nodeSelector = #'size') ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1789
            ^ SmallInteger
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1790
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1791
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1792
        "/ some wellknown boolean returners (need better type inference here)
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1793
        (#( isNil notNil not isEmptyOrNil notEmptyOrNil notEmpty isEmpty
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1794
            isBehavior isMeta
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1795
            = ~= == ~~ > >= < <=
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1796
            includes: contains:
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1797
            and: or:
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1798
            exists atEnd
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1799
        ) includes:nodeSelector ) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1800
            ^ True "/ Boolean - not boolean; it does not contain the full protocol (would not find ifTrue:)
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1801
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1802
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1803
        ( #( + - * / // \\ ) includes:nodeSelector) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1804
            "/ assume numeric
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1805
            ^ Number
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1806
        ].
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1807
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1808
        ( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1809
            "/ assume behavior
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1810
            ^ Behavior
983f74d3c7a1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4711
diff changeset
  1811
        ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1812
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1813
    ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1814
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1815
    "Created: / 28-08-2013 / 16:34:53 / cg"
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1816
!
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1817
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1818
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1819
    "looking for all symbols is way too much and inprecise;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1820
     experiment: only present symbols which are used by the class,
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1821
     and classes in that class category, or at least: implemented as method.
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1822
     We'll see..."
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1823
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1824
    |sym possibleCompletions longest editAction start stop addSymbol
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1825
     parentSelector parent symbolSelectorClass|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1826
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1827
    "/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1828
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1829
    start := (nodeOrNil ? tokenOrNil) start.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1830
    stop := (nodeOrNil ? tokenOrNil) stop.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1831
    (codeView characterAtCharacterPosition:stop) == $' ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1832
	^ self.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1833
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1834
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1835
    sym := (nodeOrNil ? tokenOrNil) value.
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1836
    possibleCompletions := Set new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1837
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1838
    addSymbol :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1839
	[:aSymbol |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1840
	    (aSymbol startsWith:sym) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1841
		(aSymbol = sym) ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1842
		    possibleCompletions add:aSymbol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1843
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1844
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1845
	].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1846
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1847
    (nodeOrNil notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1848
    and:[ (parent := nodeOrNil parent) notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1849
    and:[ parent isMessage ]]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1850
	parentSelector := parent selector.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1851
	( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1852
	    symbolSelectorClass := self classOfNode:parent receiver.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1853
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1854
	( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1855
	    "/ assume that send-target will be self.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1856
	    (methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1857
		addSymbol value:(methodOrNil selector,'Changed').
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1858
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1859
	    symbolSelectorClass := classOrNil.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1860
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1861
	( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1862
	    symbolSelectorClass := self classOfNode:parent arguments second.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1863
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1864
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1865
	symbolSelectorClass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1866
	    symbolSelectorClass withAllSuperclassesDo:[:cls |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1867
		cls ~~ Object ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1868
		    cls ~~ Model ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1869
			cls methodDictionary keysDo:addSymbol.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1870
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1871
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1872
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1873
	].
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1874
    ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1875
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1876
    (considerAll or:[classOrNil isNil]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1877
	Smalltalk allClassesDo:[:cls |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1878
	    cls theNonMetaclass methodDictionary keys do:addSymbol.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1879
	    cls theMetaclass methodDictionary keys do:addSymbol.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1880
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1881
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1882
	"/ Symbol allInstancesDo:addSymbol.
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1883
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1884
	Smalltalk allClassesInCategory:classOrNil do:[:cls |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1885
	    cls theNonMetaclass instAndClassMethodsDo:[:mthd |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1886
		mthd usedSymbols do:addSymbol
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1887
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1888
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1889
    ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1890
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1891
    possibleCompletions := possibleCompletions asOrderedCollection sort.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1892
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1893
    longest := possibleCompletions longestCommonPrefix.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1894
    possibleCompletions remove:longest ifAbsent:[].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1895
    possibleCompletions addFirst: longest.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1896
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1897
    editAction :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1898
	[:chosenIndex |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1899
	    |chosen oldSym oldLen newLen|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1900
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1901
	    chosen := possibleCompletions at:chosenIndex.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1902
	    chosen notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1903
		(codeView characterAtCharacterPosition:start) == $# ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1904
		    start := start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1905
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1906
		(codeView characterAtCharacterPosition:start) == $' ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1907
		    start := start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1908
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1909
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1910
		oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1911
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1912
		codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1913
		    undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1914
			codeView replaceFromCharacterPosition:start to:stop with:chosen
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1915
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1916
		    info:'Completion'.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1917
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1918
		(chosen startsWith:oldSym) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1919
		    oldLen := stop - start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1920
		    newLen := chosen size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1921
		    codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1922
		    codeView dontReplaceSelectionOnInput
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1923
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1924
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1925
	].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1926
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1927
    actionBlock value:possibleCompletions value:editAction value:'symbol'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1928
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1929
    "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
  1930
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1931
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1932
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1933
codeCompletionForMessage:node into:actionBlock
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  1934
    |selector lcSelector srchClass implClass
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  1935
     bestSelectors selector2 bestSelectors2 bestSelectors3 allBest best info numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1936
     newParts nSelParts oldLen newLen selectorParts
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  1937
     findBest parentNode nodeReceiver selectorsSentInCode selectorsImplementedInClass
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  1938
     split editAction parentNodeClassIfKnown
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1939
     receiverNodeClassIfKnown|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1940
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1941
    "/ Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1942
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1943
    findBest := 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1944
        [:node :selector |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1945
            |srchClass srchClasses bestSelectors bestPrefixes
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1946
             allMessagesSentToVariable classesImplementingAllMessages|
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1947
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1948
            srchClass := self classOfNode:node.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1949
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1950
            srchClass isNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1951
                node isVariable ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1952
                    allMessagesSentToVariable := Set new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1953
                    rememberedNodes do:[:eachNode |
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1954
                        eachNode allMessageNodesDo:[:eachMessage |
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1955
                            eachMessage receiver isVariable ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1956
                                eachMessage receiver name = node name ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1957
                                    eachMessage selector ~= selector ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1958
                                        allMessagesSentToVariable add:eachMessage selector
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1959
                                    ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1960
                                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1961
                            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1962
                        ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1963
                    ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1964
                    allMessagesSentToVariable notEmpty ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1965
                        "/ consider classes which implement all those messages.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1966
                        classesImplementingAllMessages := Smalltalk allImplementorsOf:(allMessagesSentToVariable first).
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1967
                        allMessagesSentToVariable do:[:eachSelector |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1968
                            classesImplementingAllMessages := classesImplementingAllMessages
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1969
                                                                select:[:cls | cls implements:eachSelector].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1970
                        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1971
                        srchClasses := classesImplementingAllMessages.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1972
                    ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1973
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1974
            ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1975
            bestSelectors := Set new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1976
            srchClasses isEmptyOrNil ifTrue:[ srchClasses := Array with:srchClass ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1977
            srchClasses do:[:srchClass |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1978
                |bestForThisClass|
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1979
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1980
                bestForThisClass := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1981
                bestForThisClass := self
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1982
                                    withoutSelectorsUnlikelyFor:srchClass
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1983
                                    from:bestForThisClass
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1984
                                    forPartial:selector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1985
                bestSelectors addAll:bestForThisClass.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1986
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1987
            (bestSelectors includes:selector) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1988
                bestSelectors := bestSelectors select:[:sel | sel size > selector size].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1989
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1990
            bestSelectors := bestSelectors asOrderedCollection.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  1991
            bestSelectors
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  1992
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1993
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1994
    selector := node selector.
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  1995
    lcSelector := selector asLowercase.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1996
    parentNode := node parent.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  1997
    nodeReceiver := node receiver.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1998
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  1999
    "/ 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
  2000
    "/ do not attempt to complete the current message.
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2001
    "/ 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
  2002
    (codeView characterBeforeCursor ? $ ) isSeparator ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2003
        (parentNode notNil and:[ parentNode isMessage ]) ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2004
            ^ self.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2005
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2006
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2007
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2008
    "/ only do this if the node-message has no parents around
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2009
    node parentheses isEmptyOrNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2010
        bestSelectors := findBest value:nodeReceiver value:selector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2011
    ] ifFalse:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2012
        bestSelectors := OrderedCollection new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2013
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2014
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2015
    "/ if the receiver is a real variable,
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2016
    "/ we can look for other messages being sent to that variable in the current method.
4823
76bba777a498 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4784
diff changeset
  2017
    "/ Also, if there are assignment 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
  2018
    (tree notNil
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2019
        and:[ nodeReceiver isVariable
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2020
        and:[ nodeReceiver isSelf not
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2021
        and:[ nodeReceiver isSuper not ]]])
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2022
    ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2023
        |classesFromAssignmentsToReceiver otherMessagesToReceiver possibleClasses possibleClassesFromOtherSends|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2024
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2025
        classesFromAssignmentsToReceiver := 
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2026
            tree allAssignmentNodes
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2027
                collect:[:eachAssignmentNode |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2028
                            |cls|
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2029
                            (nodeReceiver = eachAssignmentNode variable
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2030
                                and:[ (cls := self classOfNode:eachAssignmentNode value) notNil ]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2031
                            ) ifTrue:[ cls ] ifFalse:[ nil ]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2032
                        ]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2033
                thenSelect:[:classOrNil | classOrNil notNil].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2034
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2035
        possibleClasses := classesFromAssignmentsToReceiver.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2036
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2037
        otherMessagesToReceiver := Set new.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2038
        tree allMessageNodesDo:[:eachMessageNode |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2039
            (nodeReceiver = eachMessageNode receiver
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2040
                and:[ selector ~= eachMessageNode selector]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2041
            ) ifTrue:[   
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2042
                otherMessagesToReceiver add:eachMessageNode selector
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2043
            ]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2044
        ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2045
        otherMessagesToReceiver notEmpty ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2046
            possibleClassesFromOtherSends :=
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2047
                Smalltalk 
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2048
                    allClassesForWhich:
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2049
                        [:cls |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2050
                            cls isLoaded
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2051
                            and:[ otherMessagesToReceiver
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2052
                                    conform:[:eachSelectorSent | cls includesSelector: "canUnderstand:" eachSelectorSent]]
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2053
                        ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2054
            possibleClasses := possibleClasses , possibleClassesFromOtherSends.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2055
        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2056
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2057
        "/ if the receiver is a classVar/classInstVar,
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2058
        "/ include the class of its current value and UndefinedObject.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2059
        "/ This helps to complete class methods and (lazy) initializer code.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2060
        (classOrNil notNil) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2061
            |tryValue currentValue|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2062
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2063
            tryValue := false.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2064
            (classOrNil theNonMetaclass allClassVarNames includes: nodeReceiver name) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2065
                tryValue := true.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2066
                currentValue := classOrNil theNonMetaclass classVarAt:nodeReceiver name.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2067
            ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2068
                (classOrNil isMeta and:[ classOrNil allInstVarNames includes: nodeReceiver name ]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2069
                    tryValue := true.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2070
                    currentValue := classOrNil theNonMetaclass instVarNamed:nodeReceiver name.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2071
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2072
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2073
            tryValue ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2074
                currentValue notNil ifTrue:[ possibleClasses := { UndefinedObject } , possibleClasses ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2075
                possibleClasses := { currentValue class } , possibleClasses.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2076
            ].
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
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2079
        (possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2080
            bestSelectors :=
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2081
                (possibleClasses 
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2082
                    collectAll:[:eachClass |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2083
                        Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2084
                    ] as:Set) asOrderedCollection.
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2085
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2086
            "/ if any of those is a prefix-keyword of the selector,
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2087
            "/ 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
  2088
            bestSelectors := bestSelectors reject: [:sel | (selector startsWith: sel) or: [selector endsWith: sel]].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2089
        ].
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2090
    ].                                                                            
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2091
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2092
    "/ if we are behind a keyword messages colon,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2093
    "/ only look for matching prefix selectors;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2094
    "/ also, a good completion is to insert an argument;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2095
    "/ the name of the variable from the implementation, as comment, and selected might be a good one!!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2096
    selector isKeyword ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2097
        codeView characterBeforeCursor == $: ifTrue:[
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2098
            bestSelectors := bestSelectors select:[:sel | sel asLowercase startsWith:lcSelector].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2099
            bestSelectors isEmpty ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2100
                "/ nothing better around
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2101
                |argIndex argNames impls|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2102
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2103
                argIndex := node selectorParts size.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2104
                argNames := Set new.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2105
                impls := Smalltalk allImplementorsOf:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2106
                impls size < 10 ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2107
                    impls do:[:eachImplClass |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2108
                        |mthd argName|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2109
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2110
                        mthd := (eachImplClass compiledMethodAt:selector).
4764
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2111
                        argName := (mthd methodArgNames ? #()) at:argIndex ifAbsent:nil.
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2112
                        argName notNil ifTrue:[
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2113
                            argNames add:(argName,' in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate).
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2114
                        ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2115
                    ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2116
                    argNames notEmptyOrNil ifTrue: [
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2117
                        argNames := argNames asOrderedCollection sort.
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2118
                        actionBlock value:argNames value:[:selIndex | ] value: 'argument name hint'.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2119
                        ^ self.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2120
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2121
                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2122
            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2123
        ].
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2124
    ] ifFalse:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2125
        "/ when completing a non-keyword AND the parent is a keyword message,
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2126
        "/ only consider longer keyword messages or unary messages
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2127
        (parentNode notNil and:[ parentNode isMessage and:[parentNode selector isKeywordSelector ]]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2128
            bestSelectors := bestSelectors select:[:sel | sel isUnarySelector ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2129
        ]
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2130
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2131
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2132
    bestSelectors := bestSelectors asOrderedCollection sort:[:a :b | a size < b size].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2133
    (selector isUnarySelector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2134
    and:[ parentNode notNil
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2135
    and:[ parentNode isMessage ]]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2136
        (selector2 := parentNode selector) isKeywordSelector ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2137
            "/ 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
  2138
            "/ i.e. look if there is a longer keyword possible
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2139
            selector2 := selector2,selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2140
            bestSelectors2 := findBest value:parentNode receiver value:selector2.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2141
            bestSelectors2 := bestSelectors2 select:[:sel | sel isKeywordSelector and:[ sel startsWith:selector2]].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2142
            bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2143
            bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2144
        ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2145
            |kwSels|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2146
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2147
            "/ if its a unary message AND the parent is a unary or binary node, try again, sending the partial message
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2148
            "/ as a keyword to the parent node.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2149
            "/ this is the case when after "foo binOp bar if", which should include ifTrue: in the result.
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2150
            "/ transform from (the incorrectly parsed)
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2151
            "/    foo == (shift if)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2152
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2153
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2154
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2155
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2156
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2157
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2158
            "/           arg
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2159
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2160
            "/ into:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2161
            "/    (foo == shift) if
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2162
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2163
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2164
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2165
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2166
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2167
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2168
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2169
            "/           arg
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2170
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2171
            kwSels := findBest value:parentNode value:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2172
            kwSels := kwSels select:[:sel | sel isKeywordSelector].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2173
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2174
            kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2175
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2176
            bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2177
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2178
            "/ these need to go to bestSelectors (see editAction)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2179
            parentNodeClassIfKnown := self classOfNode:parentNode.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2180
            (parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2181
                "/ this is so common, that it deserves a special case:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2182
                "/ 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
  2183
                "/ 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
  2184
                bestSelectors := self
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2185
                                    withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2186
                                    from:bestSelectors
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2187
                                    forPartial:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2188
                kwSels := self
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2189
                            withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2190
                            from:kwSels
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2191
                            forPartial:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2192
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2193
                "/ put keyword selectors in front, because they are very likely
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2194
                bestSelectors := kwSels , bestSelectors.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2195
            ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2196
                "/ put them at the end
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2197
                bestSelectors := bestSelectors , kwSels.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2198
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2199
        ]
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2200
    ].
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2201
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2202
    (selector isUnarySelector
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2203
    and:[ node isMessage ]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2204
        receiverNodeClassIfKnown := self classOfNode:nodeReceiver.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2205
        (receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2206
            "/ this is so common, that it deserves a special case:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2207
            "/ 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
  2208
            "/ 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
  2209
            bestSelectors := self
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2210
                                withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2211
                                from:bestSelectors
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2212
                                forPartial:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2213
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2214
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2215
    (selector isUnarySelector
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2216
    and:[ parentNode notNil
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2217
    and:[ parentNode isMessage
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2218
    and:[ parentNode selector isKeyword ]]]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2219
        "/ completing an already existing keyword message with somthing starting with
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2220
        "/ if, and, or or while.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2221
        "/ here, offer a special completion which inserts parenthesis / brackets around the already
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2222
        "/ existing message. Do this only, if the existing message makes sense.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2223
        ((
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2224
            #( 'ifTrue' 'ifFalse' 'and' 'or' 'whileTrue' 'whileFalse' )
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2225
        ) contains:[:part | part startsWith:selector]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2226
            (Smalltalk allImplementorsOf:parentNode selector) notEmpty ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2227
                |selsP selsB|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2228
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2229
                selsP := #( 'ifTrue:' 'ifFalse:'  )
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2230
                            select:[:sel | sel startsWith:selector]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2231
                            thenCollect:[:sel | '() ',sel].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2232
                selsB := #( 'whileTrue:' 'whileFalse:' )
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2233
                            select:[:sel | sel startsWith:selector]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2234
                            thenCollect:[:sel | '[] ',sel].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2235
                bestSelectors3 := selsP , selsB.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2236
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2237
        ].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2238
    ] ifFalse:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2239
        "/ also offer adding brackets around a while expression
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2240
        (node receiver isBlock) ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2241
            |sels|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2242
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2243
            sels := #( 'whileTrue:' 'whileFalse:' )
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2244
                        select:[:sel | sel startsWith:selector]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2245
                        thenCollect:[:sel | '[] ',sel].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2246
            bestSelectors3 := sels.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2247
        ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2248
    ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2249
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2250
    allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()).
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2251
    allBest sort:
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2252
        [:a :b |
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2253
            |aBeforeB|
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2254
            aBeforeB := a < b.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2255
            (a asLowercase startsWith:lcSelector) ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2256
                (b asLowercase startsWith:lcSelector) ifFalse:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2257
                    aBeforeB := true
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2258
                ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2259
            ] ifFalse:[    
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2260
                (b asLowercase startsWith:lcSelector) ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2261
                    aBeforeB := false
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2262
                ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2263
            ].
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2264
            aBeforeB
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2265
        ].
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2266
                        
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2267
    split :=
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2268
        [:list :splitHow |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2269
            |part1 part2 all|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2270
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2271
            part1 := list select:splitHow.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2272
            part2 := list reject:splitHow.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2273
            part1 isEmpty ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2274
                all := part2.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2275
            ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2276
                part2 isEmpty ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2277
                    all := part1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2278
                ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2279
                    all := part1 , part2.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2280
                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2281
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2282
            all
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2283
        ].
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2284
    "/ sort: prefixes first.
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2285
    selector2 notNil ifTrue:[
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2286
        allBest := split value:allBest value:[:sel | (sel asLowercase startsWith:lcSelector) 
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2287
                                                     or:[sel startsWith:selector2]].
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2288
    ].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2289
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2290
    "/ if receiver is super, always include the method's own selector
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2291
    nodeReceiver isSuper ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2292
        (tree isMethod) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2293
            |mSel|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2294
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2295
            mSel := tree selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2296
            mSel notNil ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2297
                (mSel startsWith:selector) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2298
                    "/ already the word before the cursor?
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2299
                    (mSel ~= selector) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2300
                        allBest remove:mSel ifAbsent:[].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2301
                        allBest addFirst:mSel.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2302
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2303
                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2304
            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2305
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2306
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2307
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2308
    allBest := (bestSelectors3 ? #()) , allBest.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2309
    allBest isEmptyOrNil ifTrue:[ ^ self ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2310
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2311
    "/ the one's which are a prefix are moved towards the top of the list
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2312
    allBest := split value:allBest value:[:sel | sel notNil and:[sel asLowercase startsWith:lcSelector]].
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2313
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2314
    rememberedNodes notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2315
        selectorsSentInCode := 
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2316
            (rememberedNodes
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2317
                select:[:node | node isMessage]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2318
                thenCollect:[:node | node selector]) asSet.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2319
        selectorsSentInCode remove:selector ifAbsent:[].
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2320
    ]. 
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2321
    nodeReceiver notNil ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2322
        |classOrNil|
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2323
        (classOrNil := self classOfNode:nodeReceiver) notNil ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2324
            selectorsImplementedInClass := Set new.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2325
            classOrNil withAllSuperclassesDo:[:cls |
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2326
                cls theNonMetaclass ~~ Object ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2327
                    selectorsImplementedInClass addAll:cls selectors.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2328
                ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2329
            ]    
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2330
        ]
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  2331
    ].    
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2332
    selectorsImplementedInClass notNil ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2333
        "/ the one's already sent in the code are moved to the top of the list.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2334
        allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel].
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2335
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2336
    selectorsSentInCode notNil ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2337
        "/ the one's already sent in the code are moved to the top of the list.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2338
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2339
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2340
"/false ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2341
"/    srchClass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2342
"/        implClass := srchClass whichClassIncludesSelector:best.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2343
"/    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2344
"/        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
  2345
"/        implClass size == 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2346
"/            implClass := implClass first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2347
"/        ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2348
"/            implClass := nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2349
"/        ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2350
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2351
"/
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2352
"/    info := best storeString.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2353
"/    implClass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2354
"/        info := implClass name , ' >> ' , info.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2355
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2356
"/    self information:info.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2357
"/].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2358
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2359
    editAction :=
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2360
        [:index |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2361
            |crsrPos chosen parentsToInsert|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2362
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2363
            crsrPos := codeView characterPositionOfCursor.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2364
            chosen := allBest at:index.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2365
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2366
            chosen ~= selector ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2367
                (bestSelectors3 notNil and:[bestSelectors3 includes:chosen]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2368
                    parentsToInsert := chosen copyTo:2.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2369
                    chosen := chosen copyFrom:4.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2370
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2371
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2372
                numArgs := chosen numArgs.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2373
                (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2374
                    selectorParts := parentNode selectorParts , node selectorParts.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2375
                ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2376
                    selectorParts := node selectorParts.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2377
                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2378
                nSelParts := selectorParts size.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2379
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2380
                newParts := chosen asCollectionOfSubstringsSeparatedBy:$:.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2381
                newParts := newParts select:[:part | part size > 0].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2382
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2383
                codeView
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2384
                    undoableDo:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2385
                        |positionOfFirstArg newCursorPosition stop checkForArgumentTemplates
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2386
                         newPart oldPartialToken start|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2387
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2388
                        checkForArgumentTemplates := (selector isUnarySelector and:[chosen isKeywordSelector]).
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2389
                        numArgs > nSelParts ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2390
                            "/ new selector has more arguments; append them
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2391
                            stop := selectorParts last stop.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2392
                            codeView deleteFromCharacterPosition:stop+1 to:crsrPos-1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2393
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2394
                            "/ append the rest ...
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2395
                            numArgs downTo:nSelParts+1 do:[:idx |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2396
                                |newPart|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2397
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2398
                                newPart := newParts at:idx.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2399
                                newPart := newPart , ':'.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2400
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2401
                                (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2402
                                    newPart := ':' , newPart.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2403
                                ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2404
                                newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2405
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2406
                                codeView replaceFromCharacterPosition:stop to:stop with:newPart.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2407
                                "/ remember the leftMost replacement's end as new cursor position
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2408
                                newCursorPosition := stop + newPart size
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2409
                            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2410
                            checkForArgumentTemplates := true.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2411
                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2412
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2413
                        "/ replace existing parts
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2414
                        (nSelParts min:newParts size) downTo:1 do:[:idx |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2415
                            |skipColon|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2416
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2417
                            skipColon := 0.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2418
                            newPart := newParts at:idx.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2419
                            oldPartialToken := selectorParts at:idx.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2420
                            start := oldPartialToken start.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2421
                            stop := oldPartialToken stop.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2422
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2423
                            (chosen endsWith:$:) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2424
                                (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2425
                                    newPart := newPart , ':'.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2426
                                ] ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2427
                                    skipColon := 1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2428
                                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2429
                            ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2430
                                (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2431
                                    newPart := newPart , ':'
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2432
                                ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2433
                                    |nextChar|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2434
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2435
                                    nextChar := codeView characterAtCharacterPosition:stop+1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2436
                                    nextChar isSeparator ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2437
                                        nextChar == $. ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2438
                                            newPart := newPart , ' '
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2439
                                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2440
                                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2441
                                ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2442
        "/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2443
        "/                        ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2444
        "/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2445
                            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2446
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2447
                            oldPartialToken value ~= newPart ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2448
                                codeView replaceFromCharacterPosition:start to:stop with:newPart.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2449
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2450
                                oldLen := stop - start + 1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2451
                                newLen := newPart size.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2452
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2453
                                "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2454
                                "/ remember the leftMost replacement's end as new cursor position
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2455
                                newCursorPosition := start + newPart size + skipColon. "/ (newLen-oldLen) + 1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2456
                                "/ codeView cursorToCharacterPosition:newCursorPosition.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2457
                            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2458
                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2459
                        newCursorPosition notNil ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2460
                            codeView cursorToCharacterPosition:newCursorPosition-1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2461
                            codeView cursorRight.  "/ avoid going to the next line !!
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2462
                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2463
                        codeView dontReplaceSelectionOnInput.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2464
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2465
                        checkForArgumentTemplates ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2466
                            "/ add opening brackets, etc.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2467
                            self insertAdditonalStuffAfterSelector:chosen.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2468
                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2469
                        parentsToInsert notNil ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2470
                            |sav|
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2471
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2472
                            sav := codeView characterPositionOfCursor-1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2473
                            codeView insertString:(parentsToInsert copyLast:1) atCharacterPosition:node receiver stop+1.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2474
                            codeView insertString:(parentsToInsert copyFirst:1) atCharacterPosition:parentNode start.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2475
                            codeView cursorToCharacterPosition:sav+2; cursorRight
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2476
                        ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2477
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2478
                info:'Completion'.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2479
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2480
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2481
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2482
    actionBlock value:allBest value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2483
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2484
    "Created: / 10-11-2006 / 13:18:27 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2485
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4444
17e98954dad5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4442
diff changeset
  2486
    "Modified: / 06-11-2013 / 16:40:51 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2487
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2488
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2489
codeCompletionForMethodSpec:node
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2490
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2491
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2492
    self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2493
	codeCompletionForMethodSpec:node
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2494
	into:
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2495
	    [:suggestions :action :whatIsIt |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2496
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2497
	    |chosen|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2498
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2499
	    chosen := self askUserForCompletion:whatIsIt for:codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2500
			   at:node start from:suggestions.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2501
	    chosen notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2502
		action value:(suggestions indexOf:chosen)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2503
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2504
	].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2505
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2506
"/    |crsrPos
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2507
"/     selectorSoFar matchingSelectors
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2508
"/     selectors distances best rest
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2509
"/     allExistingMethods nameBag namesByCount selectors1 selectors2|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2510
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2511
"/    crsrPos := codeView characterPositionOfCursor - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2512
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2513
"/    selectorSoFar := ''.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2514
"/    node selectorParts doWithIndex:[:partToken :argNr|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2515
"/        |part|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2516
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2517
"/        part := partToken value.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2518
"/        selectorSoFar := selectorSoFar , part.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2519
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2520
"/        (crsrPos >= partToken start
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2521
"/        and:[crsrPos <= partToken stop]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2522
"/            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2523
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2524
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2525
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2526
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2527
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2528
"/                                        md := eachClass theMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2529
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2530
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2531
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2532
"/                "/ dont forget the stuff in the class-line
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2533
"/                Metaclass withAllSuperclassesDo:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2534
"/                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2535
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2536
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2537
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2538
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2539
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2540
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2541
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2542
"/                                        md := eachClass theNonMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2543
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2544
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2545
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2546
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2547
"/            selectors := matchingSelectors asOrderedCollection.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2548
"/
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2549
"/            "/ 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
  2550
"/            (selectors size == 1
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2551
"/            and:[selectors first = selectorSoFar]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2552
"/                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2553
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2554
"/                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2555
"/                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2556
"/                nameBag := Bag new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2557
"/                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2558
"/                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2559
"/                "/ take the one which occurs most often
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2560
"/                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
  2561
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2562
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2563
"/                    undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2564
"/                        (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2565
"/                            codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2566
"/                        ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2567
"/                            codeView insertString:best atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2568
"/                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2569
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2570
"/                    info:'completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2571
"/                codeView cursorToCharacterPosition:(crsrPos + best size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2572
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2573
"/                "the ones implemented in superclasses are shown first"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2574
"/                classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2575
"/                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2576
"/                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2577
"/                ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2578
"/                    selectors1 := selectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2579
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2580
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2581
"/                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2582
"/                distances sortWith:selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2583
"/                selectors1 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2584
"/                selectors := selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2585
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2586
"/                selectors2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2587
"/                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2588
"/                    distances sortWith:selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2589
"/                    selectors2 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2590
"/                    selectors1 := selectors1 collect:[:sel | sel allBold].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2591
"/                    selectors := selectors1,selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2592
"/                ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2593
"/
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2594
"/                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2595
"/                best isNil ifTrue:[^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2596
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2597
"/                rest := best copyFrom:selectorSoFar size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2598
"/                codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2599
"/                    undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2600
"/                        codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2601
"/                            replaceFromCharacterPosition:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2602
"/                            to:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2603
"/                            with:rest
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2604
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2605
"/                    info:'Completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2606
"/                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2607
"/            ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2608
"/            codeView cursorRight. "/ kludge to make it visible
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2609
"/        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2610
"/    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2611
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2612
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2613
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2614
    "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
  2615
    "Modified: / 01-06-2012 / 20:31:36 / cg"
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
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2618
codeCompletionForMethodSpec:node into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2619
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2620
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2621
    |crsrPos crsrLine crsrCol
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2622
     selectorSoFar matchingSelectors
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2623
     selectors distances best rest
4437
f20ff8e2ab34 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4436
diff changeset
  2624
     allExistingMethods nameBag namesByCount selectors1 selectors2 selectors0
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2625
     editAction argNames selectorsForVars
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2626
     selectorTypedSoFar|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2627
4437
f20ff8e2ab34 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4436
diff changeset
  2628
    selectors := OrderedCollection new.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2629
    selectors0 := OrderedCollection new.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2630
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2631
    "/ Transcript showCR:'m'.
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2632
    crsrLine := codeView cursorLine.
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2633
    crsrCol := codeView cursorCol.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2634
    crsrPos := codeView characterPositionOfCursor - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2635
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2636
    selectorTypedSoFar := node selector.
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2637
    selectorTypedSoFar isUnarySelector ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2638
        "/ user has just begun to edit a selector.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2639
        "/ 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
  2640
        classOrNil notNil ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2641
            selectorsForVars := OrderedCollection new.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2642
            classOrNil instVarNames do:[:nm |
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2643
                (nm startsWith:selectorTypedSoFar) ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2644
                    (classOrNil implements:nm asSymbol) ifFalse:[ selectorsForVars add:nm].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2645
                    (classOrNil implements:nm asMutator) ifFalse:[ selectorsForVars add:(nm,':')].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2646
                 ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2647
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2648
            classOrNil isMeta ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2649
                classOrNil theNonMetaclass classVarNames do:[:nm |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2650
                    |nmSel|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2651
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2652
                    nmSel := nm asLowercaseFirst.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2653
                    (nmSel startsWith:selectorTypedSoFar) ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2654
                        (classOrNil implements:nmSel asSymbol) ifFalse:[ selectorsForVars add:nmSel].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2655
                        (classOrNil implements:nmSel asMutator) ifFalse:[ selectorsForVars add:(nmSel,':')].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2656
                     ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2657
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2658
            ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2659
                "/ isXXX ?
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2660
                (('is',classOrNil nameWithoutPrefix) startsWith:selectorTypedSoFar ) ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2661
                    selectors0 add:('is',classOrNil nameWithoutPrefix).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2662
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2663
            ].
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2664
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2665
            "/ and also messages sent by the class itself
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2666
            classOrNil methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2667
                m messagesSentToSelf do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2668
                    (sel startsWith:selectorTypedSoFar) ifTrue:[
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2669
                        (classOrNil implements:sel) ifFalse:[ selectorsForVars add:sel].
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2670
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2671
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2672
            ].
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2673
            classOrNil isMeta ifFalse:[
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2674
                classOrNil theMetaclass methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2675
                    m messagesSent do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2676
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2677
                            (classOrNil implements:sel) ifFalse:[ selectorsForVars add:sel].
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2678
                        ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2679
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2680
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  2681
            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2682
        ].
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2683
    ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  2684
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2685
    selectorSoFar := ''.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2686
    node selectorParts doWithIndex:[:partToken :argNr|
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2687
        |part|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2688
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2689
        part := partToken value.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2690
        selectorSoFar := selectorSoFar , part.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2691
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2692
        (crsrPos >= partToken start
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2693
        and:[crsrPos <= partToken stop]) ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2694
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2695
                matchingSelectors := Smalltalk allClasses
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2696
                                    inject:(Set new)
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2697
                                    into:[:theSet :eachClass |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2698
                                        |md|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2699
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2700
                                        md := eachClass theMetaclass methodDictionary.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2701
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2702
                                        theSet.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2703
                                    ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2704
                "/ dont forget the stuff in the class-line
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2705
                Metaclass withAllSuperclassesDo:[:cls |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2706
                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2707
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2708
            ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2709
                matchingSelectors := Smalltalk allClasses
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2710
                                    inject:(Set new)
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2711
                                    into:[:theSet :eachClass |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2712
                                        |md|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2713
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2714
                                        md := eachClass theNonMetaclass methodDictionary.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2715
                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2716
                                        theSet.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2717
                                    ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2718
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2719
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2720
            selectors addAll:matchingSelectors.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2721
            selectorsForVars notNil ifTrue:[ selectors addAll:selectorsForVars ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2722
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2723
            selectors := selectors sort:[:a :b | a size < b size].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2724
            selectors size > 100 ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2725
                selectors := selectors copyTo:100.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2726
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2727
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2728
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2729
            "/ if there is only one, and user has already entered it, 
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2730
            "/ he might want to complete the argument-name
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2731
            (selectors size == 1
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2732
            and:[selectors first = selectorSoFar]) ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2733
                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2734
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2735
                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2736
                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2737
                nameBag := Bag new.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2738
                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2739
                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2740
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2741
                "/ take the one which occurs most often
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2742
                "/ best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2743
                argNames := (namesByCount collect:[:a | a key]).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2744
                editAction :=
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2745
                        [:chosenIndex |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2746
                            |chosenName|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2747
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2748
                            chosenName := argNames at:chosenIndex.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2749
                            codeView
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2750
                                undoableDo:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2751
                                    (crsrPos+1) >= codeView contents size ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2752
                                        codeView paste:chosenName.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2753
                                        codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2754
                                    ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2755
                                        codeView cursorToCharacterPosition:crsrPos.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2756
                                        codeView cursorRight.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2757
                                        codeView insertStringAtCursor:chosenName.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2758
                                        codeView selectFromCharacterPosition:crsrPos+1 to:crsrPos+1+chosenName size-1.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2759
                                        codeView dontReplaceSelectionOnInput
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2760
                                    ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2761
                                ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2762
                                info:'completion'.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2763
                        ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2764
                actionBlock
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2765
                    value:argNames
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2766
                    value:editAction
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2767
                    value:'argument'.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2768
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2769
                ^ self.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2770
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2771
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2772
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2773
            "the ones implemented in superclasses are shown first"
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2774
            classOrNil notNil ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2775
                selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2776
                selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2777
            ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2778
                selectors1 := selectors
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2779
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2780
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2781
            distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2782
            distances sortWith:selectors1.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2783
            selectors1 reverse.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2784
            selectors := selectors1.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2785
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2786
            selectors2 notEmptyOrNil ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2787
                distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2788
                distances sortWith:selectors2.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2789
                selectors2 reverse.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2790
                selectors1 := selectors1 collect:[:sel | sel allBold].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2791
                selectors := selectors1,selectors2.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2792
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2793
            selectors0 notEmptyOrNil ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2794
                selectors := selectors0,selectors.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2795
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2796
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2797
            editAction :=
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2798
                [:selectedCompletionIndex |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2799
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2800
                    best := selectors at:selectedCompletionIndex.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2801
                    rest := best copyFrom:selectorSoFar size + 1.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2802
                    codeView
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2803
                        undoableDo:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2804
                            codeView insertString:rest atLine:crsrLine col:crsrCol.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2805
                        ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2806
                        info:'Completion'.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2807
                    codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2808
                    codeView cursorRight. "/ kludge to make it visible
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2809
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2810
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2811
            "/ best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2812
            actionBlock
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2813
                value:selectors
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2814
                value:editAction
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2815
                value:'selector'.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2816
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2817
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2818
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2819
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2820
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2821
    "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
  2822
    "Modified: / 01-06-2012 / 20:31:36 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2823
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2824
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2825
codeCompletionForVariable:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2826
    |nonMetaClass crsrPos nm parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2827
     allVariables allDistances variablesAlreadyAdded nodeVal
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2828
     char oldLen newLen
4485
c6ed849af389 class: DoWhatIMeanSupport
Stefan Vogel <sv@exept.de>
parents: 4484
diff changeset
  2829
     getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2830
     globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2831
     editAction suggestions nameIsOK longerNames setOfNames otherArgNames
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2832
     suggestionsWithInfo|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2833
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  2834
    "/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2835
    classOrNil notNil ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2836
        nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2837
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2838
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2839
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2840
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2841
    "/ 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
  2842
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2843
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2844
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2845
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2846
    char isSeparator ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2847
        nm knownAsSymbol ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2848
            classOrNil isNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2849
                nodeVal := Smalltalk at:nm asSymbol.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2850
            ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2851
                nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2852
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2853
            nodeVal isBehavior ifTrue:[
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2854
                |selectors selectors1 selectors2|
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2855
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2856
                selectors1 := OrderedSet new.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2857
                selectors2 := OrderedSet new.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2858
                nodeVal class 
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2859
                    withAllSuperclassesDo:[:cls |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2860
                        cls methodDictionary keysAndValuesDo:[:sel :mthd |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2861
                            |cat|
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2862
                            cat := mthd category asLowercase.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2863
                            cat = 'instance creation' ifTrue:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2864
                                selectors1 add:sel
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2865
                            ] ifFalse:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2866
                                "/ other category: look if it sends new, new: etc.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2867
                                (mthd messagesSent includesAny:#(new new: basicNew basicNew:)) ifTrue:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2868
                                    selectors2 add:sel
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2869
                                ].    
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2870
                            ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2871
                        ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2872
                    ].
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2873
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  2874
                selectors := selectors1 order sort , #('-') , selectors2 order sort.
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2875
                editAction :=
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2876
                    [:answer |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2877
                        |s|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2878
                        s := answer isInteger ifTrue:[selectors at:answer] ifFalse:[answer].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2879
                        codeView
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2880
                            undoableDo:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2881
                                codeView insertString:s atCharacterPosition:crsrPos.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2882
                                codeView cursorToCharacterPosition:crsrPos+s size.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2883
                            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2884
                            info:'completion'.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2885
                    ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2886
                actionBlock
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2887
                    value:selectors
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2888
                    value:editAction
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2889
                    value:nil.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2890
                ^ self.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2891
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2892
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2893
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2894
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2895
    parent := node parent.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2896
    (parent notNil and:[parent isMessage]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2897
        node == parent receiver ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2898
            selectorOfMessageToNode := parent selector
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2899
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2900
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2901
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2902
    "/ this is pure voodoo magic (tries to make a good spelling weight,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2903
    "/ by weighting the number of startsWith characters into the spelling distance...)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2904
    getDistanceComputeBlockWithWeight :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2905
        [:weight |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2906
            [:each |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2907
                |dist factor|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2908
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2909
                dist := each spellAgainst:nm.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2910
                factor := 1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2911
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2912
                (each startsWith:nm) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2913
                    factor := 6 * nm size.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2914
                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2915
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2916
                        factor := 4 * nm size.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2917
                    ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2918
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2919
                dist := dist + (weight*factor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2920
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2921
                each -> (dist * weight)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2922
             ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2923
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2924
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2925
    nameIsOK := false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2926
    addWithFactorBlock :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2927
        [:eachNames :factor |
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  2928
            |distanceComputeBlock|
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  2929
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  2930
            distanceComputeBlock := (getDistanceComputeBlockWithWeight value:factor).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2931
            (eachNames includes:nm) ifTrue:[nameIsOK := true].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2932
            eachNames do:[:nameToAdd |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2933
                (nameToAdd ~= nm) ifTrue:[  "/ not again
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2934
                    (variablesAlreadyAdded includes:nameToAdd) ifFalse:[  "/ not again
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2935
                        variablesAlreadyAdded add:nameToAdd.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2936
                        allVariables add:nameToAdd.
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  2937
                        allDistances add:(distanceComputeBlock value:nameToAdd).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2938
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2939
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2940
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2941
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2942
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2943
    nm isUppercaseFirst ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2944
        globalFactor := 2.    "/ favour globals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2945
        localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2946
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2947
        globalFactor := 1.    "/ favour locals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2948
        localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2949
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2950
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2951
    variablesAlreadyAdded := Set new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2952
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2953
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2954
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2955
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2956
    (parent notNil
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2957
    and:[parent isMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2958
    and:[parent arguments includes:node]]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2959
        "/ yes -
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2960
        "/ 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
  2961
        "/ of this method, and take that as a basis of the selection
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2962
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2963
        implementors := SystemBrowser
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2964
                            findImplementorsOf:(parent selector)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2965
                            in:(Smalltalk allClasses)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2966
                            ignoreCase:false.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2967
        "/ which argument is it
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2968
        argIdx := parent arguments indexOf:node.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2969
        implementors size > 50 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2970
            implementors := implementors asOrderedCollection copyTo:50.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2971
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2972
        namesUsed := implementors
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2973
                        collect:[:eachImplementor |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2974
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2975
                            parseTree := eachImplementor parseTree.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2976
                            (parseTree notNil and:[parseTree arguments size > 0])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2977
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2978
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2979
                        thenSelect:[:a | a notNil].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2980
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2981
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  2982
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2983
        "/ try some commonly used arg names, such as aBoolean, anInteger, etc.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2984
        nm size > 1 ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2985
            |tryClassNamesWith|
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2986
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2987
            ((nm startsWith:'a') and:[(nm at:2) isUppercase]) ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2988
                tryClassNamesWith := 'a'
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2989
            ] ifFalse:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2990
                (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
  2991
                    tryClassNamesWith := 'an'.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2992
                ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2993
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2994
            tryClassNamesWith notNil ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2995
                addWithFactorBlock 
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2996
                    value:(Smalltalk keys 
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2997
                            collect:[:className | tryClassNamesWith,className]
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2998
                            thenSelect:[:name | name startsWith:nm])
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  2999
                    value:(1.5 * localFactor)
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3000
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3001
        ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3002
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3003
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3004
            "/ also, look for the keyword before the argument,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3005
            "/ and see if there is such an instVar
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3006
            "/ if so, add it with -Arg
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3007
            parent selector isKeyword ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3008
                kwPart := parent selector keywords at:argIdx.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3009
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3010
                    addWithFactorBlock
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3011
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3012
                        value:(1 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3013
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3014
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3015
            "/ look for the variable names of any other method in that class
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3016
            otherArgNames := Set new.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3017
            classOrNil methodDictionary keysAndValuesDo:[:sel :mthd |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3018
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3019
                            parseTree := mthd parseTree.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3020
                            (parseTree notNil and:[parseTree arguments size > 0])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3021
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3022
                                ifTrue:[ otherArgNames addAll:(parseTree arguments collect:[:each | each name])] ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3023
            addWithFactorBlock value:otherArgNames value:(1.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3024
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3025
        addWithFactorBlock value:(codeView previousReplacements collect:[:p | p value asString]) value:(1.3 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3026
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3027
        "/ locals in the block/method
4780
ac7e1d23c65b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
  3028
        |names  nameSpace|
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3029
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3030
        names := OrderedCollection withAll:node allVariablesOnScope.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3031
        setOfNames := Set withAll:names.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3032
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3033
        rememberedScopeNodes notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3034
            "/ notNil when a parseError occurred.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3035
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3036
                (eachScope isMethod or:[eachScope isBlock]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3037
                    eachScope argumentNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3038
                        (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3039
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3040
                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3041
                    eachScope isSequence ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3042
                        eachScope temporaryNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3043
                            (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3044
                        ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3045
                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3046
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3047
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3048
                "/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3049
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3050
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3051
                eachScope variableNodesDo:[:var |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3052
                    (setOfNames includes:var name) ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3053
                        names add:var name. setOfNames add:var name
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3054
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3055
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3056
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3057
        ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3058
            "/ tree must be there
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3059
            tree variableNodesDo:[:var |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3060
                (setOfNames includes:var name) ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3061
                    names add:var name. setOfNames add:var name
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3062
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3063
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3064
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3065
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3066
        addWithFactorBlock value:names value:(4 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3067
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3068
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3069
            "/ instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3070
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3071
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3072
            "/ inherited instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3073
            classOrNil superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3074
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3075
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3076
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3077
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3078
        "/ magic:
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3079
        "/ 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
  3080
        "/ give names which respond to those messages a higher weight
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3081
        selectorOfMessageToNode notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3082
            |responders nonResponders|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3083
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3084
            "/ responding to that messsage
4365
fda4ed5a9772 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4364
diff changeset
  3085
"/ self halt.
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3086
            classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3087
                "/ private classes
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3088
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3089
                                   value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3090
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3091
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3092
                names := nonMetaClass classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3093
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3094
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3095
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3096
                addWithFactorBlock value:responders value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3097
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3098
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3099
                "/ superclass var names
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3100
                nonMetaClass allSuperclassesDo:[:superClass |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3101
                    names := superClass classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3102
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3103
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3104
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3105
                    addWithFactorBlock value:responders value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3106
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3107
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3108
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3109
                "/ namespace vars
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3110
                classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3111
                    names := classOrNil topNameSpace keys.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3112
                    names := names reject:[:nm | nm includes:$:].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3113
                    names := names select:[:nm | nm isUppercaseFirst ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3114
                    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3115
                    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3116
                    addWithFactorBlock value:responders value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3117
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3118
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3119
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3120
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3121
            "/ globals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3122
            names := Smalltalk keys.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3123
            names := names reject:
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3124
                            [:nm |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3125
                                (nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3126
                            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3127
            names := names reject:[:nm | nm startsWith:'Undeclared:::' ].
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
            names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3130
            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3131
            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3132
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3133
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3134
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3135
            classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3136
                "/ pool variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3137
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3138
                    |pool names|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3139
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3140
                    pool := Smalltalk at:poolName.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3141
                    names := pool classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3142
                    names := names select:[:nm | nm isUppercaseFirst ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3143
                    responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3144
                    nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3145
                    addWithFactorBlock value:responders value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3146
                    addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3147
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3148
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3149
        ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3150
            classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3151
                "/ private classes
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3152
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3153
                                   value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3154
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3155
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3156
                addWithFactorBlock value:nonMetaClass classVarNames value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3157
                nonMetaClass superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3158
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3159
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3160
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3161
                "/ namespace vars
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3162
                classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3163
                    names := classOrNil topNameSpace keys.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3164
                    names := names reject:[:nm | nm includes:$:].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3165
                    names := names select:[:nm | nm isUppercaseFirst ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3166
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3167
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3168
                "/ namespace vars
4780
ac7e1d23c65b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
  3169
                ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
ac7e1d23c65b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4775
diff changeset
  3170
                    names := nameSpace isNameSpace ifTrue:[nameSpace keys] ifFalse:[nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3171
                    names := names select:[:nm | nm isUppercaseFirst ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3172
                    names := names reject:[:nm | nm includes:$:].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3173
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3174
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3175
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3176
                "/ pool variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3177
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3178
                    |pool names|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3179
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3180
                    pool := Smalltalk at:poolName.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3181
                    pool isNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3182
                        Transcript showCR:'non existent pool: ',poolName
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3183
                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3184
                        names := pool classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3185
                        addWithFactorBlock value:names value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3186
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3187
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3188
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3189
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3190
            "/ globals
4665
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3191
            names := OrderedCollection new.
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3192
            Smalltalk keysDo:[:k |
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3193
                (k isUppercaseFirst
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3194
                and:[ (k startsWith:'Undeclared:::') not
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3195
                and:[ ((k includes:$:) and:[ (k includesString:'::') not]) not ]]) ifTrue:[
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3196
                    names add:k
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3197
                ]
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3198
            ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3199
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3200
            "/ only consider all globals, if the first char of the completed name is uppercase;
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3201
            "/ otherwise, only consider names with a caseInsensitve prefix match
4665
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3202
            nm first isUppercase ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3203
                names := names select:[:globalName | globalName asLowercase startsWith: nm].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3204
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3205
            addWithFactorBlock value:names value:(1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3206
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3207
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3208
        "/ pseudos - assuming that thisContext is seldom used.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3209
        "/ also assuming, that nil is short so its usually typed in.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3210
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3211
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3212
        addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3213
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3214
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3215
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3216
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3217
4410
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3218
"/ nope (foo := foo + 1) should be possible!!
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3219
"/    (parent notNil and:[parent isAssignment]) ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3220
"/        "/ remove the left side of the assignment (to avoid foo := foo suggestions)
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3221
"/        |i|
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3222
"/
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3223
"/        i := allDistances findFirst:[:entry | entry key = parent variable name].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3224
"/        i ~~ 0 ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3225
"/            allDistances removeAtIndex:i
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3226
"/        ].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3227
"/    ].
4385
d3381caeb327 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
  3228
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3229
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3230
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3231
                                                           ifTrue:[el]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3232
                                                           ifFalse:[best]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3233
                                                    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3234
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3235
    allDistances sort:[:a :b |
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3236
                                a value > b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3237
                                    true
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3238
                                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3239
                                    a value = b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3240
                                        a key < b key
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3241
                                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3242
                                        false
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3243
                                    ]
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
                      ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3246
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3247
    allTheBest := allDistances.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3248
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3249
    nameIsOK ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3250
        "/ if the name already exists, only allow longer names, if there are
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3251
        longerNames := allTheBest select:[:assoc | assoc key startsWith:nm].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3252
        longerNames notEmpty ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3253
            allTheBest := longerNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3254
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3255
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3256
    allTheBest size > 15 ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3257
        "/ remove all those which are below some threshold or are a prefix
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3258
        0.4 to:0.9 by:0.1 do:[:delta |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3259
            "/ if still too many, remove more and more
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3260
            allTheBest size > 15 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3261
                allTheBest := allDistances select:[:entry | (entry key startsWith:nm) or:[ entry value >= (bestAssoc value * delta) ]].
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
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3264
        allTheBest size > 15 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3265
            "/ remove all those which are below some threshold
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3266
            0.4 to:0.9 by:0.1 do:[:delta |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3267
                "/ if still too many, remove more and more
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3268
                allTheBest size > 15 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3269
                    allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * delta) ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3270
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3271
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3272
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3273
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3274
    suggestions := allTheBest collect:[:assoc | assoc key].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3275
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3276
    "/ finally, the trick is to bring them into a reasonable order...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3277
    "/ sort the prefix matchers by length, the others by spelling distance
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3278
    "/ and bring the prefix-matchers towards the beginning
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3279
    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
  3280
                   ,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3281
                   (suggestions reject:[:s | s startsWith:nm]).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3282
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3283
    "/ if super is among them, add a full call to the completions
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3284
    (suggestions includes:'super') ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3285
        (tree notNil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3286
        and:[ tree isMethod ]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3287
            Error handle:[:ex |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3288
                Transcript showCR:'parse error in code completion ignored'.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3289
            ] do:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3290
                suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.').
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3291
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3292
        ].
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3293
    ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3294
    "/ self halt.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3295
    editAction :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3296
        [:index |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3297
            |answer start stop oldVar|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3298
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3299
            answer := suggestions at:index.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3300
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3301
            start := node start.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3302
            stop := node stop.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3303
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3304
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3305
            oldLen := stop - start + 1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3306
            newLen := answer size.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3307
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3308
            codeView
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3309
                undoableDo:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3310
                    codeView replaceFromCharacterPosition:start to:stop with:(answer).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3311
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3312
                    (answer startsWith:oldVar) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3313
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3314
                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3315
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3316
                    ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3317
                    codeView dontReplaceSelectionOnInput
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
                info:'Completion'.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3320
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3321
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3322
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3323
    suggestionsWithInfo := 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3324
        suggestions 
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3325
            collect:[:eachName |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3326
                |val|
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3327
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3328
                val := self valueOfVariable:eachName.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3329
                val isNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3330
                    eachName
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3331
                ] ifFalse:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3332
                    eachName,' (',val class name,')'
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3333
                ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3334
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3335
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3336
    actionBlock value:suggestionsWithInfo value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3337
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3338
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3339
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4314
3c3df9c97f74 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4311
diff changeset
  3340
    "Modified: / 30-07-2013 / 08:36:11 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3341
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3342
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3343
findNodeForInterval:interval in:source
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3344
    |tree node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3345
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3346
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3347
    RBParser isNil ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3348
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3349
    source = LastSource ifTrue:[
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3350
        tree := LastParseTree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3351
    ] ifFalse:[
4951
570438fc0023 #BUGFIX
mawalch
parents: 4938
diff changeset
  3352
        LastSource := LastParseTree := nil.
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3353
        tree := RBParser
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3354
                parseMethod:source
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3355
                onError:
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3356
                    [:str :err ":nodesSoFar" |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3357
                        "Transcript showCR:'Parse-Error: ',str."
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3358
                        nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3359
                    ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3360
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3361
        tree isNil ifTrue:[
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3362
            "/ try to parse as an expression
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3363
            tree := RBParser
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3364
                    parseExpression:source
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3365
                    onError:
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3366
                        [:str :err ":nodesSoFar" |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3367
                            "Transcript showCR:'Parse-Error: ',str."
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3368
                            nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3369
                        ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3370
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3371
            tree isNil ifTrue:[
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3372
                ^ nil
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3373
            ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3374
        ].
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3375
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3376
        LastSource := source.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3377
        LastParseTree := tree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3378
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3379
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3380
    Error handle:[:ex |
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3381
    ] do:[ 
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3382
        node := tree whichNodeIsContainedBy:interval.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3383
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3384
    node isNil ifTrue: [
4775
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3385
        node := tree bestNodeFor: interval.
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3386
        node isNil ifTrue: [
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3387
            node := self findNodeIn:tree forInterval:interval
66a822518725 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4764
diff changeset
  3388
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3389
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3390
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3391
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3392
    "Modified: / 06-07-2011 / 12:42:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3393
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3394
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3395
findNodeForInterval:interval in:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3396
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3397
	findNodeForInterval:interval in:source allowErrors:allowErrors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3398
	mustBeMethod:false
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3399
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3400
    "Modified: / 16-09-2011 / 14:52:28 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3401
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3402
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3403
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3404
    "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
  3405
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3406
    ^ self
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3407
	findNodeForInterval:interval in:source allowErrors:allowErrors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3408
	mustBeMethod:mustBeMethod mustBeExpression:false
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3409
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3410
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3411
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3412
    "parse it as expression or method;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3413
     if mustBeMethod is true, do not try a regular expressions (as in a workspace);
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3414
     if mustBeExpression is true, do not try method"
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3415
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3416
    |intersectingNodes smallestIntersectingNode firstIntersectingNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3417
     lastIntersectingNode onErrorBlock
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3418
     nodeGenerationHook parserClass parser currentScopeNodes bestNode|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3419
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3420
    interval isEmpty ifTrue: [^ nil].
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3421
    languageOrNil notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3422
        parserClass := languageOrNil parserClass.
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3423
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3424
        classOrNil notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3425
            parserClass := classOrNil programmingLanguage parserClass.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3426
        ]
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3427
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3428
    parserClass notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3429
        "/ hack
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3430
        parserClass == Parser ifTrue: [
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3431
            parserClass := RBParser.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3432
        ].
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3433
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3434
        parserClass := RBParser.
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3435
    ].
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  3436
    parserClass isNil ifTrue: [^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3437
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3438
    rememberedScopeNodes := nil.
4434
b15ce7d47dd8 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  3439
    rememberedNodes := OrderedCollection new.
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  3440
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3441
    "/ LastSource := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3442
    source = LastSource ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3443
        tree := LastParseTree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3444
        tokens := LastScanTokens.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3445
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3446
        intersectingNodes := OrderedCollection new.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3447
        currentScopeNodes := IdentitySet new.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3448
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3449
        onErrorBlock :=
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3450
            [:str :err :nodesSoFar |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3451
                |nodes|
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3452
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3453
                allowErrors ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3454
                    rememberedScopeNodes := currentScopeNodes.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3455
                    firstIntersectingNode notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3456
                        ^ firstIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3457
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3458
                    nodesSoFar notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3459
                        nodes := nodesSoFar asOrderedCollection
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3460
                                    collect:[:nd | nd whichNodeIntersects:interval]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3461
                                    thenSelect:[:nd | nd notNil ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3462
                        nodes size == 1 ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3463
                            ^ nodes first
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3464
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3465
                    ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3466
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3467
                nil
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3468
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3469
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3470
        self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3471
            Transcript show:'looking for: '; showCR:interval.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3472
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3473
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3474
        nodeGenerationHook :=
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3475
            [:node |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3476
                rememberedNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3477
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3478
                "/ 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
  3479
                "/ 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
  3480
                "/ what the semantic interpretation (especially: scope of variable) will be.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3481
                "/ therefore, we parse all, and return the found node at the end.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3482
                (node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3483
                    currentScopeNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3484
                ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3485
                    self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3486
                        Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3487
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3488
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3489
                    (node intersectsInterval:interval) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3490
                        self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3491
                            Transcript showCR:'yes'.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3492
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3493
                        intersectingNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3494
                        firstIntersectingNode isNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3495
                            firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3496
                        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3497
                            |lenNode lenSmallest|
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3498
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3499
                            lenNode := (node stop - node start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3500
                            lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3501
                            lenNode < lenSmallest ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3502
                                smallestIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3503
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3504
                            node start > lastIntersectingNode start ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3505
                                lastIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3506
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3507
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3508
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3509
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3510
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3511
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3512
        "/ one of the big problems when using the RBParser here is
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3513
        "/ that it behaves badly when a syntax error is encountered;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3514
        "/ 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
  3515
        "/ completely parsed (for example, a blockNode gets the parent-method only
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3516
        "/ after parsing). Thus, when an error is encountered, we cannot walk
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3517
        "/ 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
  3518
        "/ an inner scope (allVariablesOnScope returns only a partial set).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3519
        "/ 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
  3520
        "/ 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
  3521
        "/ parent gets set eventually, thus we might consider locals from sibling blocks.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3522
        "/ See rememberedScopeNodes handling above.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3523
        "/ Those other nodes are only remembered for failed parses;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3524
        "/ if the parse is ok, rememberedScopeNodes will be nil.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3525
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3526
        mustBeExpression ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3527
            tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3528
                        parseMethod: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3529
                        setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3530
                            parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3531
                            p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3532
                            p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3533
                            p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3534
                        ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3535
                        onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3536
            parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3537
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3538
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3539
        mustBeMethod ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3540
            "/ only cache parsed methods
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3541
            tree notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3542
                LastSource := source.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3543
                LastParseTree := tree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3544
                LastScanTokens := tokens.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3545
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3546
        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3547
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3548
                "/ try as an expression
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3549
                tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3550
                            parseExpression: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3551
                            setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3552
                                parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3553
                                p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3554
                                p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3555
                                p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3556
                            ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3557
                            onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3558
                parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3559
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3560
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3561
        lastIntersectingNode notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3562
            self debuggingCodeFor:#cg is:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3563
                Transcript show:'last: '; showCR:lastIntersectingNode.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3564
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3565
            ^ lastIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3566
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3567
        "/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3568
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3569
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3570
    bestNode := self findNodeForInterval:interval inParseTree:tree.
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3571
    self debuggingCodeFor:#cg is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  3572
        Transcript show:'best: '; showCR:bestNode.
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3573
    ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3574
    ^ bestNode
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3575
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3576
    "Created: / 16-09-2011 / 14:52:08 / cg"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  3577
    "Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3578
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3579
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3580
findNodeForInterval:interval inParseTree:parseTree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3581
    |node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3582
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3583
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3584
    parseTree isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3585
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3586
    node := parseTree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3587
    node isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3588
	node := parseTree whichNodeIntersects:interval.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3589
	node isNil ifTrue: [
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3590
	    node := self findNodeIn:parseTree forInterval:interval
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3591
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3592
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3593
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3594
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3595
    "Modified: / 10-11-2006 / 13:13:58 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3596
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3597
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3598
findNodeIn:tree forInterval:interval
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3599
    |nodeFound wouldReturn|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3600
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3601
    nodeFound := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3602
    tree nodesDo:[:eachNode |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3603
	(eachNode intersectsInterval:interval) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3604
	    (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3605
		nodeFound := eachNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3606
	    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3607
		(nodeFound parent == eachNode parent
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3608
		and:[ eachNode start >= nodeFound start
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3609
		      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3610
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3611
		    (nodeFound parent notNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3612
		    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3613
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3614
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3615
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3616
	    nodeFound notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3617
		"/ already found one - beyond that one; leave
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3618
		wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3619
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3620
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3621
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3622
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3623
    ^ nodeFound
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3624
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3625
    "Modified: / 20-11-2006 / 12:31:12 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3626
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3627
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3628
insertAdditonalStuffAfterSelector:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3629
    |optionalExtraSpace|
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3630
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3631
    optionalExtraSpace := (codeView characterAfterCursor isSeparator)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3632
			    ifTrue:['']
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3633
			    ifFalse:[' '].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3634
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3635
    (
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3636
	#(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3637
	    'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3638
	    'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3639
	) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3640
    ) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3641
	codeView insertStringAtCursor:('[',optionalExtraSpace).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3642
	"/ codeView cursorLeft:1+extra size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3643
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3644
    (
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3645
	#(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3646
	    'collect:' 'select:' 'reject:' 'do:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3647
	) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3648
    ) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3649
	codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3650
	codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3651
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3652
    (
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3653
	#(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3654
	    'contains:' 'findFirst:' 'detect:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3655
	) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3656
    ) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3657
	codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3658
	codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3659
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3660
    (
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3661
	#(
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3662
	    'remove:ifAbsent:' 'detect:ifNone:'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3663
	) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3664
    ) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3665
	codeView insertStringAtCursor:('[]',optionalExtraSpace).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3666
	codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3667
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3668
!
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  3669
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3670
old_askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3671
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3672
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3673
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3674
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3675
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3676
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3677
    LastChoices notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3678
	lastChoice := LastChoices at:what ifAbsent:nil.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3679
	lastChoice notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3680
	    "/ 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
  3681
	    (list includes: lastChoice) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3682
		(list indexOf: lastChoice) < 10 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3683
		    list := {lastChoice allBold } , (list copyWithout:lastChoice).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3684
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3685
	    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3686
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3687
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3688
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3689
    list size < 30 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3690
	|menu idx exitKey|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3691
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3692
	menu := PopUpMenu labels:list.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3693
	menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3694
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3695
		hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3696
		    exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3697
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3698
		hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3699
	menu memorizeLastSelection:3 "sigh, not 1 because of heading!!".
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3700
	idx := menu startUpWithHeading:'Choose ',what.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3701
	idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3702
	    exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3703
		codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3704
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3705
	    ^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3706
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3707
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3708
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3709
	resources := codeView application isNil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3710
			ifTrue:[ codeView resources]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3711
			ifFalse:[ codeView application resources ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3712
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3713
	choice := Dialog
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3714
	   choose:(resources string:'Choose ',what)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3715
	   fromList:list
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3716
	   lines:20
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3717
	   initialSelection:(list firstIfEmpty:nil)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3718
	   title:(resources string:'Code completion').
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3719
	choice isNil ifTrue:[^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3720
    ].
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  3721
    choice := choice string.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3722
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3723
    LastChoices isNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3724
	LastChoices := Dictionary new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3725
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3726
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3727
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3728
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3729
    "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
  3730
    "Modified: / 28-08-2013 / 15:28:01 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3731
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3732
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3733
treeForCode:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3734
    |tree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3735
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3736
    source = LastSource ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3737
	tree := LastParseTree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3738
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3739
	tree := RBParser
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3740
		parseMethod:source
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3741
		onError: [:str :err :nodesSoFar :parserOrNil|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3742
			allowErrors ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3743
			    "/ parserOrNil isNil if raised by the scanner
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3744
			    parserOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3745
				^ parserOrNil currentMethodNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3746
			    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3747
			].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3748
			^ nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3749
		    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3750
		proceedAfterError:false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3751
		rememberNodes:true.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3752
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3753
	tree notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3754
	    LastSource := source.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3755
	    LastParseTree := tree.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3756
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3757
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3758
    ^ tree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3759
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3760
    "Modified: / 13-01-2012 / 11:54:30 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3761
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3762
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  3763
tryCodeCompletionWithSource:source nodeInterval:interval at:characterPositionOfCursor mustBeExpression:mustBeExpression into:actionBlock
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3764
    "this is tried multiple times;
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3765
        first with cursor line only
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3766
        then with the source copied up to the cursor position,
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3767
        then with the full source.
4381
43de05e6af6c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  3768
     Either one may give better results (for example, when completing
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3769
     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
  3770
     legal, but stupid message send to be parsed...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3771
     (which happens often after inserting)"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3772
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  3773
    |node nodeParent checkedNode characterBeforeCursor nodeIsInTemporaries|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3774
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3775
    "/ this is too naive and stupid; if there is a syntactic error,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3776
    "/ 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
  3777
    "/ 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
  3778
    "/ without any progress.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3779
    "/ 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
  3780
    "/ as it parses the code. Stop, when the interval is hit.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3781
    "/ that will also work for syntactic incorrect source code.
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  3782
    (mustBeExpression not and:[methodOrNil notNil or:[classOrNil notNil]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3783
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3784
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3785
    node isNil ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3786
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3787
        node isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3788
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3789
            self information:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3790
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3791
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3792
    ].
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  3793
    nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3794
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3795
    (node isVariable
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  3796
    and:[ nodeParent notNil
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  3797
    and:[ nodeParent isMessage
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  3798
    and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3799
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3800
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3801
    ].
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3802
    characterPositionOfCursor > source size ifTrue:[^ self].
4525
71ebd312132a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4524
diff changeset
  3803
    characterBeforeCursor := source at:(characterPositionOfCursor-1 max:1). "/ codeView characterBeforeCursor.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3804
    characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  3805
    characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3806
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3807
    node isVariable ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3808
        nodeIsInTemporaries :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3809
            nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3810
            and:[ nodeParent isSequence
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3811
            and:[ nodeParent temporaries notEmptyOrNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3812
            and:[ node stop <= nodeParent temporaries last stop ]]].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3813
        nodeIsInTemporaries ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3814
            "/ cursor must be right after the variable
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3815
            characterPositionOfCursor >= (node stop) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3816
                self codeCompletionForVariable:node into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3817
            ]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3818
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3819
        ^ self.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3820
    ].
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  3821
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3822
    node isLiteral ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3823
        "/ however, user may want to complete a symbol inside a literal array!!
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3824
        node value isArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3825
            node token isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3826
                |elementBeforeCursor searcher|
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3827
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3828
                elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3829
                elementBeforeCursor isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3830
                    searcher :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3831
                        [:tok :check |
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3832
                            tok isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3833
                                tok value inject:nil into:[:found :el | found ifNil:[searcher value:el value:check]]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3834
                            ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3835
                                (check value:tok) ifTrue:[tok] ifFalse:[nil]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3836
                            ]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3837
                        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3838
                    elementBeforeCursor := searcher value:node token value:[:anElementToken | characterPositionOfCursor == (anElementToken stop)].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3839
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3840
                (elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3841
                    self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3842
                    ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3843
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3844
            ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3845
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3846
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3847
        "/ cursor must be right after the literal
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3848
        characterPositionOfCursor == (node stop + 1) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3849
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3850
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3851
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3852
        node value isSymbol ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3853
            self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3854
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3855
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3856
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3857
        "/ huh - completing strings, numbers or what?
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3858
        (nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3859
            and:[ nodeParent isMessage
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3860
            and:[ nodeParent isKeyword ]])
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3861
        ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3862
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3863
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3864
        "/ no, move up and try completing the outer keyword message (next arg)
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3865
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3866
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3867
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3868
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  3869
    "/ move outward, until we find a message-send node,
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  3870
    "/ or the method's selector pattern node.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3871
    checkedNode := node.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3872
    [checkedNode notNil] whileTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3873
        (characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3874
            self information:'Inside a message node'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3875
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3876
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3877
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3878
        checkedNode isMessage ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3879
            "/ completion in a message-send
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3880
            self codeCompletionForMessage:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3881
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3882
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3883
        checkedNode isMethod ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3884
            "/ completion in a method's selector pattern
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3885
            self codeCompletionForMethodSpec:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3886
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3887
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  3888
        checkedNode := checkedNode parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3889
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3890
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3891
    self information:'Node is neither variable nor message.'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3892
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3893
    "Modified: / 04-07-2006 / 18:48:26 / fm"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3894
    "Modified: / 16-09-2011 / 14:54:47 / cg"
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3895
!
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  3896
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3897
valueOfNode:aNode
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3898
    "when showing possible completions for a message,
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3899
     it is a good idea to know what the reveiver's value is.
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3900
     Sigh - returns nil both if unknown AND if a real nil is there."
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3901
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3902
    |nodeSelector nodeReceiver isNonDestructive receiverValue method|
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3903
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3904
    aNode isLiteral ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3905
        ^ aNode value
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3906
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3907
    aNode isVariable ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3908
        ^ self valueOfVariable:aNode name.
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3909
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3910
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3911
    aNode isMessage ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3912
        nodeSelector := aNode selector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3913
        nodeReceiver := aNode receiver.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3914
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3915
        "/ some hardwired knowlegde here
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3916
        classOrNil notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3917
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3918
                ^ classOrNil
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3919
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3920
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3921
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3922
        isNonDestructive := false.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3923
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3924
        ( #( class theMetaclass theNonMetaclass ) includes:nodeSelector) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3925
            isNonDestructive := true.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3926
        ] ifFalse:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3927
            "/ follow non-destructive accessors
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3928
            receiverValue := self valueOfNode:nodeReceiver.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3929
            receiverValue notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3930
                method := receiverValue class lookupMethodFor:nodeSelector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3931
                method notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3932
                    (ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3933
                        "/ we can savely call that method to get the current value
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3934
                        ^ receiverValue perform: nodeSelector.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3935
                    ]
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3936
                ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3937
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3938
        ].
4422
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3939
    ].
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3940
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3941
    ^ nil
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3942
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3943
    "Created: / 28-08-2013 / 16:34:53 / cg"
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3944
!
ee7c441fce69 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  3945
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3946
valueOfVariable:aVariableName
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3947
    "when showing possible completions for a variable,
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3948
     it is a good idea to know what the reveiver's value is.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3949
     Sigh - returns nil both if unknown AND if a real nil is there."
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3950
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3951
    |nodeVal con privateClass|
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3952
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3953
    aVariableName isUppercaseFirst ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3954
        "/ simply 'evaluate' the variable (like in a browser's codeView)
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3955
        "/ mhmh - will we catch workspace vars then?
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3956
        Error handle:[:ex |
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3957
        ] do:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3958
            nodeVal := Parser new evaluate:aVariableName in:nil receiver:classOrNil.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3959
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3960
        nodeVal notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3961
            ^ nodeVal
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3962
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3963
        classOrNil notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3964
            (classOrNil theNonMetaclass classVarNames includes:aVariableName) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3965
                nodeVal := classOrNil theNonMetaclass classVarAt:aVariableName.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3966
                ^ nodeVal.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3967
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3968
            privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3969
            privateClass notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3970
                nodeVal := privateClass.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3971
                ^ nodeVal.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3972
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3973
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3974
        ^ nil
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3975
    ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3976
    aVariableName = 'self' ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3977
        (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[^ classOrNil theNonMetaclass].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3978
        contextOrNil notNil ifTrue:[^ contextOrNil receiver].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3979
        ^ nil
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3980
    ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3981
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3982
    contextOrNil notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3983
        con := contextOrNil.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3984
        [ con notNil ] whileTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3985
            "/ a local in the context?
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3986
            ((con argAndVarNames ? #()) includes:aVariableName) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3987
                nodeVal := con argsAndVars at:(con argAndVarNames indexOf:aVariableName) ifAbsent:nil.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3988
                nodeVal notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3989
                    ^ nodeVal
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3990
                ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3991
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3992
            con := con home.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3993
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3994
        "/ an instvar
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3995
        (contextOrNil receiver class allInstVarNames includes:aVariableName) ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3996
            nodeVal := contextOrNil receiver instVarNamed:aVariableName.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3997
            nodeVal notNil ifTrue:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3998
                ^ nodeVal
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3999
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  4000
        ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  4001
    ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  4002
    ^ nil
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  4003
!
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  4004
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4005
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4006
    "some heuristics;
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4007
     as best selectors has been chosen by implemented methods for aClass,
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4008
     some of them should be filtered (for example, at:/at:put:, which are
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4009
     found in object, but only make sense for variable objects or those which do
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4010
     implement at:put: themself.
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4011
     I have currently no better idea than hardcoding stuff I found irritating..."
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4012
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4013
    |selectors noNilChecks noIsXXXChecks noNoXXXChecks noBecome 
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4014
     noIndexedSetters noIndexedGetters noSizeQueries|
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4015
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4016
    aClass isNil ifTrue:[ ^ selectorsArg ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4017
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4018
    noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := false.
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4019
    noIndexedSetters := noIndexedGetters := noSizeQueries := false.
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4020
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4021
    selectors := (selectorsArg ? #()) asOrderedCollection.
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4022
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4023
    self tracePoint:#cg message:aClass.
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4024
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4025
    "/ actually meaning booleans here
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4026
    (aClass == True or:[aClass == False]) ifTrue:[
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4027
        noNilChecks := noBecome := true.
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4028
        (partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ].
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4029
        (partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4030
    ].
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4031
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  4032
    (aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ].
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4033
    (aClass includesBehavior: Symbol) ifTrue:[ noNilChecks := noBecome := noIndexedSetters := true ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4034
    (aClass includesBehavior: Number) ifTrue:[ noBecome := true ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4035
    (aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := true ].
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  4036
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4037
    (aClass isMeta) ifTrue:[
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4038
        noNilChecks := noBecome := true.
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4039
        "/ remove messages which are only defined in Object and non-meta classes.
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4040
        selectors := selectors reject:
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4041
            [:sel |
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4042
                (Object implements:sel)
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4043
                and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]]
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4044
            ].
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4045
    ].
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4046
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4047
    aClass isVariable ifFalse:[
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4048
        noIndexedGetters := noIndexedSetters := noSizeQueries := true.
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4049
    ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4050
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4051
    noIndexedSetters ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4052
        #( #'at:put:' #'basicAt:put:') do:[:indexAccessSelector |
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4053
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4054
                selectors := selectors copyWithout:indexAccessSelector.
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4055
            ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4056
        ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4057
    ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4058
    noIndexedGetters ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4059
        #( #'at:' #'basicAt:') do:[:indexAccessSelector |
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4060
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4061
                selectors := selectors copyWithout:indexAccessSelector.
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4062
            ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4063
        ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4064
    ].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4065
    noSizeQueries ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4066
        #( #size #basicSize ) do:[:indexAccessSelector |
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4067
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4068
                selectors := selectors copyWithout:indexAccessSelector.
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4069
            ].
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4070
        ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4071
    ].
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4072
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4073
    noNilChecks ifTrue:[
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4074
        selectors removeAllFoundIn:#(
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4075
                    'isNil' 'notNil'
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4076
                    'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:'
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4077
                    'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:'
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4078
                    'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:'
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4079
                  ).
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4080
    ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4081
    noIsXXXChecks ifTrue:[
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4082
        "/ get rid of all isXXX selectors
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4083
        selectors := selectors reject:[:sel | sel startsWith:'is'].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4084
    ].
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  4085
    noNoXXXChecks ifTrue:[
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4086
        "/ get rid of all notXXX selectors
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4087
        selectors := selectors reject:[:sel | sel startsWith:'no'].
4418
149eefdc6206 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  4088
    ].
4615
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4089
    noBecome ifTrue:[
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4090
        "/ get rid of all become* selectors
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4091
        selectors := selectors reject:[:sel | sel startsWith:'become'].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4092
        selectors remove:#oneWayBecome: ifAbsent:[].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4093
        selectors := selectors reject:[:sel | sel startsWith:'changeClassTo'].
6611c207243f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4610
diff changeset
  4094
    ].
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4095
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4096
    "/ actually: directly implemented selectors are more likely, so move them to top
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4097
    selectors := (selectors select:[:sel | aClass implements:sel])
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4098
                 ,
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  4099
                 (selectors reject:[:sel | aClass implements:sel]).
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  4100
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  4101
    ^ selectors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4102
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4103
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4104
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4105
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4106
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4107
    |sym possibleCompletions best start stop oldLen newLen oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4108
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4109
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4110
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4111
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4112
    Symbol allInstancesDo:[:existingSym |
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4113
	(existingSym startsWith:sym) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4114
	    (existingSym = sym) ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4115
		possibleCompletions add:existingSym
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4116
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4117
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4118
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4119
    possibleCompletions sort.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4120
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4121
    best := possibleCompletions longestCommonPrefix.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4122
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4123
	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
  4124
	best isNil ifTrue:[^ self].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4125
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4126
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4127
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4128
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4129
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4130
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4131
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4132
	start := start + 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4133
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4134
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4135
	start := start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4136
	stop := stop - 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4137
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4138
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4139
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4140
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4141
    codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4142
	undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4143
	info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4144
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4145
    (best startsWith:oldVar) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4146
	oldLen := stop - start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4147
	newLen := best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4148
	codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4149
	codeView dontReplaceSelectionOnInput
4238
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
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4152
    "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
  4153
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4154
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4155
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4156
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4157
    |selector
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4158
     bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4159
     newParts nSelParts oldLen newLen selectorParts
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4160
     findBest parentNode selectorInBest selector2InBest2
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4161
     parser selectorsSentInCode selectorsImplementedInClass split
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4162
     varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4163
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4164
    RefactoryTyper notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4165
        "/ refactory package also provides a (very limited) typer;
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4166
        "/ 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
  4167
        (node receiver isVariable) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4168
            varName := node receiver name.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4169
            varName isUppercaseFirst ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4170
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4171
                tree := RBParser
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4172
                            parseMethod:codeView contents string
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4173
                            onError:[:aString :pos | nil].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4174
                tree notNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4175
                    rbTypes := RefactoryTyper
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4176
                                classesFor: varName
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4177
                                in: tree
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4178
                                model: nil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4179
                                ignoredSelectors:(Array with:node selector).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4180
                    rbTypes size > 0 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4181
                        rbTypes size > 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4182
                            rbTypes remove:ProtoObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4183
                            rbTypes remove:Autoload ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4184
                            rbTypes remove:ObsoleteObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4185
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4186
                        rbTypes size == 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4187
                            rbType := rbTypes first.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4188
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4189
                            rbType := Class commonSuperclassOf:rbTypes
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4190
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4191
                        (rbType notNil "and:[rbType ~= Object]") ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4192
                            bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4193
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4194
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4195
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4196
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4197
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4198
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4199
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4200
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4201
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4202
        selectorsSentInCode := parser messagesSent.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4203
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4204
    classOrNil notNil ifTrue:[
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4205
        selectorsImplementedInClass := Set new.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4206
        classOrNil withAllSuperclassesDo:[:cls |
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4207
            cls theNonMetaclass ~~ Object ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4208
                selectorsImplementedInClass addAll:cls selectors.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4209
            ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  4210
        ]    
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4211
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4212
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4213
    findBest := [:node :selector |
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4214
        |srchClass bestSelectors bestPrefixes|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4215
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4216
        codeView withCursor:(Cursor questionMark) do:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4217
            srchClass := self classOfNode:node receiver.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4218
            srchClass notNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4219
                bestSelectors := Parser findBest:30 selectorsFor:selector in:srchClass forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4220
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4221
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4222
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4223
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4224
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4225
        (bestSelectors includes:selector) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4226
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4227
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4228
        bestSelectors
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4229
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4230
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4231
    selector := node selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4232
    bestSelectors := findBest value:node value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4233
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4234
    parentNode := node parent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4235
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4236
    parentIsKeywordMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4237
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4238
            and:[ parentNode isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4239
            and:[ parentNode selector isKeywordSelector]]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4240
    parentIsBinaryMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4241
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4242
            and:[ parentNode isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4243
            and:[ parentNode selector isBinarySelector]]).
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4244
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4245
    tryParent := false.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4246
    "/ 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
  4247
    (node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4248
        tryParent := true.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4249
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4250
        "/ 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
  4251
        (node isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4252
        and:[ node receiver isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4253
        and:[ node receiver receiver isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4254
        and:[ node receiver receiver name isUppercaseFirst
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4255
        and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4256
            rcvrClass := Smalltalk classNamed:(node receiver receiver name).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4257
            "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4258
            bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4259
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4260
            "/ also, if nothing was found
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4261
            (bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4262
            and:[ parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4263
            and:[ parentNode isMessage ]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4264
                "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4265
                "/ selector2 := parentNode selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4266
                "/ selector2 := selector2,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4267
                bestSelectors := findBest value:parentNode value:selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4268
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4269
        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4270
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4271
    tryParent ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4272
        selector2 := parentNode selector,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4273
        bestSelectors2 := findBest value:parentNode value:selector2.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4274
    ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4275
    bestSelectorsFromRB notEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4276
        bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4277
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4278
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4279
    "/ if the parent is a keyword selector, the child cannot
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4280
    (parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4281
        bestSelectors := bestSelectors reject:[:sel | sel isKeywordSelector]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4282
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4283
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4284
    bestSelectors2 isEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4285
        allBest := bestSelectors.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4286
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4287
        bestSelectors isEmptyOrNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4288
            allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4289
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4290
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4291
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4292
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4293
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4294
                "/ selector2 is more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4295
                allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4296
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4297
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4298
                    "/ selector more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4299
                    allBest := bestSelectors
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4300
                ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4301
                    "/ assume same likelyness
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4302
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4303
                    allBest := bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4304
                                ifTrue:[ bestSelectors2 ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4305
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4306
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4307
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4308
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4309
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4310
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4311
    allBest isEmptyOrNil ifTrue:[ ^ self ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4312
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4313
    split :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4314
        [:list :splitHow |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4315
            |part1 part2 all|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4316
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4317
            part1 := list select:splitHow.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4318
            part2 := list reject:splitHow.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4319
            part1 isEmpty ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4320
                all := part2.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4321
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4322
                part2 isEmpty ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4323
                    all := part1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4324
                ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4325
                    all := part1 , part2.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4326
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4327
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4328
            all
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4329
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4330
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4331
    selectorsImplementedInClass notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4332
        "/ the ones implemented in the receiver class are moved to the top of the list.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4333
        allBest := split value:allBest value:[:sel | selectorsImplementedInClass includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4334
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4335
    selectorsSentInCode notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4336
        "/ the ones already sent in the code are moved to the top of the list.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4337
        allBest := split value:allBest value:[:sel | selectorsSentInCode includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4338
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4339
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4340
    "/ the ones which are a prefix are moved towards the top of the list
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4341
    allBest := split value:allBest value:[:sel | sel notNil and:[sel startsWith:selector]].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4342
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4343
    best := allBest first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4344
    allBest size > 1 ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4345
        "allBest size < 20 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4346
            |idx|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4347
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4348
            idx := (PopUpMenu labels:allBest) startUp.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4349
            idx == 0 ifTrue:[ ^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4350
            best := allBest at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4351
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4352
            allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4353
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4354
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4355
        ]."
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4356
        allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4357
        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
  4358
        best isEmptyOrNil ifTrue:[^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4359
        best = '-' ifTrue:[^ self].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4360
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4361
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4362
"/    srchClass notNil ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4363
"/        implClass := srchClass whichClassIncludesSelector:best.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4364
"/    ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4365
"/        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
  4366
"/        implClass size == 1 ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4367
"/            implClass := implClass first.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4368
"/        ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4369
"/            implClass := nil
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4370
"/        ]
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4371
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4372
"/
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4373
"/    info := best storeString.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4374
"/    implClass notNil ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4375
"/        info := implClass name , ' >> ' , info.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4376
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  4377
"/    self information:info.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4378
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4379
    best ~= selector ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4380
        numArgs := best numArgs.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4381
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4382
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4383
            selectorParts := parentNode selectorParts , node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4384
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4385
            selectorParts := node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4386
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4387
        nSelParts := selectorParts size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4388
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4389
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4390
        newParts := newParts select:[:part | part size > 0].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4391
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4392
        codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4393
            undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4394
                |newCursorPosition stop|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4395
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4396
                numArgs > nSelParts ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4397
                    stop := selectorParts last stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4398
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4399
                    "/ append the rest ...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4400
                    numArgs downTo:nSelParts+1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4401
                        |newPart|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4402
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4403
                        newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4404
                        (best endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4405
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4406
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4407
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4408
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4409
                            newPart := ':' , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4410
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4411
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4412
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4413
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4414
                        newCursorPosition := stop + newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4415
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4416
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4417
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4418
                (nSelParts min:newParts size) downTo:1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4419
                    |newPart oldPartialToken start stop nextChar|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4420
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4421
                    newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4422
                    oldPartialToken := selectorParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4423
                    start := oldPartialToken start.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4424
                    stop := oldPartialToken stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4425
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4426
                    (best isKeywordSelector) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4427
                        (oldPartialToken value endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4428
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4429
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4430
                            (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4431
                                newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4432
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4433
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4434
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4435
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4436
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4437
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4438
                            nextChar := codeView characterAtCharacterPosition:stop+1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4439
                            nextChar isSeparator ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4440
                                (').' includes:nextChar) ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4441
                                    newPart := newPart , ' '
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4442
                                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4443
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4444
                        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4445
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4446
"/                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4447
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4448
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4449
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4450
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4451
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4452
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4453
                    newCursorPosition isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4454
                        oldLen := stop - start + 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4455
                        newLen := newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4456
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4457
                        newCursorPosition := stop + (newLen-oldLen)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4458
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4459
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4460
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4461
                codeView cursorToCharacterPosition:newCursorPosition.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4462
                codeView cursorRight.  "/ avoid going to the next line !!
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4463
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4464
                ((best endsWith:':') and:[numArgs == 1]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4465
                    |impls impl|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4466
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4467
                    "/ see if it expects a block argument (heuristic)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4468
                    best := best asSymbol.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4469
                    (node notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4470
                    and:[classOrNil notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4471
                    and:[node receiver isSelf]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4472
                        (impl := classOrNil whichClassImplements:best) isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4473
                            impls := #().
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4474
                            Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4475
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4476
                            impls := { impl }
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4477
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4478
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4479
                        impls := Smalltalk allImplementorsOf:best.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4480
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4481
                    (impls contains:[:cls |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4482
                        |argName|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4483
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4484
                        argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4485
                        (argName includesString:'block') or:[ (argName includesString:'action')]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4486
                    ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4487
                        codeView insertStringAtCursor:'['
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4488
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4489
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4490
                codeView dontReplaceSelectionOnInput.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4491
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  4492
        info:'Completion'.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4493
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4494
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4495
    "Created: / 10-11-2006 / 13:18:27 / cg"
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4496
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  4497
    "Modified: / 28-08-2013 / 15:27:32 / cg"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4498
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  4499
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4500
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4501
    |parent nonMetaClass crsrPos nm
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4502
     allVariables allDistances best nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4503
     char start stop oldLen newLen oldVar
4485
c6ed849af389 class: DoWhatIMeanSupport
Stefan Vogel <sv@exept.de>
parents: 4484
diff changeset
  4504
     getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4505
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4506
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4507
    classOrNil notNil ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4508
	nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4509
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4510
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4511
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4512
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4513
    "/ 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
  4514
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4515
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4516
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4517
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4518
    char isSeparator ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4519
	classOrNil isNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4520
	    nodeVal := Smalltalk at:nm asSymbol.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4521
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4522
	    nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4523
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4524
	nodeVal isBehavior ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4525
	    |methods menu exitKey idx|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4526
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4527
	    methods := nodeVal class methodDictionary values
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4528
			    select:[:m | |cat|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4529
				cat := m category asLowercase.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4530
				cat = 'instance creation'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4531
			    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4532
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4533
	    menu := PopUpMenu labels:(methods collect:[:each | each selector]).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4534
	    menu hideOnKeyFilter:[:key | |hide|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4535
		    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4536
		    hide ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4537
			exitKey := key.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4538
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4539
		    hide].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4540
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4541
	    idx := menu startUp.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4542
	    idx == 0 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4543
		exitKey notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4544
		    codeView keyPress:exitKey x:0 y:0.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4545
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4546
		^ self
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4547
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4548
	    best := (methods at:idx) selector.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4549
	    codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4550
		undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4551
		    codeView insertString:best atCharacterPosition:crsrPos.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4552
		    codeView cursorToCharacterPosition:crsrPos+best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4553
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4554
		info:'completion'.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4555
	    ^ self.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4556
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4557
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4558
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4559
    ((parent := node parent) notNil and:[parent isMessage]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4560
	node == parent receiver ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4561
	    selectorOfMessageToNode := parent selector
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4562
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4563
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4564
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4565
    getDistanceComputeBlockWithWeight :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4566
	[:weight |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4567
	    [:each |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4568
		|dist factor|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4569
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4570
		dist := each spellAgainst:nm.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4571
		factor := 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4572
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4573
		(each startsWith:nm) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4574
		    factor := 6 * nm size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4575
		] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4576
		    (each asLowercase startsWith:nm asLowercase) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4577
			factor := 4 * nm size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4578
		    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4579
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4580
		dist := dist + (weight*factor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4581
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4582
		each -> (dist * weight)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4583
	     ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4584
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4585
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4586
    addWithFactorBlock :=
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4587
	[:eachNames :factor | |namesToAdd|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4588
	    namesToAdd := eachNames select:[:nameToAdd | nameToAdd ~= nm ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4589
	    namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4590
	    allVariables addAll:namesToAdd.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4591
	    allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4592
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4593
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4594
    nm isUppercaseFirst ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4595
	globalFactor := 2.    "/ favour globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4596
	localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4597
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4598
	globalFactor := 1.    "/ favour locals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4599
	localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4600
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4601
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4602
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4603
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4604
4308
f1c31624744d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4304
diff changeset
  4605
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4606
    ((parent := node parent) notNil
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4607
    and:[parent isMethod
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  4608
    and:[parent arguments includes:node]]) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4609
	"/ 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
  4610
	"/ 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
  4611
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4612
	implementors := SystemBrowser
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4613
			    findImplementorsOf:(parent selector)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4614
			    in:(Smalltalk allClasses)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4615
			    ignoreCase:false.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4616
	"/ which argument is it
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4617
	argIdx := parent arguments indexOf:node.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4618
	implementors size > 50 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4619
	    implementors := implementors asOrderedCollection copyTo:50.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4620
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4621
	namesUsed := implementors
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4622
			collect:[:eachImplementor |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4623
			    |parseTree|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4624
			    parseTree := eachImplementor parseTree.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4625
			    (parseTree notNil and:[parseTree arguments size > 0])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4626
				ifFalse:nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4627
				ifTrue:[ (parseTree arguments at:argIdx) name] ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4628
			thenSelect:[:a | a notNil] as:Set.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4629
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4630
	addWithFactorBlock value:namesUsed value:(2 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4631
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4632
	classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4633
	    "/ also, look for the keyword before the argument,
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4634
	    "/ and see if there is such an instVar
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4635
	    "/ if so, add it with -Arg
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4636
	    parent selector isKeyword ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4637
		kwPart := parent selector keywords at:argIdx.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4638
		(classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4639
		    addWithFactorBlock
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4640
			value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4641
			value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4642
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4643
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4644
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4645
    ] ifFalse:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4646
	classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4647
	    "/ locals in the block/method
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4648
	    |names|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4649
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4650
	    names := node allVariablesOnScope.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4651
	    "/ if there were no variables (due to a parse error)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4652
	    "/ do another parse and see what we have
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4653
	    names isEmpty ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4654
		tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4655
		"/ better if we already have a body (include locals then)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4656
		"/ otherwise, only the arguments are considered
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4657
		tree notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4658
		    names := (tree body ? tree) allVariablesOnScope.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4659
		]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4660
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4661
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4662
	    addWithFactorBlock value:names value:(4 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4663
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4664
	    "/ instance variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4665
	    addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4666
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4667
	    "/ inherited instance variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4668
	    classOrNil superclass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4669
		addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4670
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4671
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4672
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4673
	selectorOfMessageToNode notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4674
	    |names responders nonResponders|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4675
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4676
	    "/ responding to that messsage
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4677
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4678
	    classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4679
		"/ private classes
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4680
		addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4681
				   value:(1.75 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4682
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4683
		"/ class variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4684
		names := nonMetaClass classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4685
		responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4686
		nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4687
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4688
		addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4689
		addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4690
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4691
		"/ superclass var names
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4692
		nonMetaClass allSuperclassesDo:[:superClass |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4693
		    names := superClass classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4694
		    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4695
		    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4696
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4697
		    addWithFactorBlock value:responders value:(1 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4698
		    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4699
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4700
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4701
		"/ namespace vars
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4702
		classOrNil nameSpace ~~ Smalltalk ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4703
		    names := classOrNil topNameSpace keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4704
		    names := names reject:[:nm | nm includes:$:].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4705
		    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4706
		    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
  4707
		    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
  4708
		    addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4709
		    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4710
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4711
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4712
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4713
	    "/ globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4714
	    names := Smalltalk keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4715
	    "/ names := names reject:[:nm | nm includes:$:].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4716
	    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4717
	    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
  4718
	    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
  4719
	    addWithFactorBlock value:responders value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4720
	    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4721
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4722
	    "/ pool variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4723
	    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4724
		|pool|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4725
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4726
		pool := Smalltalk at:poolName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4727
		names := pool classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4728
		names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4729
		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
  4730
		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
  4731
		addWithFactorBlock value:responders value:(2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4732
		addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4733
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4734
	] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4735
	    |names|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4736
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4737
	    classOrNil notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4738
		"/ private classes
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4739
		addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4740
				   value:(1.75 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4741
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4742
		"/ class variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4743
		addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4744
		classOrNil superclass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4745
		    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4746
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4747
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4748
		"/ namespace vars
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4749
		classOrNil nameSpace ~~ Smalltalk ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4750
		    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
  4751
		    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4752
		    addWithFactorBlock value:names value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4753
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4754
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4755
		"/ pool variables
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4756
		classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4757
		    |pool|
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4758
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4759
		    pool := Smalltalk at:poolName.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4760
		    names := pool classVarNames.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4761
		    addWithFactorBlock value:names value:(2.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4762
		].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4763
	    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4764
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4765
	    "/ globals
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4766
	    names := Smalltalk keys.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4767
	    names := names select:[:nm | nm isUppercaseFirst ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4768
	    addWithFactorBlock value:names value:(1.5 * globalFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4769
	].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4770
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4771
	"/ pseudos - assuming that thisContext is seldom used.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4772
	"/ also assuming, that nil is short so its usually typed in.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4773
	addWithFactorBlock value:#('self') value:(2.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4774
	addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4775
	addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4776
	addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4777
	addWithFactorBlock value:#('true') value:(1 * localFactor).
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4778
	addWithFactorBlock value:#('false') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4779
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4780
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4781
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4782
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4783
    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
  4784
							   ifTrue:[el]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4785
							   ifFalse:[best]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4786
						    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4787
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4788
    allDistances sort:[:a :b |
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4789
				a value > b value ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4790
				    true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4791
				] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4792
				    a value = b value ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4793
					a key < b key
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4794
				    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4795
					false
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4796
				    ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4797
				]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4798
		      ].
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  4799
    ((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4800
	allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4801
	allTheBest size > 15 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4802
	    allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4803
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4804
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4805
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4806
    start := node start.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4807
    stop := node stop.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4808
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4809
    best := self askUserForCompletion:('Variable for "%1"' bindWith:node name)
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4810
		 for:codeView at: start
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4811
		 from:(allTheBest collect:[:assoc | assoc key]).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4812
    best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4813
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4814
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4815
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4816
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4817
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4818
    codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4819
	undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4820
	info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4821
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4822
    (best startsWith:oldVar) ifTrue:[
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4823
	oldLen := stop - start + 1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4824
	newLen := best size.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4825
	codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4826
	codeView dontReplaceSelectionOnInput
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4827
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4828
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4829
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4830
    "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
  4831
    "Modified: / 28-08-2013 / 15:37:28 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4832
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4833
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4834
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4835
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4836
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4837
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4838
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4839
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4840
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4841
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4842
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4843
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4844
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4845
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4846
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4847
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4848
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4849
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4850
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4851
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4852
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  4853
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4854
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4855
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4856
version
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4857
    ^ '$Header$'
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4858
!
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  4859
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  4860
version_CVS
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4861
    ^ '$Header$'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  4862
! !
4194
e677aae984be Refactoring:
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
  4863